:root {
  color-scheme: light;   /* app is light-mode only */
  --indigo: #4338ca;
  --indigo-600: #4f46e5;
  --indigo-50: #eef2ff;
  --green: #16a34a;
  --green-50: #dcfce7;
  --amber: #d97706;
  --amber-50: #fef3c7;
  --red: #dc2626;
  --red-50: #fee2e2;
  --blue: #0284c7;
  --blue-50: #e0f2fe;
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1e2233;
  --muted: #6b7280;
  --border: #e6e8f0;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(20,20,50,.06), 0 8px 24px rgba(20,20,50,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--indigo-600); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }

/* ---------- Nav ---------- */
.nav { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.nav-inner { max-width: 1100px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-size: 1.15rem; color: var(--text); font-weight: 500; }
.brand img { height: 30px; width: 30px; object-fit: contain; border-radius: 7px; }
.brand b { color: var(--indigo); font-weight: 700; }
.nav-links { display: flex; align-items: center; gap: .3rem; margin-left: auto; }
.nav-links a { padding: .5rem .8rem; border-radius: 10px; color: var(--text); font-size: .93rem; font-weight: 500; display: flex; align-items: center; gap: .45rem; }
.nav-links a:hover { background: var(--indigo-50); }
.nav-links a.active { background: var(--indigo-50); color: var(--indigo); }
.nav-links a.logout { color: var(--muted); }
.nav-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--indigo); color: #fff; font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; }
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; }
.nav-toggle { display: none; margin-left: auto; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: .68rem; padding: .05rem .4rem; font-weight: 700; }

