:root {
  --navy: #0b2f56;
  --navy-2: #0f416f;
  --blue: #1769aa;
  --blue-light: #eaf4fb;
  --cyan: #26a7d8;
  --ink: #16324a;
  --muted: #66788a;
  --line: #dce6ef;
  --surface: #ffffff;
  --surface-soft: #f5f8fb;
  --success: #157347;
  --danger: #b42318;
  --shadow: 0 16px 42px rgba(15, 47, 82, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--surface-soft); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 4%, rgba(38, 167, 216, .12), transparent 28rem),
    var(--surface-soft);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: inherit; }
button, input, select { font: inherit; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 0 4vw;
  color: #fff;
  background: linear-gradient(115deg, var(--navy), var(--navy-2));
  box-shadow: 0 8px 30px rgba(8, 37, 68, .18);
}

.brand { display: inline-flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand span:last-child { display: grid; line-height: 1.12; }
.brand strong { font-size: 1rem; letter-spacing: .01em; }
.brand small { margin-top: 4px; color: rgba(255, 255, 255, .72); font-size: .76rem; }
.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 14px;
  color: #fff;
  background: rgba(255, 255, 255, .13);
  font-weight: 800;
  letter-spacing: -.04em;
}
.brand-mark-large { width: 62px; height: 62px; border-radius: 20px; background: linear-gradient(135deg, var(--blue), var(--cyan)); }

.main-menu { display: flex; align-items: center; gap: 6px; }
.main-menu a, .nav-logout {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  padding: 0 14px;
  border: 0;
  border-radius: 11px;
  color: rgba(255, 255, 255, .82);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}
.main-menu a:hover, .main-menu a.active, .nav-logout:hover { color: #fff; background: rgba(255, 255, 255, .12); }
.main-menu form { margin: 0; }
.menu-toggle { display: none; border: 1px solid rgba(255,255,255,.28); border-radius: 10px; color: #fff; background: transparent; padding: 8px 12px; }

.page-shell { width: min(1500px, 92vw); margin: 0 auto; padding: 38px 0 70px; }
.auth-shell { display: grid; width: min(920px, 92vw); min-height: calc(100vh - 55px); margin: 0 auto; padding: 40px 0; place-items: center; }
.site-footer { padding: 18px; color: var(--muted); font-size: .8rem; text-align: center; }

.auth-card {
  width: min(520px, 100%);
  padding: 38px;
  border: 1px solid rgba(220, 230, 239, .9);
  border-radius: 26px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 30px 80px rgba(11, 47, 86, .14);
}
.setup-card { width: min(620px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 18px; margin-bottom: 28px; }
.auth-title { margin: 0 0 24px; font-size: clamp(1.55rem, 4vw, 2rem); }
.auth-brand h1 { margin: 3px 0 4px; font-size: clamp(1.55rem, 4vw, 2rem); }
.auth-brand p { margin: 0; color: var(--muted); }

h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.8rem, 3vw, 2.55rem); letter-spacing: -.035em; }
h2 { margin: 0; font-size: 1.1rem; letter-spacing: -.012em; }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.page-heading { margin-bottom: 26px; }
.page-heading p:not(.eyebrow) { max-width: 760px; margin: 8px 0 0; color: var(--muted); }
.page-heading-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }

.panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-muted { background: #eff6fb; box-shadow: none; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.content-grid { display: grid; gap: 22px; }
.content-grid-aside { grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); }
.user-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.checkbox-line { display: flex; grid-template-columns: none; align-items: center; gap: 9px; font-weight: 700; }
.checkbox-line input { width: 18px; min-height: 18px; margin: 0; accent-color: var(--blue); }
.form-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.stack-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: #29445c; font-size: .86rem; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #c8d6e2;
  border-radius: 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 170, .12); }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}
