:root {
  --pine: #1a3344;
  --pine-deep: #0f2230;
  --lake: #4a6d8c;
  --kbt-blue: #5a7a9a;
  --mist: #e8eef0;
  --snow: #f7faf9;
  --saffron: #c8973a;
  --saffron-soft: #e8c97a;
  --ink: #15201c;
  --muted: #5c6f68;
  --line: rgba(20, 53, 44, 0.1);
  --danger: #b42318;
  --ok: #1f7a4d;
  --card: rgba(255, 255, 255, 0.88);
  --shadow: 0 18px 50px rgba(12, 34, 28, 0.12);
  --radius: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: Georgia, "Times New Roman", serif;
  --sidebar: 272px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(47, 111, 122, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(200, 151, 58, 0.16), transparent 50%),
    linear-gradient(165deg, #f4f8f7 0%, #e7eef0 45%, #f8f6f0 100%);
  background-attachment: fixed;
}

a { color: var(--lake); text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--pine-deep), var(--pine));
  color: #eef6f3;
  padding: 1.4rem 1rem 1rem;
  display: flex; flex-direction: column; gap: 1.5rem;
  position: sticky; top: 0; height: 100vh;
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.06);
}
.brand { display: flex; gap: .75rem; align-items: center; padding: .4rem .6rem 1rem; }
.brand-logo {
  width: auto; height: 44px; max-width: 140px; object-fit: contain; border-radius: 8px;
  background: rgba(255,255,255,.95); padding: 4px 6px; flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(0,0,0,.2);
}
.brand-text { min-width: 0; }
.veloz-footer {
  text-align: center; padding: .85rem 1rem 1.25rem; font-size: .78rem; color: var(--muted);
  border-top: 1px solid var(--line); margin-top: auto;
}
.veloz-footer a { color: var(--lake); font-weight: 500; }
.content { display: flex; flex-direction: column; min-height: calc(100vh - 72px); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  background:
    linear-gradient(145deg, var(--saffron-soft), var(--saffron)),
    var(--saffron);
  box-shadow: 0 8px 20px rgba(200,151,58,.35);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 10px 8px 8px;
  border: 2px solid rgba(20,53,44,.35); border-radius: 50% 50% 40% 40%;
}
.brand-name { font-family: var(--display); font-size: 1.45rem; line-height: 1; font-weight: 600; }
.brand-sub { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; opacity: .7; margin-top: .2rem; }

.nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.nav-link {
  color: rgba(238,246,243,.78); padding: .7rem .9rem; border-radius: 12px;
  transition: .2s ease; font-weight: 500; font-size: .95rem;
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(232,201,122,.18); color: #fff; box-shadow: inset 3px 0 0 var(--saffron-soft); }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,.1); padding-top: 1rem; display: grid; gap: .75rem; }
.user-chip { padding: 0 .4rem; }
.user-chip strong { display: block; font-size: .92rem; }
.user-chip span { font-size: .75rem; opacity: .65; text-transform: uppercase; letter-spacing: .08em; }

.main { min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.35rem 1.75rem .5rem; gap: 1rem;
}
.page-title {
  margin: 0; font-family: var(--display); font-size: clamp(1.8rem, 2.4vw, 2.4rem);
  font-weight: 600; letter-spacing: -.01em; color: var(--pine-deep);
}
.content { padding: .75rem 1.75rem 2.5rem; }

.panel, .stat-card, .card {
  background: var(--card); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 1.25rem; }
.panel + .panel { margin-top: 1rem; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { padding: 1.1rem 1.2rem; position: relative; overflow: hidden; }
.stat-card::before {
  content: ""; position: absolute; right: -20px; top: -20px; width: 90px; height: 90px;
  border-radius: 50%; background: radial-gradient(circle, rgba(47,111,122,.18), transparent 70%);
}
.stat-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.stat-value { font-family: var(--display); font-size: 2rem; margin-top: .2rem; color: var(--pine); }
.stat-hint { color: var(--muted); font-size: .82rem; margin-top: .15rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }

.btn {
  appearance: none; border: none; cursor: pointer;
  border-radius: 999px; padding: .65rem 1.15rem; font-weight: 600;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--pine), var(--lake));
  color: #fff; box-shadow: 0 10px 24px rgba(20,53,44,.25);
}
.btn-accent {
  background: linear-gradient(135deg, var(--saffron), #a87420);
  color: #1a1408; box-shadow: 0 10px 24px rgba(200,151,58,.28);
}
.btn-ghost {
  background: transparent; color: inherit; border: 1px solid currentColor; opacity: .9;
}
.sidebar .btn-ghost { color: #eef6f3; border-color: rgba(255,255,255,.25); }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid rgba(180,35,24,.3); }
.btn-sm { padding: .4rem .8rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); background: #fff;
  border-radius: 12px; padding: .7rem .85rem; color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: rgba(47,111,122,.55); box-shadow: 0 0 0 4px rgba(47,111,122,.12);
}
.textarea { min-height: 90px; resize: vertical; }
.label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .35rem; font-weight: 500; }
.field { margin-bottom: .9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }

