:root {
  --navy: #0f2a4a;
  --navy-light: #16395f;
  --teal: #0e8a7a;
  --teal-light: #e6f5f2;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e6ed;
  --text: #1d2733;
  --text-muted: #6b7685;
  --danger: #d64545;
  --warn: #e0a013;
  --ok: #2e9e5b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 60%, var(--teal) 130%);
}
.login-card {
  background: var(--card);
  padding: 40px 36px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 360px;
  text-align: center;
}
.login-logo { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 18px; letter-spacing: 0.5px; margin: 0 0 4px; color: var(--navy); }
.login-card .subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card button {
  margin-top: 6px; padding: 11px; border: none; border-radius: 8px; background: var(--teal);
  color: white; font-weight: 600; font-size: 14px; cursor: pointer;
}
.login-card button:hover { background: #0c7568; }

/* ---------- App shell ---------- */
.topbar {
  background: var(--navy);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 64px;
  gap: 32px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 26px; }
.brand-title { font-weight: 700; font-size: 14px; letter-spacing: 0.5px; }
.brand-sub { font-size: 12px; color: #9fb6cf; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs a {
  color: #c8d6e5; text-decoration: none; padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
}
.tabs a:hover { background: rgba(255,255,255,0.08); color: white; }
.tabs a.active { background: var(--teal); color: white; }
.user-menu { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #c8d6e5; }
.btn-link { background: none; border: none; color: #c8d6e5; cursor: pointer; font-size: 13px; text-decoration: underline; }
.btn-link:hover { color: white; }

.view { padding: 24px 28px 60px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.page-head h2 { margin: 0; font-size: 20px; color: var(--navy); }
.report-date { color: var(--text-muted); font-size: 13px; }
.hint { color: var(--text-muted); font-size: 13px; margin: -4px 0 16px; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--navy); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; color: var(--navy); }
.table-wrap { overflow-x: auto; padding: 0; }
.table-wrap table { margin: 0; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { background: #fafbfc; color: var(--text-muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; }
.data-table tbody tr:hover { background: #f8fafc; }
.sortable th { cursor: pointer; user-select: none; }
.sortable th:hover { color: var(--navy); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-Aplus, .badge-A { background: #e3f6ea; color: var(--ok); }
.badge-B { background: #e6f0fb; color: #1a5fb4; }
.badge-C { background: #fff4dd; color: var(--warn); }
.badge-D, .badge-E { background: #fde7e7; color: var(--danger); }

.status-pill { padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.status-Pending { background: #fff4dd; color: var(--warn); }
.status-Resolved { background: #e3f6ea; color: var(--ok); }
.status-Closed { background: #eceff3; color: var(--text-muted); }

.alert-OVERDUE { color: var(--danger); font-weight: 700; }
.alert-WATCH { color: var(--warn); font-weight: 700; }
.alert-OK { color: var(--ok); font-weight: 700; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--teal); color: white; border: none; padding: 9px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #0c7568; }
.btn-secondary {
  background: white; color: var(--text); border: 1px solid var(--border); padding: 9px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-secondary:hover { background: #f4f6f9; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.btn-icon:hover { background: #eceff3; }

/* ---------- Forms / modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 42, 74, 0.45); display: flex; align-items: center;
  justify-content: center; z-index: 100; padding: 20px;
}
.modal-form {
  background: var(--card); border-radius: var(--radius); padding: 26px 28px; width: 420px; max-width: 100%;
  display: flex; flex-direction: column; gap: 12px; max-height: 90vh; overflow-y: auto;
}
.modal-form h3 { margin: 0 0 6px; color: var(--navy); }
.modal-form label { font-size: 13px; font-weight: 600; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.modal-form input, .modal-form select, .modal-form textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.autofill-preview { background: var(--teal-light); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; color: var(--navy); }

.form-error { color: var(--danger); font-size: 13px; min-height: 16px; }
.form-success { color: var(--ok); font-size: 13px; min-height: 16px; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.inline-form input {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; flex: 1; min-width: 180px;
}

/* ---------- Settings groups ---------- */
.settings-group { margin-bottom: 18px; }
.settings-group h4 { margin: 0 0 10px; font-size: 13px; color: var(--navy); text-transform: uppercase; letter-spacing: 0.4px; }
.settings-row {
  display: grid; grid-template-columns: 1fr 110px; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.settings-row .meta { font-size: 13px; }
.settings-row .meta .note { color: var(--text-muted); font-size: 11.5px; display: block; margin-top: 2px; }
.settings-row input { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; width: 100%; }

/* ---------- Lookup ---------- */
.lookup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.lookup-grid .panel dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; }
.lookup-grid .panel dt { color: var(--text-muted); }
.lookup-grid .panel dd { margin: 0; font-weight: 600; text-align: right; }
