@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ink: #16212B;
  --surface: #FFFFFF;
  --bg: #EEF1F4;
  --border: #D8DEE3;
  --primary: #2F5D62;
  --primary-dark: #21454A;
  --accent: #C97B3D;
  --danger: #B14A4A;
  --success: #4C8C6B;
  --muted: #6B7A85;
  --sidebar-bg: #16212B;
  --sidebar-fg: #C7D0D6;
  --sidebar-fg-active: #FFFFFF;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  margin: 0 0 0.4em;
  letter-spacing: -0.01em;
}

code, .mono, .asset-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth (login) page ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(160deg, var(--sidebar-bg) 0%, var(--sidebar-bg) 42%, var(--bg) 42%);
}

.auth-card {
  width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px rgba(22, 33, 43, 0.18);
  padding: 36px 32px 32px;
}

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.auth-brand .mark {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 2px;
  display: inline-block;
}

.auth-brand h1 {
  font-size: 20px;
  color: var(--ink);
}

.auth-sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--ink);
}
.btn-outline:hover { border-color: var(--primary); text-decoration: none; }

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; text-decoration: none; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.demo-hint {
  margin-top: 20px;
  padding: 10px 12px;
  background: #F5F2EB;
  border: 1px solid #E4DCC8;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
  color: #6B5C3F;
}

/* ---------- App shell (post-login) ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  flex-shrink: 0;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
  padding: 0 6px;
}

.sidebar .brand .mark {
  width: 9px; height: 9px;
  background: var(--accent);
  border-radius: 2px;
}

.sidebar .brand span {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  color: #fff;
  font-size: 15px;
}

.sidebar nav a {
  display: block;
  padding: 9px 10px;
  border-radius: 4px;
  color: var(--sidebar-fg);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-fg-active);
  text-decoration: none;
}

.sidebar .role-tag {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 12px;
  color: var(--muted);
}

.sidebar .role-tag strong { color: #fff; display: block; }
.sidebar .role-tag__link {
  display: block;
  margin-top: 8px;
  color: var(--sidebar-fg);
  font-size: 11.5px;
}
.sidebar .role-tag__link:hover { color: #fff; }

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.topbar h2 { font-size: 16px; margin: 0; }

.topbar form { margin: 0; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Hamburger — hidden on desktop, shown in the mobile media query */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.nav-backdrop { display: none; }

.content { padding: 28px; }

/* ---------- Flash messages ---------- */

