:root {
  --white:      #ffffff;
  --bg:         #f0f2f7;
  --bg-2:       #ffffff;
  --bg-3:       #f5f6fa;
  --border:     #dde1ed;
  --border-2:   #c8cde0;

  --blue:       #1a73e8;
  --blue-h:     #1558b0;
  --blue-light: #e8f0fd;
  --green:      #1a9e5c;
  --green-light:#e6f7ee;
  --orange:     #d97706;
  --orange-light:#fef3c7;
  --red:        #dc2626;
  --red-light:  #fee2e2;
  --gray:       #64748b;
  --gray-light: #f1f5f9;
  --teal:       #0891b2;
  --teal-light: #e0f2fe;
  --purple:     #7c3aed;
  --purple-light:#ede9fe;

  --text-1: #1e2332;
  --text-2: #4b5468;
  --text-3: #8e96b0;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

  --sidebar-w:  200px;
  --topbar-h:   44px;
  --radius:     6px;
  --radius-sm:  4px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 3px 10px rgba(0,0,0,.09), 0 1px 3px rgba(0,0,0,.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── TOPBAR ──────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  z-index: 200; box-shadow: var(--shadow-sm);
}

.topbar-brand {
  width: var(--sidebar-w);
  display: flex; align-items: center;
  padding: 0 1rem;
  border-right: 1px solid var(--border);
  height: 100%; flex-shrink: 0;
  font-weight: 700; font-size: .95rem; color: var(--blue);
  letter-spacing: -.02em; gap: .4rem;
}

.topbar-breadcrumb {
  display: flex; align-items: center; gap: .4rem;
  padding: 0 1.25rem; font-size: .78rem; color: var(--text-3); flex: 1;
}
.topbar-breadcrumb a { color: var(--blue); text-decoration: none; }
.topbar-breadcrumb a:hover { text-decoration: underline; }
.topbar-breadcrumb .sep { color: var(--border-2); font-size: .7rem; }
.topbar-breadcrumb .current { color: var(--text-2); font-weight: 500; }

.topbar-actions { display: flex; align-items: center; gap: .6rem; padding-right: 1.25rem; }
.topbar-company {
  font-size: .72rem; font-weight: 600; color: var(--text-2);
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .2rem .6rem;
}

/* ── LAYOUT ──────────────────────────────────── */
.app-shell { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }

/* ── SIDEBAR — always visible, fixed width ───── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: .6rem 0;
  position: fixed;
  top: var(--topbar-h); left: 0;
  height: calc(100vh - var(--topbar-h));
  z-index: 100;
  flex-shrink: 0;
}

.nav-links { list-style: none; flex: 1; }

.nav-links a {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 1rem;
  color: var(--text-2); text-decoration: none;
  font-size: .85rem; font-weight: 500;
  transition: background .12s, color .12s;
  border-left: 3px solid transparent;
}
.nav-links a:hover { background: var(--bg-3); color: var(--text-1); }
.nav-links li.active a {
  background: var(--blue-light); color: var(--blue);
  font-weight: 600; border-left-color: var(--blue);
}
.nav-icon { font-size: .9rem; width: 18px; text-align: center; flex-shrink: 0; opacity: .75; }

.sidebar-bottom { border-top: 1px solid var(--border); padding: .6rem 0 .25rem; }

.sync-status {
  display: flex; align-items: center; gap: .45rem;
  font-size: .68rem; color: var(--text-3);
  padding: .35rem 1rem .5rem;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green); flex-shrink: 0;
  box-shadow: 0 0 4px rgba(26,158,92,.4);
  animation: pulse 2.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

.btn-sync {
  display: flex; align-items: center; justify-content: center; gap: .4rem;
  width: calc(100% - 1.25rem); margin: 0 .625rem;
  background: var(--blue); border: none; color: white;
  border-radius: var(--radius-sm); padding: .5rem .6rem;
  font-size: .76rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: background .12s;
}
.btn-sync:hover { background: var(--blue-h); }
.btn-sync:disabled { opacity: .5; cursor: default; }

/* ── MAIN ────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1; padding: 1.25rem 1.5rem 2.5rem;
  max-width: calc(100vw - var(--sidebar-w));
  min-width: 0;
}

/* ── PAGE HEADER ─────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap; gap: .75rem;
}
.page-title { font-size: 1.1rem; font-weight: 700; color: var(--text-1); letter-spacing: -.01em; }
.page-sub { color: var(--text-3); font-size: .72rem; margin-top: .1rem; }
.page-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.select-filter {
  background: var(--white); border: 1px solid var(--border-2);
  color: var(--text-1); border-radius: var(--radius-sm);
  padding: .35rem .65rem; font-size: .76rem; font-family: var(--font);
  outline: none; cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.select-filter:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(26,115,232,.12); }

.search-input {
  background: var(--white); border: 1px solid var(--border-2);
  color: var(--text-1); border-radius: var(--radius-sm);
  padding: .35rem .7rem; font-size: .76rem; font-family: var(--font);
  outline: none; width: 200px; box-shadow: var(--shadow-sm);
  transition: width .2s, border-color .12s;
}
.search-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(26,115,232,.12); width: 230px; }
.search-input::placeholder { color: var(--text-3); }

/* ── KPI GRID ────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr;
  gap: .75rem; margin-bottom: 1rem;
}

.kpi-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1.1rem;
  box-shadow: var(--shadow-sm); transition: box-shadow .15s, transform .15s;
}
.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.kpi-card.kpi-main {
  background: linear-gradient(135deg, var(--blue) 0%, #0cb89a 100%);
  border-color: transparent; box-shadow: 0 2px 12px rgba(26,115,232,.2);
}
.kpi-card.kpi-main .kpi-label { color: rgba(255,255,255,.75); }
.kpi-card.kpi-main .kpi-value { color: white; font-size: 1.45rem; }
.kpi-card.kpi-main .kpi-sub   { color: rgba(255,255,255,.65); }

.kpi-label {
  font-size: .62rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin-bottom: .3rem;
}
.kpi-value { font-size: 1.2rem; font-weight: 700; color: var(--text-1); line-height: 1.1; letter-spacing: -.02em; }
.kpi-sub   { font-size: .64rem; color: var(--text-3); margin-top: .2rem; }

/* ── PANEL ───────────────────────────────────── */
.panel {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .6rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}
.panel-title { font-size: .78rem; font-weight: 700; color: var(--text-1); }
.panel-body  { padding: .9rem 1rem; }

/* ── CHARTS ──────────────────────────────────── */
.charts-row   { display: grid; grid-template-columns: 3fr 2fr; gap: .75rem; margin-bottom: .75rem; }
.charts-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; margin-bottom: .75rem; }

