:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-hover: #1d2a52;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --accent: #e94560;
  --accent-hover: #ff6b6b;
  --success: #00d26a;
  --danger: #ff5c7a;
  --warning: #ffc107;
  --border: #2a2a4a;
  --shadow: 0 10px 40px rgba(0, 0, 0, .28);
  --radius: 14px;
  --header-h: 68px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
}

[data-theme="light"] {
  --bg-primary: #f4f6fb;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef1f8;
  --text-primary: #121226;
  --text-secondary: #5b5d72;
  --border: #d9deea;
  --shadow: 0 8px 28px rgba(18, 18, 38, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, select, input { font: inherit; color: inherit; }
img { max-width: 100%; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--header-h);
  height: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 10px 22px;
  background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 168px;
}
.brand img, .brand svg { width: 36px; height: 36px; object-fit: contain; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; letter-spacing: .02em; }
.brand-tag { font-size: 11px; color: var(--text-secondary); }

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.nav a {
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-weight: 500;
}
.nav a:hover, .nav a.active {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}
.period-select, .field, .search {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 16px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }

.wrap { width: min(1280px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 48px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 28px; letter-spacing: -.03em; }
.muted { color: var(--text-secondary); }
.mono { font-family: var(--mono); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi {
  padding: 16px 18px;
}
.kpi .label { color: var(--text-secondary); font-size: 13px; }
.kpi .value { font-family: var(--mono); font-size: 26px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -.03em; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1.2fr .8fr; gap: 12px; }
.grid-2.equal, .grid-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chart-card { padding: 16px; min-height: 320px; }
.chart-card h2, .table-card h2 { margin: 0 0 12px; font-size: 16px; }
.chart-wrap { position: relative; height: 260px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.table-card { padding: 16px; overflow: hidden; }
.table-scroll { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
table.data th, table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
table.data th { color: var(--text-secondary); font-size: 12px; font-weight: 600; cursor: pointer; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--bg-hover); }
table.data tbody tr.alert { box-shadow: inset 3px 0 0 var(--warning); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--mono); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  font-size: 12px;
}
.flag { width: 18px; height: 13px; border-radius: 2px; object-fit: cover; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; color: var(--text-secondary); font-size: 13px; }
.pager button {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.cards-mobile { display: none; }
.mobile-card {
  padding: 14px;
  margin-bottom: 8px;
}
.mobile-card .row { display: flex; justify-content: space-between; gap: 8px; margin: 4px 0; }
.mobile-card .row span:last-child { text-align: right; word-break: break-word; }
.mobile-card strong { word-break: break-word; }
.mobile-card.alert { box-shadow: inset 3px 0 0 var(--warning); }

.spark { width: 92px; height: 28px; display: block; }

.footer {
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 22px;
  text-align: center;
}

.custom-range { display: flex; align-items: center; gap: 8px; }
.custom-range.open { display: flex; }
.range-sep { color: var(--text-secondary); font-size: 13px; }
.chart-pct {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.chart-pct span {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  animation: pctIn .45s ease both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
.chart-pct b { color: var(--text-primary); font-weight: 600; margin-right: 4px; }
.pkg-cell { white-space: normal; min-width: 220px; max-width: 420px; }
.pkg-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.pkg-link, .pkg-list .mono {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--text-primary);
}
.pkg-link:hover { color: var(--accent); text-decoration: underline; }
.note {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 13px;
}
@keyframes pctIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.empty { padding: 40px 16px; text-align: center; color: var(--text-secondary); }

.login-body {
  height: 100vh;
  overflow: hidden;
  background: #070712;
}
.login-stage {
  height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  align-items: stretch;
}
.login-eagle {
  position: relative;
  overflow: hidden;
  height: 100%;
  min-height: 0;
  background: #070712;
}
.login-eagle-fly {
  width: 100%;
  height: 100%;
  transform: scale(1);
  transform-origin: 50% 55%;
  will-change: transform;
  animation: eagleFlyIn 1.7s cubic-bezier(.16, 1, .3, 1) forwards;
}
.login-eagle img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 52% 6%;
  transform-origin: 50% 55%;
  animation: eagleHover 7s 1.7s ease-in-out infinite alternate;
}
.login-eagle::before,
.login-eagle::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.login-eagle::before {
  background:
    linear-gradient(90deg, transparent 48%, #070712 96%),
    linear-gradient(180deg, rgba(7,7,18,.15), transparent 30%, rgba(7,7,18,.55));
}
.login-eagle::after {
  background: radial-gradient(circle at 70% 30%, rgba(201,163,106,.16), transparent 42%);
  animation: glowPulse 6s ease-in-out infinite;
}
.login-embers {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.login-embers i {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #d4b483;
  box-shadow: 0 0 12px rgba(212,180,131,.7);
  opacity: .55;
  animation: ember 8s linear infinite;
}
.login-embers i:nth-child(1) { left: 12%; bottom: 8%; animation-delay: 0s; }
.login-embers i:nth-child(2) { left: 28%; bottom: 2%; animation-delay: 1.4s; }
.login-embers i:nth-child(3) { left: 46%; bottom: 10%; animation-delay: 2.8s; }
.login-embers i:nth-child(4) { left: 63%; bottom: 4%; animation-delay: 0.7s; }
.login-embers i:nth-child(5) { left: 78%; bottom: 14%; animation-delay: 2.1s; }
.login-embers i:nth-child(6) { left: 18%; bottom: 18%; animation-delay: 3.5s; }
.login-sheen {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 36%, rgba(255,255,255,.12) 50%, transparent 64%);
  transform: translateX(-80%);
  animation: sheen 7.5s ease-in-out infinite;
}
.login-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  padding: 0 40px;
}
.login-panel::before {
  content: "";
  position: absolute;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201,163,106,.12), transparent 68%);
  animation: glowPulse 5s ease-in-out infinite;
}
.login-stack {
  position: relative;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}
.login-head {
  padding: 18px 22px 16px;
  text-align: center;
  background: linear-gradient(180deg, rgba(26,26,46,.88), rgba(15,15,35,.78));
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 22px;
  backdrop-filter: blur(28px);
  box-shadow: 0 18px 48px rgba(0,0,0,.38), inset 0 1px 0 rgba(255,255,255,.06);
  animation: cardIn .7s cubic-bezier(.16,1,.3,1) both;
}
.login-head span {
  display: block;
  color: #c9a36a;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
}
.login-head strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1.1;
}
.login-head strong::after {
  content: "";
  display: block;
  width: 42px;
  height: 1px;
  margin: 12px auto 0;
  background: linear-gradient(90deg, transparent, #c9a36a, transparent);
}
.login-card {
  position: relative;
  width: 100%;
  padding: 26px 24px 22px;
  background: linear-gradient(180deg, rgba(26,26,46,.88), rgba(15,15,35,.78));
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 22px;
  backdrop-filter: blur(28px);
  box-shadow: 0 30px 80px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.06);
  animation: cardIn .85s .08s cubic-bezier(.16,1,.3,1) both;
}
.login-kicker {
  margin: 0 0 10px;
  color: #c9a36a;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.login-card h1 {
  margin: 0 0 10px;
  font-size: 32px;
  line-height: 1.15;
  letter-spacing: -.04em;
}
.login-lead { margin: 0 0 4px; font-size: 14px; line-height: 1.5; }
.login-card form { display: grid; gap: 6px; margin-top: 20px; }
.login-card label {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #c8c8d4;
}
.login-card .field {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  font-size: 16px;
  background: rgba(7,7,18,.55);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  transition: border-color .25s ease, box-shadow .25s ease;
}
.login-card .field:focus {
  outline: none;
  border-color: #c9a36a;
  box-shadow: 0 0 0 4px rgba(201,163,106,.16);
}
.login-card #err { color: #ff6b6b; margin: 10px 0 0; font-size: 13px; }
.login-btn {
  position: relative;
  overflow: hidden;
  margin-top: 12px;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 13px 16px;
  background: linear-gradient(180deg, #1a1a1a, #0a0a0a);
  color: #f3efe6;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0,0,0,.4);
}
.login-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255,255,255,.35) 48%, transparent 72%);
  transform: translateX(-120%);
  animation: sheen 3.8s ease-in-out infinite;
}
.login-btn:hover { filter: brightness(1.08); }
@keyframes eagleFlyIn {
  from { transform: scale(1); }
  to { transform: scale(1.32) translate3d(0, -5%, 0); }
}
@keyframes eagleFlyInMobile {
  from { transform: scale(1.08); }
  to { transform: scale(1.18); }
}
@keyframes eagleHover {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to { transform: scale(1.125) translate3d(0, -4%, 0); }
}
@keyframes glowPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
@keyframes ember {
  0% { transform: translateY(0) scale(1); opacity: 0; }
  15% { opacity: .7; }
  100% { transform: translateY(-72vh) scale(.4); opacity: 0; }
}
@keyframes sheen {
  0%, 55% { transform: translateX(-120%); }
  80%, 100% { transform: translateX(120%); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .login-eagle-fly,
  .login-eagle img,
  .login-embers i,
  .login-sheen,
  .login-eagle::after,
  .login-panel::before,
  .login-btn::after,
  .login-head,
  .login-card {
    animation: none !important;
  }
  .login-eagle-fly { transform: none; }
}
@media (max-width: 860px) {
  .login-body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .login-stage {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: min(48vh, 360px) auto;
  }
  .login-eagle { height: min(48vh, 360px); background: #070712; overflow: hidden; }
  .login-eagle-fly {
    width: 100%;
    height: 100%;
    transform-origin: 50% 40%;
    animation: eagleFlyInMobile 1.5s cubic-bezier(.16, 1, .3, 1) forwards;
  }
  .login-eagle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 36%;
  }
  .login-eagle::before {
    background:
      linear-gradient(180deg, transparent 70%, #070712 100%),
      linear-gradient(180deg, rgba(7,7,18,.08), transparent 18%);
  }
  .login-panel {
    height: auto;
    align-items: flex-start;
    padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  }
  .login-panel::before { width: 240px; height: 240px; }
  .login-stack { width: 100%; max-width: 400px; margin: 0 auto; }
  .login-head { padding: 14px 16px 12px; }
  .login-head strong { font-size: 26px; }
  .login-card { padding: 20px 16px 18px; }
  .login-card h1 { font-size: 26px; }
  .login-lead { font-size: 14px; }
}
.logout-link {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-2.equal, .grid-charts { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app-header {
    height: auto;
    flex-wrap: wrap;
    gap: 10px 12px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .brand { min-width: 0; flex: 1; }
  .brand img, .brand svg { width: 32px; height: 32px; }
  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    gap: 6px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 0 0 auto;
    padding: 9px 12px;
    font-size: 14px;
  }
  .header-tools {
    flex: 1 1 auto;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .period-select { flex: 1 1 140px; min-width: 0; max-width: 180px; }
  .custom-range,
  .custom-range.open {
    order: 5;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }
  .custom-range .field { width: 100%; min-width: 0; }
  .logout-link { padding: 8px 10px; white-space: nowrap; }
  .wrap { width: calc(100% - 24px); padding: 16px 0 36px; }
  .page-head { flex-direction: column; align-items: start; margin-bottom: 14px; }
  .page-head h1 { font-size: 24px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 18px; word-break: break-word; }
  .chart-card { min-height: 0; padding: 14px; }
  .chart-wrap { height: 220px; }
  .toolbar { flex-direction: column; }
  .toolbar .search, .toolbar .field { width: 100%; }
  .desktop-only { display: none; }
  .cards-mobile { display: block; }
  .table-scroll { -webkit-overflow-scrolling: touch; }
  .pager {
    flex-wrap: wrap;
    gap: 8px;
  }
  .pager button { min-height: 40px; padding: 8px 12px; }
  .footer { padding: 16px 12px calc(18px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