.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 18px;
  border-left: 3px solid transparent;
}
.flash-success { background: #EBF4EF; border-color: var(--success); color: #2C5C43; }
.flash-error { background: #F8EDEC; border-color: var(--danger); color: #7A2E2E; }

/* ---------- Cards / stat grid ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card .num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 28px;
  font-weight: 700;
}

.stat-card .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 4px;
}

.stat-card.accent { border-left-color: var(--accent); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.success { border-left-color: var(--success); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 24px;
}

/* ---------- Dashboard: attention band ---------- */

.attention {
  background: #FBF0DF;
  border: 1px solid #E9D3AC;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}
.attention.attention--clear {
  background: #EBF4EF;
  border-color: #C4E1D1;
  border-left-color: var(--success);
}
.attention__title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #7A5C2C;
  margin-bottom: 10px;
}
.attention--clear .attention__title { color: #2C5C43; margin-bottom: 0; }
.attention__items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.attention__items a {
  display: flex;
  align-items: baseline;
  gap: 7px;
  background: var(--surface);
  border: 1px solid #E9D3AC;
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--ink);
  font-size: 13px;
}
.attention__items a:hover { border-color: var(--accent); text-decoration: none; }
.attention__items .n {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 17px;
  color: var(--accent);
}

/* ---------- Dashboard: summary cards ---------- */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.summary-card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.summary-card__head > span {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 13px;
}
.summary-card__head a { font-size: 12px; }
.summary-card__big {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 12px;
}
.summary-card__big span {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.summary-card__rows { list-style: none; margin: 0; padding: 0; }
.summary-card__rows li {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  padding: 4px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
}
.summary-card__rows li span:last-child { color: var(--ink); font-weight: 600; }
.summary-card__rows li.is-alert span { color: var(--danger); }

/* ---------- Dashboard: 14-day spark bars ---------- */

.spark {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 90px;
}
.spark__col {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
}
.spark__bar {
  width: 100%;
  min-height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}
.spark__bar.is-zero { background: var(--border); }

.panel h3 {
  font-size: 15px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h3::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 1px;
}

/* ---------- Table ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-admin { background: #EAE3F5; color: #5B3C8C; }
.badge-staff { background: #E1EEF0; color: var(--primary-dark); }
.badge-client { background: #F5EADF; color: #8A5A2C; }
.badge-active { background: #E7F3EC; color: var(--success); }
.badge-inactive { background: #F3E7E7; color: var(--danger); }

/* Complaint status badges */
.badge-status-New { background: #E9EDF1; color: #445261; }
.badge-status-Assigned { background: #E1EEF0; color: var(--primary-dark); }
.badge-status-InProgress { background: #FBF0DF; color: #8A5A2C; }
.badge-status-Waiting { background: #FBF0DF; color: #8A5A2C; }
.badge-status-Resolved { background: #E7F3EC; color: var(--success); }
.badge-status-Closed { background: #EAEAEA; color: #555; }
.badge-status-Pending { background: #E9EDF1; color: #445261; }
.badge-status-Completed { background: #E7F3EC; color: var(--success); }
.badge-status-Verified { background: #EAE3F5; color: #5B3C8C; }

.badge-priority-Low { background: #E7F3EC; color: var(--success); }
.badge-priority-Medium { background: #FBF0DF; color: #8A5A2C; }
.badge-priority-High { background: #F8E5DC; color: #A15325; }
.badge-priority-Urgent { background: #F8DEDE; color: var(--danger); }

.badge-overdue { background: var(--danger); color: #fff; }

/* Complaint code, photo thumbnails, timeline */
.complaint-code { font-family: 'JetBrains Mono', monospace; font-weight: 600; }

.photo-thumb {
  max-width: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  margin-top: 8px;
}

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  padding: 12px 0 12px 18px;
  border-left: 2px solid var(--border);
  position: relative;
  margin-left: 4px;
}
.timeline li::before {
  content: '';
  position: absolute;
  left: -6px; top: 16px;
  width: 10px; height: 10px;
  background: var(--primary);
  border-radius: 50%;
  border: 2px solid var(--surface);
}
.timeline li:last-child { border-left-color: transparent; }
.timeline .t-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.timeline .t-note { font-size: 13.5px; }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-bar a {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--ink);
}
.filter-bar a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filter-bar a:hover { text-decoration: none; border-color: var(--primary); }

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }

/* ---------- Forms inline ---------- */

.inline-form { display: inline; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.form-grid .field { margin-bottom: 0; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

/* ---------- Upload preview (populated by /js/app.js) ---------- */

.upload-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  min-height: 0;
  font-size: 12px;
  color: var(--muted);
}
.upload-preview:empty { display: none; }

/* "Take photo" helper — most useful on phones/tablets; hidden where there is
   no touch pointer so a laptop file dialog button doesn't add noise. */
.take-photo-btn { display: none; margin-top: 6px; }
@media (pointer: coarse) {
  .take-photo-btn { display: inline-block; }
}
.upload-preview-img {
  max-width: 120px;
  max-height: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ---------- Mobile: sidebar becomes a slide-in drawer ---------- */

@media (max-width: 720px) {
  .nav-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 236px;
    z-index: 50;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .app-shell.nav-open .sidebar { transform: none; }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(22, 33, 43, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .app-shell.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  .main { width: 100%; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar h2 { flex: 1; font-size: 15px; }
  .topbar-actions { gap: 6px; }
  .content { padding: 18px 14px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }

  /* wide tables scroll instead of blowing out the layout */
  .panel > table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- Attendance devices (ADMS) ---------- */
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 8px 0 12px; }
.muted { color: var(--muted); font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); font-weight: 600; }
.table-scroll { overflow-x: auto; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .field { margin-bottom: 0; min-width: 220px; }
.field-actions { display: flex; align-items: flex-end; }
tr.row-warn td { background: #FDF7EC; }
tr.row-alert td { background: #FBEEEE; }
.log-detail { font-family: 'JetBrains Mono', monospace; font-size: 12px; word-break: break-word; max-width: 560px; }
.map-form { display: flex; gap: 6px; align-items: center; }
.map-form select { padding: 5px 8px; font-size: 12.5px; max-width: 280px; }

/* ---------- Attendance devices: list + form ---------- */
[hidden] { display: none !important; }
.section-head { margin: 4px 0 14px; }
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-family: 'Inter', sans-serif; font-weight: 600;
  padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.section-title::before { display: none; }
.section-sub { color: var(--muted); font-size: 13px; margin: 0; }
.panel--flush { padding: 0; overflow: hidden; }
.list-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.list-search {
  width: 100%; max-width: 320px; padding: 7px 11px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.list-search:focus { outline: none; border-color: var(--primary); }
.btn-add { width: auto; white-space: nowrap; }
.data-table thead th { background: #F7F8FA; padding-top: 14px; padding-bottom: 14px; }
.data-table td { vertical-align: middle; }
.data-table .muted-cell { color: var(--muted); }
.col-actions { text-align: right; white-space: nowrap; }
.row-actions { display: inline-flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.row-actions .btn { min-width: 64px; text-align: center; }
.type-pill {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
}
.type-pill--adms { background: #E7F3EC; color: var(--success); }
.type-pill--pull { background: #E1EEF0; color: var(--primary-dark); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.status-dot--on { background: var(--success); }
.status-dot--down { background: var(--danger); }
.status-dot--off { background: #A9B3BA; }

.panel .form-title { font-size: 18px; margin-bottom: 18px; text-transform: none; letter-spacing: -0.01em; color: var(--ink); }
.panel .form-title::before { display: none; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 28px; }
.form-2col .field { margin-bottom: 0; }
.field-span { grid-column: 1 / -1; }
.label-opt { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.radio-row { display: flex; gap: 22px; align-items: center; min-height: 38px; }
.radio, .check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 400; }
.radio input, .check input { width: auto; margin: 0; accent-color: var(--primary); }
.check input { width: 17px; height: 17px; }
.setup-box {
  margin-top: 20px; padding: 18px 20px; background: #F7F8FA;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.setup-box h4 { font-size: 15px; margin-bottom: 10px; }
.setup-box ol { margin: 0 0 10px; padding-left: 20px; color: var(--muted); font-size: 13.5px; line-height: 1.9; }
.setup-box ol strong, .setup-box code { color: var(--ink); }
.setup-box code { font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.setup-url { font-size: 13.5px; color: var(--muted); margin: 6px 0; }
.setup-warn { color: var(--accent); font-size: 13.5px; margin: 8px 0 0; }
.setup-tip { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.form-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.form-footer__actions { display: flex; gap: 8px; }
.form-footer__actions .btn { width: auto; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.kv-grid span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.kv-grid strong { font-size: 14px; font-weight: 600; }
@media (max-width: 720px) {
  .form-2col { grid-template-columns: 1fr; }
  .list-toolbar { flex-direction: column; align-items: stretch; }
  .list-search { max-width: none; }
}
.field label.radio, .field label.check { display: inline-flex; margin: 0; font-size: 14px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink); }