.chart-legend { display: flex; gap: .75rem; }
.legend-item  { display: flex; align-items: center; gap: .3rem; font-size: .68rem; color: var(--text-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.blue  { background: var(--blue); }
.dot.green { background: #0cb89a; }

/* ── TABLES ──────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table  { width: 100%; border-collapse: collapse; font-size: .82rem; }

.data-table th {
  text-align: left; padding: .65rem 1rem;
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); white-space: nowrap;
  background: var(--bg-3); border-bottom: 2px solid var(--border-2);
}

.data-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-2); vertical-align: middle;
  line-height: 1.3;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f4f7ff; }
.data-table tbody tr.clickable-row { cursor: pointer; }
.data-table tbody tr.clickable-row:hover td { background: #edf2ff !important; }
.data-table tbody tr.clickable-row:hover td strong { color: var(--blue); }
.data-table td strong { color: var(--text-1); font-weight: 600; }
.data-table td.mono { font-size: .72rem; color: var(--text-3); font-family: 'Courier New', monospace; }

.loading-row { text-align: center; color: var(--text-3); padding: 2.5rem !important; font-size: .78rem; }

/* ── BADGES ──────────────────────────────────── */
.badge {
  display: inline-block; padding: .18rem .6rem;
  border-radius: 100px; font-size: .66rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.badge-green  { background: var(--green-light);  color: var(--green); }
.badge-blue   { background: var(--blue-light);   color: var(--blue); }
.badge-yellow { background: var(--orange-light); color: var(--orange); }
.badge-red    { background: var(--red-light);    color: var(--red); }
.badge-gray   { background: var(--gray-light);   color: var(--gray); }
.badge-teal   { background: var(--teal-light);   color: var(--teal); }
.badge-purple { background: var(--purple-light); color: var(--purple); }

/* ── STATES ──────────────────────────────────── */
.states-list { display: flex; flex-direction: column; gap: .4rem; max-height: 260px; overflow-y: auto; }
.state-item  { display: flex; align-items: center; gap: .6rem; padding: .15rem 0; }
.state-label { font-size: .72rem; font-weight: 600; color: var(--text-1); width: 28px; flex-shrink: 0; }
.state-bar-wrap { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; border: 1px solid var(--border); }
.state-bar   { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--blue), #0cb89a); transition: width .5s ease; }
.state-count { font-size: .7rem; color: var(--text-3); width: 28px; text-align: right; }

/* ── SETTINGS ────────────────────────────────── */
.settings-desc { color: var(--text-2); line-height: 1.6; margin-bottom: .9rem; font-size: .8rem; }
.form-row { display: flex; gap: .6rem; flex-wrap: wrap; }

.text-input {
  flex: 1; min-width: 180px;
  background: var(--white); border: 1px solid var(--border-2);
  color: var(--text-1); border-radius: var(--radius-sm);
  padding: .5rem .85rem; font-size: .8rem;
  outline: none;
}
.text-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(26,115,232,.1); }

.btn-primary {
  background: var(--blue); color: white; border: none;
  border-radius: var(--radius-sm); padding: .5rem 1rem;
  font-size: .78rem; font-family: var(--font); font-weight: 600;
  cursor: pointer; transition: background .12s; white-space: nowrap;
}
.btn-primary:hover { background: var(--blue-h); }

.btn-secondary {
  background: var(--white); border: 1px solid var(--border-2);
  color: var(--text-2); border-radius: var(--radius-sm);
  padding: .45rem .9rem; font-size: .78rem; font-family: var(--font);
  cursor: pointer; transition: border-color .12s, color .12s; font-weight: 500;
}
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }

.btn-copy-inline { background:none; border:1px solid var(--border-2); border-radius:var(--radius-sm); padding:.1rem .35rem; font-size:.72rem; cursor:pointer; color:var(--text-3); vertical-align:middle; }
.btn-copy-inline:hover { border-color:var(--blue); color:var(--blue); background:var(--blue-light); }

.token-status { margin-top: .6rem; font-size: .76rem; min-height: 1.2em; }
.token-status.ok  { color: var(--green); }
.token-status.err { color: var(--red); }

/* ── TOAST ───────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: #1e2332; color: #fff;
  padding: .65rem 1rem; border-radius: var(--radius);
  font-size: .78rem; box-shadow: var(--shadow);
  transform: translateY(8px); opacity: 0;
  pointer-events: none; transition: all .2s;
  z-index: 9999; max-width: 300px;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── SCROLLBAR ───────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b7cc; }

/* ── RESPONSIVE ──────────────────────────────── */
@media (max-width: 1400px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .kpi-card.kpi-main { grid-column: span 3; }
}
@media (max-width: 1100px) {
  .charts-row, .charts-row-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .charts-row, .charts-row-3 { grid-template-columns: 1fr; }
  .main-content { padding: 1rem; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-card.kpi-main { grid-column: span 2; }
  .page-header { flex-direction: column; }
  .page-actions { width: 100%; }
  .select-filter { flex: 1; }
  .search-input  { width: 100%; }
}
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card.kpi-main { grid-column: span 1; }
}

/* ── Detail button ───────────────────────────────────────────────────────────── */
.btn-detail {
  display: inline-block;
  padding: .22rem .65rem;
  background: var(--white);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: .72rem;
  font-weight: 600;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn-detail:hover {
  background: var(--blue-light);
  border-color: var(--blue);
}