/* ---------- Layout ---------- */
.container { max-width: 1100px; width: 100%; margin: 0 auto; padding: 1.4rem 1rem 2.5rem; flex: 1; }
.page-head { margin-bottom: 1.3rem; }
.page-head h1 { margin-bottom: .1rem; }
.grid { display: grid; gap: 1.1rem; margin-bottom: 1.1rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 780px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem; box-shadow: var(--shadow); }
.card-flat { box-shadow: none; }
.card-title { margin-bottom: 1rem; font-size: 1rem; font-weight: 650; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid transparent; border-radius: 11px; padding: .6rem 1.1rem; font-size: .92rem; font-weight: 600; cursor: pointer; font-family: inherit; transition: .15s; background: #eef0f6; color: var(--text); }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--indigo); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--indigo-50); border-color: var(--indigo-50); }
.btn-block { width: 100%; }
.btn-lg { padding: .85rem 1.3rem; font-size: 1rem; }
.btn-sm { padding: .38rem .8rem; font-size: .82rem; border-radius: 9px; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.link-btn { background: none; border: none; color: var(--indigo-600); cursor: pointer; font-size: .84rem; padding: .15rem 0; font-family: inherit; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: #374151; margin-bottom: .85rem; }
input, select, textarea { width: 100%; margin-top: .35rem; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 10px; font-size: .95rem; font-family: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--indigo-600); box-shadow: 0 0 0 3px var(--indigo-50); }
input:disabled { background: #f3f4f6; color: var(--muted); }
textarea { resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 520px) { .field-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; justify-content: flex-end; }
.inline-input { max-width: 220px; }

/* ---------- Flash ---------- */
.flash-wrap { margin-bottom: 1rem; display: grid; gap: .5rem; }
.flash { padding: .7rem 1rem; border-radius: 11px; font-size: .9rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 1px solid transparent; }
.flash-success { background: var(--green-50); color: #14532d; border-color: #bbf7d0; }
.flash-danger { background: var(--red-50); color: #7f1d1d; border-color: #fecaca; }
.flash-warning, .flash-warn { background: var(--amber-50); color: #78350f; border-color: #fde68a; }
.flash-info { background: var(--blue-50); color: #075985; border-color: #bae6fd; }
.flash-x { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: inherit; opacity: .6; }

/* ---------- Auth ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: linear-gradient(150deg, #eef2ff, #f4f5fb 60%); }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 2rem 1.8rem; width: 100%; max-width: 390px; box-shadow: var(--shadow); }
.auth-head { text-align: center; margin-bottom: 1.4rem; }
.auth-logo { height: 62px; width: 62px; object-fit: contain; border-radius: 14px; margin-bottom: .6rem; }
.auth-head h1 { font-size: 1.5rem; }
.auth-head h1 b { color: var(--indigo); }
.auth-form label { text-align: left; }
.auth-hint { text-align: center; font-size: .8rem; margin-top: 1rem; margin-bottom: 0; }

/* ---------- Attendance ---------- */
.status-row { display: flex; gap: .8rem; margin-bottom: 1.2rem; }
.status-box { flex: 1; background: #f7f8fc; border: 1px solid var(--border); border-radius: 13px; padding: .9rem; text-align: center; }
.status-box.done { background: var(--green-50); border-color: #bbf7d0; }
.status-label { display: block; font-size: .78rem; color: var(--muted); font-weight: 600; }
.status-time { display: block; font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin-top: .1rem; }
.attendance-actions { display: flex; gap: .7rem; }
.attendance-actions .btn { flex: 1; }
.geo-hint { font-size: .8rem; margin: .9rem 0 0; }
.geo-msg { font-size: .86rem; margin: .6rem 0 0; min-height: 1rem; }
.geo-msg.ok, .geo-msg.geo-ok { color: var(--green); }
.geo-msg.err, .geo-msg.geo-err { color: var(--red); }
.geo-msg.geo-loading { color: var(--muted); }

/* ---------- Stats ---------- */
.stat-grid { display: flex; gap: .8rem; }
.stat { flex: 1; text-align: center; background: #f7f8fc; border-radius: 13px; padding: 1rem .5rem; }
.stat-num { display: block; font-size: 1.9rem; font-weight: 750; color: var(--indigo); letter-spacing: -.02em; }
.stat-label { font-size: .78rem; color: var(--muted); }
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.2rem; }
@media (max-width: 680px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.stat-card .stat-num { color: var(--text); }
.stat-card.accent-green .stat-num { color: var(--green); }
.stat-card.accent-blue .stat-num { color: var(--blue); }
.stat-card.accent-amber .stat-num { color: var(--amber); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .5rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .65rem .6rem; border-bottom: 1px solid #f1f2f7; white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.row-inactive { opacity: .55; }
.member-cell { display: flex; align-items: center; gap: .5rem; }

/* ---------- Pills ---------- */
.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 650; background: #eef0f6; color: var(--muted); }
.pill-success { background: var(--green-50); color: #14532d; }
.pill-danger { background: var(--red-50); color: #7f1d1d; }
.pill-warn { background: var(--amber-50); color: #78350f; }
.pill-info { background: var(--blue-50); color: #075985; }

/* ---------- Avatars ---------- */
.avatar-lg, .avatar-sm { border-radius: 50%; background: var(--indigo); color: #fff; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.avatar-lg { width: 110px; height: 110px; font-size: 2.2rem; }
.avatar-sm { width: 30px; height: 30px; font-size: .74rem; }
.avatar-lg img, .avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.profile-photo { display: flex; flex-direction: column; align-items: center; gap: .8rem; }
.file-btn { cursor: pointer; }

/* Profile layout: narrow photo column + wide details, then full-width rows.
   The save action is a plain bar, not a card. */
.profile-grid {
  display: grid;
  grid-template-columns: minmax(0, 290px) minmax(0, 1fr);
  gap: 1.1rem;
  align-items: stretch;   /* photo card matches the details card's height */
  margin-bottom: 1.1rem;
}
/* Fill the taller card and centre the avatar block in the leftover space. */
.profile-photo-card { display: flex; flex-direction: column; }
.profile-photo-card .profile-photo { flex: 1; justify-content: center; }
.profile-grid > .span-full { grid-column: 1 / -1; }
.profile-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}
.actions-hint { font-size: .82rem; margin-right: auto; }

/* Tablet: photo column stops earning its keep — stack everything. */
@media (max-width: 780px) {
  .profile-grid { grid-template-columns: 1fr; }
  .profile-grid > * { grid-column: 1 / -1; }
}
/* Phone: full-width tap target, hint above it. */
@media (max-width: 520px) {
  .profile-actions { justify-content: stretch; gap: .6rem; }
  .profile-actions .btn { width: 100%; }
  .actions-hint { margin-right: 0; width: 100%; text-align: center; }
}

/* ---------- Leaves ---------- */
.leave-list { display: grid; gap: .7rem; }
.leave-item { display: flex; justify-content: space-between; gap: 1rem; padding: .9rem; border: 1px solid var(--border); border-radius: 12px; background: #fafbfe; flex-wrap: wrap; }
.leave-main { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.leave-type { font-weight: 650; font-size: .92rem; }
.leave-dates { font-size: .85rem; color: #374151; }
.leave-reason { font-size: .82rem; }
.leave-side { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; }
.review-form { display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; }

/* ---------- Tabs / chips ---------- */
.admin-tabs { display: flex; gap: .3rem; margin-top: .9rem; flex-wrap: wrap; overflow-x: auto; }
.tab { padding: .45rem .85rem; border-radius: 10px; font-size: .88rem; font-weight: 550; color: var(--muted); white-space: nowrap; }
.tab:hover { background: var(--indigo-50); }
.tab.active { background: var(--indigo); color: #fff; }
.filter-row { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.chip { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); font-size: .85rem; color: var(--muted); background: #fff; }
.chip.active { background: var(--indigo); color: #fff; border-color: var(--indigo); }
.chip-static { background: #f7f8fc; }
.chip-list { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 1.2rem 0; }
.add-member summary { cursor: pointer; font-weight: 600; }
.action-cell { display: flex; flex-direction: column; gap: .2rem; }
.kv { list-style: none; padding: 0; margin: 1rem 0; }
.kv li { display: flex; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid #f1f2f7; font-size: .9rem; }
.kv li span { color: var(--muted); }
.geo-preview { display: flex; justify-content: center; padding: 1rem 0; }
.geo-ring { width: 130px; height: 130px; border-radius: 50%; border: 3px dashed var(--indigo); background: var(--indigo-50); display: flex; align-items: center; justify-content: center; position: relative; }
.geo-ring::after { content: ''; width: 12px; height: 12px; background: var(--indigo); border-radius: 50%; position: absolute; }
.geo-ring span { position: absolute; bottom: 10px; font-size: .75rem; font-weight: 700; color: var(--indigo); }
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 4rem; color: var(--indigo); }
.footer { text-align: center; padding: 1.2rem; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--border); background: var(--card); }
.footer b { color: var(--indigo); }

/* ---------- Mobile nav ---------- */
@media (max-width: 720px) {
  .nav-toggle { display: block; }
  .nav-links { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--card); border-bottom: 1px solid var(--border); padding: .5rem; gap: .2rem; box-shadow: var(--shadow); }
  .nav-links.open { display: flex; }
  .nav-links a { padding: .7rem .9rem; }
  .nav-name { display: inline; }
}

/* ---------- Charts / statistics ---------- */
.chart-card { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .2rem; flex-wrap: wrap; }
.chart-sub { font-size: .82rem; color: var(--muted); margin: 0 0 .6rem; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: var(--indigo-600); transition: fill .12s; }
.chart .bar-hit:hover + .bar, .chart .bar.hot { fill: var(--indigo); }
.chart .bar-hit { fill: transparent; cursor: pointer; }
.chart .bar-label { fill: var(--text); font-size: 11px; font-weight: 600; font-family: var(--font); }
.chart-empty { text-align: center; color: var(--muted); padding: 2rem 0; font-size: .9rem; }
.chart-tip { position: absolute; pointer-events: none; background: #1e2233; color: #fff; padding: .4rem .6rem; border-radius: 8px; font-size: .78rem; line-height: 1.35; white-space: nowrap; opacity: 0; transition: opacity .12s; z-index: 20; transform: translate(-50%, -115%); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.chart-tip.show { opacity: 1; }
.chart-tip b { font-weight: 700; }

/* segmented status bar */
.seg-bar { display: flex; width: 100%; height: 34px; border-radius: 8px; overflow: hidden; gap: 2px; background: var(--card); }
.seg { display: flex; align-items: center; justify-content: center; color: #fff; font-size: .78rem; font-weight: 700; min-width: 2px; }
.seg-approved { background: var(--green); }
.seg-pending { background: var(--amber); }
.seg-rejected { background: var(--red); }
.seg-legend { display: flex; gap: 1.1rem; flex-wrap: wrap; margin-top: .7rem; font-size: .82rem; }
.seg-legend span { display: inline-flex; align-items: center; gap: .4rem; color: var(--text); }
.seg-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* data table disclosure */
.data-table { margin-top: .9rem; }
.data-table summary { cursor: pointer; font-size: .8rem; color: var(--muted); }
.data-table summary:hover { color: var(--indigo-600); }

.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.rank-list li { display: grid; grid-template-columns: 1.4rem 1fr auto; align-items: center; gap: .6rem; font-size: .88rem; }
.rank-num { color: var(--muted); font-size: .78rem; font-weight: 700; }
.rank-bar-wrap { background: #eef0f6; border-radius: 5px; height: 9px; overflow: hidden; }
.rank-bar { background: var(--indigo-600); height: 100%; border-radius: 5px; }
.rank-name { font-size: .86rem; margin-bottom: .25rem; display: block; }
.rank-val { font-variant-numeric: tabular-nums; font-weight: 650; font-size: .84rem; }