.button-primary { color: #fff; background: var(--blue); box-shadow: 0 8px 20px rgba(23, 105, 170, .2); }
.button-primary:hover { background: #105a94; }
.button-secondary { color: var(--blue); border-color: #9fc1dc; background: #fff; }
.button-ghost { color: var(--muted); background: transparent; }
.button-danger { color: #fff; background: var(--danger); }
.button-danger:hover { background: #8f1d15; }
.button-small { min-height: 34px; padding: 7px 11px; border-radius: 9px; font-size: .78rem; }
.button-full { width: 100%; }

.alert { width: min(920px, 100%); margin: 0 auto 20px; padding: 14px 16px; border: 1px solid; border-radius: 12px; }
.alert-success { color: #0f5b38; border-color: #a7d8c0; background: #ecf8f2; }
.alert-error { color: #8f1d15; border-color: #f0b3ad; background: #fff1f0; }
.alert-info { color: #205778; border-color: #b7d7e9; background: #eef8fd; }

.filter-panel { margin-bottom: 22px; }
.filter-grid { display: grid; grid-template-columns: repeat(6, minmax(135px, 1fr)); gap: 14px; align-items: end; }
.filter-actions { display: flex; gap: 6px; grid-column: span 6; justify-content: flex-end; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi { min-height: 142px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.kpi strong { display: block; margin-top: 10px; color: var(--navy); font-size: clamp(1.7rem, 3vw, 2.45rem); line-height: 1; }
.kpi small { display: block; margin-top: 10px; color: var(--muted); }
.kpi-wide { grid-column: span 5; min-height: auto; }
.kpi-wide strong { font-size: 1.35rem; }

.insight-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin: 0 0 22px; overflow: hidden; border: 1px solid #bfd8e9; border-radius: var(--radius); background: #bfd8e9; }
.insight-strip > div { padding: 20px; background: var(--blue-light); }
.insight-strip span { display: block; color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
.insight-strip strong { display: block; margin-top: 5px; font-size: 1.05rem; }
.insight-strip p { margin: 5px 0 0; color: var(--muted); font-size: .86rem; }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.chart-card-wide { grid-column: span 2; }
.chart-wrap { position: relative; width: 100%; height: 285px; overflow: hidden; }
.chart-wrap-tall { height: 390px; }
.chart-wrap canvas { display: block; width: 100%; height: 100%; max-width: 100%; }
.chart-explanation { margin-top: 15px; padding: 13px 15px; border-left: 4px solid var(--cyan); border-radius: 8px; color: #526678; background: #f3f8fb; font-size: .88rem; }

.table-panel { margin-top: 22px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #f7fafc; font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; }
td { font-size: .88rem; }
tbody tr:hover { background: #f8fbfd; }
.table-subline { display: block; margin-top: 3px; color: var(--muted); font-size: .78rem; }
.table-count { color: var(--muted); font-size: .82rem; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inline-form { display: inline-flex; margin: 0; }
.status { display: inline-flex; padding: 4px 9px; border-radius: 999px; background: #edf2f6; font-size: .74rem; font-weight: 800; text-transform: capitalize; }
.status-completed { color: var(--success); background: #e9f7f0; }
.status-failed { color: var(--danger); background: #fff0ef; }
.status-processing { color: #856404; background: #fff8df; }

.file-drop { min-height: 250px; place-content: center; justify-items: center; padding: 26px; border: 2px dashed #9ebbd1; border-radius: 16px; color: var(--muted); background: #f8fbfd; text-align: center; cursor: pointer; }
.file-drop:hover { border-color: var(--blue); background: #f1f8fc; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-drop-title { color: var(--ink); font-size: 1.1rem; font-weight: 800; }
.file-drop strong { max-width: 100%; color: var(--blue); }
.check-list { display: grid; gap: 10px; margin: 18px 0; padding: 0; list-style: none; }
.check-list li::before { margin-right: 8px; color: var(--success); content: "✓"; font-weight: 900; }
code { padding: 2px 5px; border-radius: 5px; background: rgba(11, 47, 86, .08); font-size: .86em; }
.help-text, .security-note { color: var(--muted); font-size: .85rem; }
.security-note { margin: 20px 0 0; text-align: center; }
.empty-state { padding: 50px 24px; text-align: center; }
.empty-state p { color: var(--muted); }

@media (max-width: 1100px) {
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-actions { grid-column: span 3; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-wide { grid-column: span 2; }
}

@media (max-width: 760px) {
  .topbar { min-height: 68px; padding: 0 18px; }
  .brand small { display: none; }
  .menu-toggle { display: inline-flex; }
  .main-menu { position: absolute; top: 60px; right: 14px; left: 14px; display: none; align-items: stretch; padding: 10px; border: 1px solid rgba(255,255,255,.16); border-radius: 14px; background: var(--navy); box-shadow: 0 18px 40px rgba(0,0,0,.22); flex-direction: column; }
  .main-menu.open { display: flex; }
  .main-menu a, .nav-logout { width: 100%; justify-content: flex-start; }
  .page-shell { width: min(94vw, 100%); padding-top: 26px; }
  .page-heading-actions { align-items: stretch; flex-direction: column; }
  .content-grid-aside, .chart-grid { grid-template-columns: 1fr; }
  .user-form-grid { grid-template-columns: 1fr; }
  .chart-card-wide { grid-column: span 1; }
  .filter-grid { grid-template-columns: 1fr; }
  .filter-actions { grid-column: span 1; justify-content: stretch; }
  .filter-actions .button { flex: 1; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-wide { grid-column: span 2; }
  .insight-strip { grid-template-columns: 1fr; }
  .auth-card { padding: 26px 22px; }
  .auth-brand { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 480px) {
  .panel { padding: 19px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-wide { grid-column: span 1; }
  .chart-wrap { height: 260px; }
  .chart-wrap-tall { height: 400px; }
}

@media print {
  body { background: #fff; }
  .topbar, .site-footer, .filter-panel, .button { display: none !important; }
  .page-shell { width: 100%; padding: 0; }
  .panel, .kpi { break-inside: avoid; box-shadow: none; }
}