.table-wrap { overflow: auto; border-radius: 14px; }
table.data {
  width: 100%; border-collapse: collapse; font-size: .92rem;
}
table.data th, table.data td {
  text-align: left; padding: .85rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top;
}
table.data th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600;
  background: rgba(232,238,240,.65);
}
table.data tr:hover td { background: rgba(47,111,122,.04); }
.badge {
  display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  background: rgba(47,111,122,.12); color: var(--lake);
}
.badge-ok { background: rgba(31,122,77,.12); color: var(--ok); }
.badge-warn { background: rgba(200,151,58,.18); color: #8a6418; }
.badge-danger { background: rgba(180,35,24,.12); color: var(--danger); }
.badge-muted { background: rgba(92,111,104,.12); color: var(--muted); }

.empty {
  text-align: center; padding: 2.5rem 1rem; color: var(--muted);
}
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tab {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: .45rem .95rem; cursor: pointer; font-weight: 500; color: var(--muted);
}
.tab.active { background: var(--pine); color: #fff; border-color: var(--pine); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12,34,28,.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
  animation: fadeIn .18s ease;
}
.modal {
  width: min(640px, 100%); max-height: 90vh; overflow: auto;
  background: #fff; border-radius: 22px; box-shadow: var(--shadow); padding: 1.35rem 1.4rem 1.2rem;
  animation: rise .22s ease;
}
.modal.wide { width: min(920px, 100%); }
.modal h2 { margin: 0 0 1rem; font-family: var(--display); font-size: 1.7rem; color: var(--pine-deep); }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

.toast-host { position: fixed; right: 1.2rem; top: 1.2rem; z-index: 80; display: grid; gap: .5rem; }
.toast {
  background: var(--pine-deep); color: #fff; padding: .75rem 1rem; border-radius: 12px;
  box-shadow: var(--shadow); min-width: 220px; animation: rise .2s ease;
}
.toast.error { background: var(--danger); }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    linear-gradient(120deg, rgba(12,34,28,.72), rgba(47,111,122,.45)),
    radial-gradient(ellipse at 30% 20%, rgba(232,201,122,.35), transparent 50%),
    linear-gradient(160deg, #0c221c, #2f6f7a);
}
.login-card {
  width: min(420px, 100%); background: rgba(255,255,255,.94); border-radius: 28px;
  padding: 2rem 1.75rem; box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0; font-family: var(--display); font-size: 2.3rem; color: var(--pine-deep); text-align: center;
}
.login-card .tagline { text-align: center; color: var(--muted); margin: .35rem 0 1.5rem; }

.day-card {
  border: 1px solid var(--line); border-radius: 16px; padding: 1rem; margin-bottom: .75rem; background: #fff;
}
.day-card h3 { margin: 0 0 .35rem; font-size: 1.05rem; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #3dd68c; display: inline-block;
  box-shadow: 0 0 0 0 rgba(61,214,140,.7); animation: pulse 1.8s infinite; margin-right: .4rem;
}

.split { display: grid; grid-template-columns: 1.2fr .8fr; gap: 1rem; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: .35rem .75rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61,214,140,.55); }
  70% { box-shadow: 0 0 0 10px rgba(61,214,140,0); }
  100% { box-shadow: 0 0 0 0 rgba(61,214,140,0); }
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .split, .grid-3 { grid-template-columns: 1fr; }
}

.btn-icon {
  appearance: none; border: 1px solid var(--line); background: #fff;
  border-radius: 12px; width: 42px; height: 42px; font-size: 1.2rem; cursor: pointer;
  display: none; align-items: center; justify-content: center; flex-shrink: 0;
}
.mobile-only { display: none; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(12,34,28,.45);
  z-index: 40; backdrop-filter: blur(3px);
}
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag-chip {
  display: inline-flex; padding: .25rem .55rem; border-radius: 999px; font-size: .75rem;
  background: rgba(74,109,140,.12); color: var(--lake); border: 1px solid rgba(74,109,140,.2);
}
.tag-chip.selected { background: var(--lake); color: #fff; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; }
.bar-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; font-size: .88rem; }
.bar-track { flex: 1; height: 8px; background: rgba(74,109,140,.12); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--lake), var(--kbt-blue)); border-radius: 999px; }
.star-rating { display: flex; gap: .35rem; font-size: 1.6rem; }
.star-rating button { background: none; border: none; cursor: pointer; opacity: .35; padding: 0; }
.star-rating button.on { opacity: 1; color: var(--saffron); }
.login-logo { max-width: min(320px, 90%); max-height: 88px; width: auto; height: auto; object-fit: contain; margin: 0 auto 1rem; display: block; background: #111; padding: 10px 14px; border-radius: 14px; }
.login-veloz { text-align: center; margin-top: 1.5rem; font-size: .78rem; color: rgba(255,255,255,.65); }
.login-veloz a { color: rgba(255,255,255,.85); }

@media (max-width: 960px) {
  .mobile-only { display: inline-flex; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; width: min(var(--sidebar), 88vw);
    transform: translateX(-105%); transition: transform .25s ease;
    height: 100vh; overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-backdrop { display: block; }
  .nav { flex-direction: column; }
  .topbar { padding: 1rem; gap: .65rem; }
  .page-title { font-size: 1.55rem; }
  .content { padding: .5rem 1rem 2rem; }
  .stats { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .stat-value { font-size: 1.65rem; }
  .report-grid { grid-template-columns: 1fr; }
  .modal { width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; align-self: flex-end; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .toast-host { left: 1rem; right: 1rem; top: auto; bottom: 1rem; }
  table.data { font-size: .85rem; }
  table.data th, table.data td { padding: .65rem .5rem; }
  .kv { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .spacer { display: none; }
}
