:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #64717d;
  --line: #dce2e7;
  --navy: #16324f;
  --blue: #2478d4;
  --blue-soft: #e7f1fb;
  --orange: #e4872b;
  --orange-soft: #fff0dd;
  --red: #bd3d3a;
  --green: #237b62;
  --green-soft: #e4f4ee;
  --shadow: 0 9px 30px rgba(20, 44, 67, 0.07);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.logout-form { margin: 0; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 28px clamp(20px, 4vw, 64px) 22px;
  color: white;
  background:
    radial-gradient(circle at 80% 20%, rgba(51, 142, 224, 0.34), transparent 30%),
    linear-gradient(125deg, #102b46, #17466f);
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(28px, 4vw, 42px); letter-spacing: -0.04em; }
h2 { margin-bottom: 5px; font-size: 25px; letter-spacing: -0.025em; }
h3 { margin-bottom: 3px; font-size: 16px; }
.eyebrow { margin-bottom: 6px; font-size: 11px; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; opacity: 0.78; }
.subtitle, .helper-text { color: var(--muted); }
.app-header .subtitle { margin-bottom: 0; color: rgba(255,255,255,0.74); }
.header-actions, .timeline-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.header-actions { justify-content: flex-end; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 0 clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(12px);
}
.tab { padding: 15px 18px 13px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { border-bottom-color: var(--blue); color: var(--navy); }
.tab:disabled { cursor: default; opacity: 0.4; }

main { padding: 22px clamp(20px, 4vw, 64px) 64px; }
.notice { margin-bottom: 24px; padding: 13px 16px; border: 1px solid #f0d2a9; border-radius: 10px; background: var(--orange-soft); color: #764a1e; line-height: 1.45; }
.page-section { display: none; }
.page-section.active { display: block; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 26px 0 16px; }
.section-heading p:last-child { margin-bottom: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card { min-height: 112px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi-value { margin-top: 14px; color: var(--navy); font-size: 25px; font-weight: 780; letter-spacing: -0.035em; }
.kpi-context { margin-top: 5px; color: var(--muted); font-size: 11px; }

.chart-grid { display: grid; gap: 16px; }
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.panel-heading { padding: 17px 18px 0; }
.panel-heading p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.inline-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.chart { width: 100%; min-height: 310px; }
.chart.tall { min-height: 390px; }
.compact-chart { min-height: 190px; }
.timeline-chart { min-height: 430px; }
.hidden { display: none !important; }

.status-chip { display: inline-flex; align-items: center; padding: 7px 10px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.status-chip.neutral { color: #dce9f6; background: rgba(255,255,255,0.12); }
.status-chip.good { color: #baf1dd; background: rgba(32,144,111,0.28); }
.status-chip.bad { color: #ffe0c2; background: rgba(191,95,37,0.3); }
.button { padding: 9px 13px; border: 1px solid transparent; border-radius: 8px; font-weight: 720; }
.button.primary { color: white; background: var(--blue); }
.button.quiet { border-color: var(--line); color: var(--navy); background: white; }
.app-header .button.quiet { border-color: rgba(255,255,255,0.25); color: white; background: rgba(255,255,255,0.1); }
.button:disabled { cursor: default; opacity: 0.45; }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-button { padding: 8px 12px; border: 1px solid #b9cfe4; border-radius: 999px; color: var(--navy); background: var(--blue-soft); font-weight: 700; }
.preset-button.active { border-color: var(--blue); color: white; background: var(--blue); }
.helper-text { min-height: 18px; margin: 8px 0 14px; font-size: 12px; }

.filter-panel { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 11px; font-weight: 750; }
.field input, .field select, .inline-heading select { width: 100%; min-height: 39px; padding: 8px 10px; border: 1px solid #cbd4dc; border-radius: 8px; color: var(--ink); background: white; }
.suffix-input { display: flex; align-items: center; border: 1px solid #cbd4dc; border-radius: 8px; background: white; }
.suffix-input input { min-width: 0; border: 0; }
.suffix-input span { padding-right: 10px; color: var(--muted); font-size: 11px; }
.filter-actions { display: flex; align-items: end; gap: 8px; }

.table-panel { overflow: hidden; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.table-toolbar p { margin: 0; color: var(--muted); }
.pagination { display: flex; align-items: center; gap: 10px; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 11px 13px; border-bottom: 1px solid #edf0f2; text-align: right; font-size: 12px; }
th { position: sticky; top: 0; color: var(--muted); background: #f9fafb; font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; }
th:first-child, td:first-child, th:last-child, td:last-child { text-align: left; }
tbody tr.clickable:hover { background: #f1f7fd; cursor: pointer; }
.model-pill, .signal-pill { display: inline-block; margin: 1px 3px 1px 0; padding: 3px 6px; border-radius: 999px; font-size: 10px; font-weight: 750; }
.model-pill.weibull { color: #165e4d; background: var(--green-soft); }
.model-pill.lognormal { color: #864d16; background: var(--orange-soft); }
.signal-pill { color: #40505f; background: #eef1f4; }
.signal-pill.alert { color: #8b302e; background: #f9e4e3; }

.detail-grid { margin-bottom: 16px; }
.metric-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 18px 12px; }
.mini-metric { padding: 10px; border-radius: 8px; background: #f3f6f8; }
.mini-metric span { display: block; color: var(--muted); font-size: 10px; }
.mini-metric strong { display: block; margin-top: 3px; font-size: 14px; }
.timeline-panel { margin-bottom: 16px; }
.timeline-status { margin: 14px 18px 0; padding: 10px 12px; border-radius: 8px; color: var(--muted); background: #f4f6f8; }
.timeline-status.error { color: #8b302e; background: #f9e4e3; }
.timeline-status.success { color: #155c4a; background: var(--green-soft); }
.toggle { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }

#toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 380px; padding: 12px 15px; border-radius: 9px; color: white; background: #263746; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: 180ms ease; }
#toast.visible { opacity: 1; transform: translateY(0); }

.login-body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 78% 18%, rgba(51, 142, 224, 0.3), transparent 30%),
    linear-gradient(135deg, #102b46, #17466f);
}
.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-card { width: min(100%, 430px); padding: 34px; border-radius: 16px; background: white; box-shadow: 0 22px 60px rgba(4, 20, 36, 0.3); }
.login-card h1 { color: var(--navy); font-size: 32px; }
.login-card .subtitle { margin-bottom: 24px; }
.login-form { display: grid; gap: 14px; }
.login-form input { min-height: 44px; padding: 9px 11px; border: 1px solid #cbd4dc; border-radius: 8px; }
.login-error { margin: 0; color: var(--red); font-size: 12px; font-weight: 700; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .filter-panel { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { max-width: 100%; justify-content: flex-start; }
}
@media (max-width: 760px) {
  .app-header, .section-heading, .inline-heading { align-items: flex-start; flex-direction: column; }
  .two-col { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-panel { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
}
