/* ── Tokens ────────────────────────────────────────── */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #16a34a;
  --accent-light: #f0fdf4;
  --accent-border: #bbf7d0;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.08);
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }
table { border-collapse: collapse; }

/* ── Shell ─────────────────────────────────────────── */
.shell { max-width: 1440px; margin: 0 auto; padding: 0 24px; }

/* ── Nav ───────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px;
}
.nav-left { display: flex; align-items: center; gap: 24px; }
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.nav-brand img { width: 28px; height: 28px; }
.nav-links { display: flex; gap: 4px; }
.nav-link {
  padding: 5px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  transition: all .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg); }
.nav-link--active { color: #fff; background: var(--text); }
.nav-link--active:hover { color: #fff; background: #1f2937; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--text); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.nav-user-info { line-height: 1.2; }
.nav-user-name { font-size: 13px; font-weight: 600; }
.nav-user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.nav-user-btn {
  display: flex; align-items: center; padding: 4px; border: none;
  background: none; border-radius: 8px; transition: background .15s;
}
.nav-user-btn:hover { background: var(--bg); }

/* ── User Dropdown ─────────────────────────────────── */
.user-dropdown {
  position: absolute; right: 0; top: 100%; margin-top: 8px;
  width: 220px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 100; overflow: hidden;
}
.user-dropdown-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.user-dropdown-name { font-size: 13px; font-weight: 600; }
.user-dropdown-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.user-dropdown-body { padding: 4px; }
.user-dropdown-item {
  display: block; padding: 8px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  transition: background .1s;
}
.user-dropdown-item:hover { background: var(--bg); color: var(--text); }
.user-dropdown-item--danger { color: #dc2626; }
.user-dropdown-item--danger:hover { background: #fef2f2; color: #dc2626; }
.dropdown-enter { transition: opacity .15s ease, transform .15s ease; }
.dropdown-leave { transition: opacity .1s ease, transform .1s ease; }

/* ── Page Header ───────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; padding: 28px 0 20px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.page-meta { display: flex; gap: 12px; flex-wrap: wrap; }
.meta-pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px;
  box-shadow: var(--shadow);
}
.meta-pill-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.meta-pill-value { font-size: 13px; font-weight: 600; margin-top: 1px; }

/* ── Controls Card ─────────────────────────────────── */
.controls {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  box-shadow: var(--shadow); margin-bottom: 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.controls label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.controls input[type="date"],
.controls select {
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; background: var(--surface);
  transition: border-color .15s;
}
.controls input:focus,
.controls select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.btn {
  padding: 6px 16px; border: none; border-radius: 6px;
  font-size: 13px; font-weight: 600;
  background: var(--text); color: #fff;
  transition: background .15s;
}
.btn:hover { background: #1f2937; }
.htmx-indicator { font-size: 12px; color: var(--text-muted); display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ── Table Card ────────────────────────────────────── */
.table-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); margin-bottom: 32px;
}

/* ── Scorecard Table ───────────────────────────────── */
.scorecard { width: 100%; font-feature-settings: "tnum"; }
.scorecard th {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
  background: var(--surface);
}
.scorecard th:first-child { text-align: left; }
.scorecard th:not(:first-child) { text-align: right; }
.scorecard th.col-current { background: var(--accent-light); color: var(--accent); }

.scorecard td { padding: 9px 16px; border-bottom: 1px solid #f3f4f6; font-size: 13px; }
.scorecard td:first-child { font-weight: 500; color: var(--text); white-space: nowrap; }
.scorecard td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.scorecard td.col-current { background: var(--accent-light); color: var(--text); font-weight: 600; }

.scorecard tr:hover td { background: #fafbfc; }
.scorecard tr:hover td.col-current { background: #e8fbe8; }
.scorecard tr:last-child td { border-bottom: none; }

/* Section separator */
.scorecard .section-start td { border-top: 2px solid var(--border-strong); }
.scorecard .section-label {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted);
  padding-right: 8px;
}

/* ── TRIR Editable Cell ────────────────────────────── */
.trir-value {
  cursor: pointer;
  border-bottom: 1px dashed var(--border-strong);
  transition: border-color .15s;
}
.trir-value:hover { border-color: var(--accent); color: var(--accent); }

.trir-popover {
  position: absolute; right: 0; top: 100%; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow-lg); z-index: 20;
  display: flex; align-items: flex-end; gap: 8px;
  white-space: nowrap;
}
.trir-popover label { font-size: 11px; font-weight: 600; color: var(--text-secondary); display: flex; flex-direction: column; gap: 3px; }
.trir-popover input {
  width: 72px; padding: 5px 8px; border: 1px solid var(--border);
  border-radius: 5px; font-size: 13px; text-align: right;
}
.trir-popover input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.trir-popover .btn { padding: 5px 12px; font-size: 12px; }

/* ── Toast ─────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 100; }
.toast {
  background: var(--text); color: #fff;
  padding: 10px 20px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .3s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Login Page ────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px; max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg); text-align: center;
}
.login-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; }
.login-card .error { color: var(--danger); background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px; padding: 10px; font-size: 13px; margin-bottom: 16px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-weight: 500;
  color: var(--text); transition: all .15s;
}
.google-btn:hover { border-color: var(--border-strong); background: var(--bg); }
.google-btn svg { width: 18px; height: 18px; }
.login-card .hint { font-size: 11px; color: var(--text-muted); margin-top: 16px; }

/* ── Report Library ────────────────────────────────── */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-top: 20px; }
.report-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.report-card:hover { border-color: var(--accent-border); }
.report-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.report-card p { font-size: 13px; color: var(--text-secondary); }
.report-card .badge { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 8px; }
.report-card .badge--muted { color: var(--text-muted); }
.report-card--disabled { opacity: .5; pointer-events: none; }

/* ── Loading State ─────────────────────────────────── */
.loading-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 64px 24px; color: var(--text-muted); gap: 12px;
}
.loading-state p { font-size: 13px; font-weight: 500; }
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ────────────────────────────────────────── */
@media (max-width: 768px) {
  .shell { padding: 0 12px; }
  .nav-inner { height: 48px; }
  .nav-brand span { display: none; }
  .nav-user-info { display: none; }
  .nav-right { gap: 8px; }
  .nav-avatar { width: 28px; height: 28px; font-size: 10px; }

  .page-header { padding: 16px 0 12px; flex-direction: column; }
  .page-title { font-size: 18px; }
  .page-meta { width: 100%; }
  .meta-pill { flex: 1; min-width: 0; padding: 6px 10px; }
  .meta-pill-label { font-size: 9px; }
  .meta-pill-value { font-size: 12px; }

  .controls { padding: 10px 12px; gap: 8px; }
  .controls label { font-size: 11px; }
  .controls input[type="date"],
  .controls select { padding: 5px 8px; font-size: 12px; }
  .btn { padding: 5px 12px; font-size: 12px; }

  .table-card { border-radius: 0; margin-left: -12px; margin-right: -12px; border-left: none; border-right: none; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .scorecard { min-width: 600px; }
  .scorecard th { padding: 8px 10px; font-size: 9px; }
  .scorecard td { padding: 7px 10px; font-size: 12px; }
  .scorecard .section-label { font-size: 8px; }

  .trir-popover { right: auto; left: 0; }

  .toast-container { bottom: 12px; right: 12px; left: 12px; }
  .toast { width: 100%; text-align: center; }

  .report-grid { grid-template-columns: 1fr; }
}

/* ── Small mobile ──────────────────────────────────── */
@media (max-width: 480px) {
  .nav-links { gap: 2px; }
  .nav-link { padding: 4px 8px; font-size: 12px; }
  .controls { flex-direction: column; align-items: stretch; }
  .controls label { justify-content: space-between; }
}

/* ── Safety TRIR Calendar ──────────────────────────── */
.safety-table th { text-align: center; }
.safety-table th:first-child { text-align: left; }
.safety-table td { text-align: center; vertical-align: middle; }
.safety-table td:first-child { text-align: left; }
.safety-input {
  width: 80px; padding: 5px 8px; border: 1px solid var(--border);
  border-radius: 5px; font-size: 13px; text-align: right;
  transition: border-color .15s;
}
.safety-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.safety-input--wide { width: 110px; }
.trir-computed { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-size: 13px; }
.has-data-dot::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  background: var(--accent); border-radius: 50%; margin-right: 6px; vertical-align: middle;
}
.row-changed { background: #eff6ff !important; }
.row-changed td { background: inherit !important; }
.safety-actions {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 0 32px; position: sticky; bottom: 0;
  background: var(--bg); z-index: 10;
}
.safety-hint { font-size: 12px; color: #3b82f6; font-weight: 500; }
.btn--accent { background: var(--accent); }
.btn--accent:hover { background: #15803d; }
.toast-banner {
  background: var(--accent-light); border: 1px solid var(--accent-border);
  color: var(--accent); border-radius: var(--radius);
  padding: 10px 16px; font-size: 13px; font-weight: 500; margin-bottom: 16px;
}

/* ── Alpine cloak ──────────────────────────────────── */
[x-cloak] { display: none !important; }
