:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --green-light: #e8f5e9;
  --red: #c62828;
  --red-light: #fdecea;
  --blue: #1565c0;
  --purple: #6a1b9a;
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e3e5e8;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --sidebar-bg: #171b21;
  --sidebar-text: #b8bec7;
  --sidebar-text-active: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

/* Without this, any element whose own rule sets `display` (like
   .modal-overlay's `display: flex` below) silently overrides the
   [hidden] attribute's default `display: none` — the class rule and
   the UA's [hidden] rule have equal specificity, so source order wins,
   and ours loads after the browser's default stylesheet. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.error-text { color: var(--red); font-size: 13px; margin-top: 8px; }
.empty-state { color: var(--text-muted); text-align: center; padding: 48px 20px; }
.text-right { text-align: right; }

.text-link {
  background: none; border: none; color: var(--green); cursor: pointer;
  font-size: 13px; padding: 0; font-family: inherit;
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1b5e20 0%, #2e7d32 45%, #43a047 100%);
  padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 40px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand h1 { margin: 12px 0 4px; font-size: 22px; }
.login-logo {
  width: 48px; height: 48px; border-radius: 12px; background: var(--green);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; margin: 0 auto;
}

.account-list { display: flex; flex-direction: column; gap: 8px; }
.account-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; border: 1px solid transparent; text-align: left;
  width: 100%; font: inherit; color: inherit; transition: border-color .12s;
}
.account-row:hover { border-color: var(--green); background: var(--green-light); }
.account-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--green-light); color: var(--green);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.account-avatar.large { width: 56px; height: 56px; font-size: 24px; margin: 0 auto 8px; }
.account-name { font-weight: 600; }

.pin-header { text-align: center; margin-top: 4px; }
.pin-header h2 { margin: 0 0 2px; font-size: 18px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 24px 0; }
.pin-dot { width: 12px; height: 12px; border-radius: 50%; background: #d5d5d5; display: inline-block; }
.pin-dot.filled { background: var(--green); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 240px; margin: 0 auto; }
.keypad button {
  aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--border); background: var(--card);
  font-size: 18px; cursor: pointer; transition: background .1s;
}
.keypad button:hover { background: var(--bg); }
.keypad-spacer { visibility: hidden; border: none !important; }

/* ---------- App shell ---------- */

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

.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 20px 18px;
  font-weight: 700; color: #fff; font-size: 15px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  background: none; border: none; color: var(--sidebar-text); font-size: 14px;
  cursor: pointer; text-align: left; font-family: inherit;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--green); color: #fff; font-weight: 600; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.08); }
.session-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.session-name { color: #fff; font-weight: 600; font-size: 13px; }
.sidebar-footer .text-link { color: #ff8a80; }

.main-content { flex: 1; padding: 28px 36px 60px; max-width: 1200px; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header h2 { margin: 0; font-size: 22px; }

.segmented { display: inline-flex; background: #eceef1; border-radius: 8px; padding: 3px; }
.segmented-option {
  padding: 7px 14px; border: none; background: none; border-radius: 6px;
  font-size: 13px; cursor: pointer; color: var(--text); font-family: inherit;
}
.segmented-option.active { background: var(--card); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- Dashboard ---------- */

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.dashboard-grid .span-full { grid-column: 1 / -1; }

.stat-card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }

.section-card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.section-card h4 { margin: 0 0 10px; font-size: 14px; }
.section-row {
  display: flex; justify-content: space-between; padding: 8px 0; font-size: 13px;
  border-top: 1px solid var(--border);
}
.section-row:first-of-type { border-top: none; }

/* ---------- Tables ---------- */

.table-card {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-muted); padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table .thumb {
  width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--bg);
  display: flex; align-items: center; justify-content: center; font-size: 15px; overflow: hidden;
}
.data-table .thumb img { width: 100%; height: 100%; object-fit: cover; }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--text-muted); font-size: 12px; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-low { background: var(--red-light); color: var(--red); }
.badge-action-create { background: var(--green-light); color: var(--green-dark); }
.badge-action-update { background: #e3edfb; color: var(--blue); }
.badge-action-delete { background: var(--red-light); color: var(--red); }

.detail-grid { display: flex; flex-direction: column; gap: 16px; max-width: 480px; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,20,25,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--card); width: 100%; max-width: 480px;
  border-radius: 14px; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.icon-button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.modal-body input, .modal-body select {
  font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-weight: 400;
}
.modal-footer { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }

.photo-picker { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.photo-preview {
  width: 88px; height: 88px; border-radius: 12px; object-fit: cover; background: var(--bg);
  display: flex; align-items: center; justify-content: center; font-size: 28px; border: 1px solid var(--border);
}

/* ---------- Buttons ---------- */

.primary-button {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.primary-button:hover { background: var(--green-dark); }
.modal-footer .primary-button { flex: 1; padding: 12px; }
.secondary-button {
  background: var(--red-light); color: var(--red); border: none; border-radius: 8px;
  padding: 12px; font-size: 14px; font-weight: 600; cursor: pointer; flex: 1; font-family: inherit;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1a1a1a; color: #fff; padding: 12px 22px; border-radius: 8px;
  font-size: 13px; z-index: 200; max-width: 90%; text-align: center; box-shadow: var(--shadow);
}

.color-green { color: var(--green); }
.color-red { color: var(--red); }
.color-blue { color: var(--blue); }
.color-purple { color: var(--purple); }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar-brand { padding: 14px 16px; }
  .sidebar-nav { flex-direction: row; flex: 1; overflow-x: auto; padding: 8px 12px; }
  .sidebar-footer { border-top: none; padding: 8px 16px; }
  .main-content { padding: 20px; }
}
