:root {
  --bg: #0f1419;
  --bg-elev: #171d25;
  --bg-panel: #1c2430;
  --bg-soft: #232d3b;
  --line: #2c3848;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #3d9a7a;
  --accent-2: #4db892;
  --accent-soft: rgba(61, 154, 122, 0.16);
  --danger: #d56b6b;
  --warn: #d4a44a;
  --ok: #4db892;
  --radius: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --font: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(61, 154, 122, 0.18), transparent 60%),
    radial-gradient(700px 400px at 90% 80%, rgba(70, 110, 180, 0.12), transparent 55%),
    var(--bg);
}
.login-shell { width: min(420px, calc(100% - 32px)); }
.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #3d9a7a, #2a6f5a);
  font-weight: 700; letter-spacing: 0.04em;
}
.brand-title { font-size: 22px; font-weight: 700; }
.brand-sub { color: var(--muted); font-size: 13px; }
.login-form { display: grid; gap: 14px; }
.login-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-footnote { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }
.form-error { color: var(--danger); margin: 0; font-size: 13px; }

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-columns: 260px 1fr;
}
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 8px; }
.nav-list { display: grid; gap: 4px; }
.nav-btn {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}
.nav-btn:hover { background: var(--bg-soft); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent-2); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 8px; }
.sidebar-meta { color: var(--muted); font-size: 12px; }

.main {
  padding: 24px 28px 40px;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}
.page-title { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-desc { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 550;
  transition: 0.15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(145deg, #3d9a7a, #2f7d63);
  border-color: transparent;
  color: #fff;
}
.btn-danger { background: rgba(213, 107, 107, 0.15); border-color: rgba(213, 107, 107, 0.4); color: #ffb4b4; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 10px; font-size: 13px; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card, .panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 8px; font-family: var(--mono); }

.panel + .panel { margin-top: 14px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-title { font-size: 16px; font-weight: 650; margin: 0; }

.analytics-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.analytics-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); max-width: 100%; }
.analytics-tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; cursor: pointer; min-height: 44px; }
.analytics-tabs button[aria-selected="true"] { border-bottom-color: var(--accent-2); color: var(--accent-2); }
.analytics-tabs span { color: var(--muted); font-size: 12px; margin-left: 4px; }
.analytics-section { width: 100%; }
.analytics-table-scroll { overflow-x: auto; max-width: 100%; }
.analytics-table { border-collapse: collapse; width: 100%; min-width: 760px; table-layout: fixed; font-size: 14px; }
.analytics-table th, .analytics-table td { text-align: left; border-bottom: 1px solid var(--line); padding: 14px 10px; vertical-align: top; overflow-wrap: anywhere; }
.analytics-table th { font-size: 12px; color: var(--muted); font-weight: 500; }
.analytics-table th:first-child { width: 28%; }
.analytics-table th:nth-child(2) { width: 12%; }
.analytics-table th:nth-child(3) { width: 17%; }
.analytics-table th:nth-child(4) { width: 18%; }
.analytics-table th:last-child { width: 25%; }
.analytics-table td .muted { font-size: 12px; margin-top: 4px; }
.analytics-sync { display: inline-flex; gap: 8px; align-items: center; white-space: nowrap; }
.analytics-sync input { width: 16px; height: 16px; accent-color: var(--accent-2); }
.analytics-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.analytics-actions .btn { border-radius: 6px; white-space: normal; }
.analytics-footer { margin-top: 16px; }
.analytics-request { padding: 12px 0; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-wrap: anywhere; }
.analytics-request.error { color: #ffb4b4; }
.analytics-live { margin-top: 8px; font-size: 12px; line-height: 1.5; }
.analytics-live.error { color: #ffb4b4; }
.analytics-live progress { display: block; width: 100%; height: 6px; margin-top: 8px; accent-color: var(--accent-2); }

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field { display: grid; gap: 6px; }
.field.span-2 { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th, table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
table.data th {
  background: var(--bg-soft);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}
table.data tr:hover td { background: rgba(255,255,255,0.02); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.pill.ok { background: rgba(77, 184, 146, 0.15); border-color: rgba(77, 184, 146, 0.35); color: #8ee0c3; }
.pill.warn { background: rgba(212, 164, 74, 0.15); border-color: rgba(212, 164, 74, 0.35); color: #f0c878; }
.pill.danger { background: rgba(213, 107, 107, 0.15); border-color: rgba(213, 107, 107, 0.35); color: #ffb4b4; }

.ops-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.op-card {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
}
.op-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.op-card h4 { margin: 0 0 6px; font-size: 14px; }
.op-card p { margin: 0; color: var(--muted); font-size: 12.5px; }

.book-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  padding: 4px;
}
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
}
.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-2);
}

.preview-box {
  background: #0c1016;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100vw - 24px));
  z-index: 50;
}
.toast.error { border-color: rgba(213, 107, 107, 0.5); }
.hidden { display: none !important; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.hint {
  background: rgba(61, 154, 122, 0.08);
  border: 1px dashed rgba(61, 154, 122, 0.35);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}
.hint code {
  font-family: var(--mono);
  color: var(--accent-2);
  font-size: 12px;
}
.hint.error-hint {
  background: rgba(213, 107, 107, 0.1);
  border-color: rgba(213, 107, 107, 0.45);
  color: #ffc9c9;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 16, 0.72);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 16px;
}
.modal {
  width: min(560px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px; display: grid; gap: 14px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}
.analytics-modal { display: flex; flex-direction: column; overflow: hidden; }
.analytics-modal .modal-head, .analytics-modal .modal-foot { flex-shrink: 0; }
.analytics-modal .modal-body { min-height: 0; overflow: auto; }
.analytics-modal .modal-head button { flex-shrink: 0; }
.analytics-modal #calUrl, .analytics-modal #calAutoloadUrl { min-height: 64px; }
.step-dots { display: flex; gap: 6px; margin-bottom: 4px; }
.step-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line);
}
.step-dot.on { background: var(--accent); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.card-title { font-weight: 650; font-size: 15px; }
.card-meta { color: var(--muted); font-size: 12.5px; display: grid; gap: 4px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.accent {
  background: var(--accent-soft);
  border-color: rgba(61, 154, 122, 0.4);
  color: var(--accent-2);
}
.search-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.search-bar input {
  flex: 1;
  min-width: 180px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.check-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 4px;
}
.check-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  cursor: pointer;
}
.check-item input { accent-color: var(--accent); }
.paste-zone {
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  padding: 18px;
  background: rgba(255,255,255,0.02);
}
.paste-zone:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.paste-zone textarea {
  width: 100%;
  min-height: 72px;
  border: 0;
  background: transparent;
  resize: vertical;
  outline: none;
  font-size: 14px;
}
.cred-box {
  background: #0c1016;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav-list { grid-template-columns: repeat(3, 1fr); }
  .grid-stats, .ops-grid, .field-grid { grid-template-columns: 1fr; }
}
