/* Two themes: White (default) and Blue (dark navy). Every color below comes from
   these tokens, so switching the theme repaints the whole page, not just the header. */
:root, :root[data-theme="white"] {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1b2430;
  --muted: #5b6676;
  --line: #d5dbe3;
  --line-soft: #e6eaef;
  --primary: #1f5fa8;
  --primary-dark: #174a84;
  --on-primary: #ffffff;
  --navy: #1f3b5c;
  --green: #1f7a3a;
  --green-bg: #e3f3e6;
  --red: #b42318;
  --red-bg: #fbe4e2;
  --red-border: #e3a29c;
  --amber: #8a5300;
  --amber-bg: #fdf0d5;
  --gray-bg: #eceff3;
  --blue-bg: #e1ecf8;
  --blue-fg: #183f6b;
  --th-bg: #f5f7fa;
  --row-alt: #fafbfc;
  --row-hover: #eef4fb;
  --btn-hover: #f2f5f8;
  --btn-hover-border: #9aa6b6;
  --input-bg: #ffffff;
  --input-border: #b8c1cd;
  --focus: #86b3ea;
  --dash: #9dbbe0;
  --top-bg: #ffffff;
  --top-fg: #1b2430;
  --top-line: #d5dbe3;
  --top-btn: #b8c1cd;
  --top-hover: #f2f4f7;
  --brand: #1f5fa8;
  --login-bg: #e9edf2;
  --overlay: rgba(15, 25, 40, .5);
  --radius: 8px;
  font-size: 17px;
  color-scheme: light;
}

:root[data-theme="blue"] {
  --bg: #0f1c2c;
  --panel: #172a40;
  --text: #e8eef5;
  --muted: #a7b4c4;
  --line: #2c4560;
  --line-soft: #233a53;
  --primary: #4f9be8;
  --primary-dark: #3d86d1;
  --on-primary: #08131f;
  --navy: #4f9be8;
  --green: #6fd38c;
  --green-bg: #183d2a;
  --red: #ff8f85;
  --red-bg: #4a1f22;
  --red-border: #8a3a37;
  --amber: #f3c26b;
  --amber-bg: #45351a;
  --gray-bg: #22364d;
  --blue-bg: #1d3b5e;
  --blue-fg: #cfe3fa;
  --th-bg: #1d3350;
  --row-alt: #1a2e46;
  --row-hover: #21405f;
  --btn-hover: #21384f;
  --btn-hover-border: #4c6888;
  --input-bg: #0f2133;
  --input-border: #3b5876;
  --focus: #4f9be8;
  --dash: #3f6a96;
  --top-bg: #13243a;
  --top-fg: #e8eef5;
  --top-line: #2c4560;
  --top-btn: #3f5d7e;
  --top-hover: #1f3550;
  --brand: #e8eef5;
  --login-bg: #0f1c2c;
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
[hidden] { display: none !important; }
h1 { font-size: 1.7rem; margin: 0 0 6px; }
h2 { font-size: 1.3rem; margin: 0 0 12px; }
h3 { font-size: 1.1rem; margin: 0 0 10px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

/* ---------- buttons and fields ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 46px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--btn-hover-border); background: var(--btn-hover); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 1px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-green { background: #1f7a3a; border-color: #1f7a3a; color: #fff; }
.btn-green:hover { background: #17612d; border-color: #17612d; }
.btn-danger { background: var(--panel); border-color: var(--red-border); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-danger-solid { background: #b42318; border-color: #b42318; color: #fff; }
.btn-light { background: transparent; color: var(--top-fg); border-color: var(--top-btn); }
.btn-light:hover { background: var(--top-hover); }
.btn-wide { width: 100%; }
.btn-big { font-size: 1.08rem; min-height: 54px; padding: 12px 26px; }
.btn[disabled] { opacity: .55; cursor: wait; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-weight: 600; }
.field .hint { font-size: .9rem; color: var(--muted); }
input, select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  min-height: 46px;
}
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: center; font-size: 1rem; padding: 6px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; }
.form-error {
  background: var(--red-bg); color: var(--red); padding: 12px 14px; border-radius: var(--radius);
  margin-bottom: 14px; font-weight: 600;
}

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--login-bg); }
.login-box { background: var(--panel); padding: 34px; border-radius: 12px; width: 100%; max-width: 420px; border: 1px solid var(--line); }

/* ---------- layout ---------- */
.shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  background: var(--top-bg);
  color: var(--top-fg);
  border-bottom: 2px solid var(--top-line);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  flex-wrap: wrap;
}
.brand { font-size: 1.2rem; font-weight: 700; color: var(--brand); }
.site-pick { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.site-pick select { min-width: 260px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.user-name { opacity: .9; }
.demo-badge { background: #ffd666; color: #3d2c00; padding: 4px 10px; border-radius: 6px; font-weight: 600; font-size: .9rem; }

.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.sidebar a {
  display: block; padding: 13px 16px; border-radius: var(--radius); color: var(--text);
  text-decoration: none; font-weight: 600; font-size: 1.02rem;
}
.sidebar a:hover { background: var(--gray-bg); }
.sidebar a.active { background: var(--primary); color: var(--on-primary); }
.sidebar a.nav-accent { border: 2px dashed var(--dash); color: var(--primary); margin: 6px 0; }
.sidebar a.nav-accent.active { color: var(--on-primary); border-color: var(--primary); }

.content { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 18px; }
.toolbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; }
.toolbar .grow { flex: 1; min-width: 220px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.tile {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 14px 16px;
  text-align: left; font: inherit; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; justify-content: flex-start;
}
.tile:hover { border-color: var(--btn-hover-border); }
.tile.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--blue-bg) inset; }
.tile .num { font-size: 2.1rem; font-weight: 700; line-height: 1.1; }
.tile .lbl { font-weight: 600; margin-top: 4px; }
.tile .sub { font-size: .88rem; color: var(--muted); }
.tile.green .num { color: var(--green); }
.tile.red .num { color: var(--red); }
.tile.amber .num { color: var(--amber); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.list th { background: var(--th-bg); font-weight: 700; font-size: .95rem; position: sticky; top: 0; z-index: 1; }
table.list tbody tr:nth-child(even) { background: var(--row-alt); }
table.list tbody tr.clickable { cursor: pointer; }
table.list tbody tr.clickable:hover { background: var(--row-hover); }
table.list td.num, table.list th.num { text-align: center; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 1.05rem; }

.status { display: inline-block; padding: 4px 12px; border-radius: 20px; font-weight: 700; font-size: .92rem; white-space: nowrap; }
.status.green { background: var(--green-bg); color: var(--green); }
.status.red { background: var(--red-bg); color: var(--red); }
.status.amber { background: var(--amber-bg); color: var(--amber); }
.status.gray { background: var(--gray-bg); color: var(--muted); }
.status.blue { background: var(--blue-bg); color: var(--blue-fg); }

.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--gray-bg); display: inline-grid; place-items: center; font-weight: 700; color: var(--muted); flex: none; }
.person { display: flex; align-items: center; gap: 12px; }
.person b { display: block; }
.person .muted { font-size: .9rem; }

/* ---------- timesheet ---------- */
.sheet-wrap { overflow: auto; max-height: 70vh; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: .9rem; }
table.sheet th, table.sheet td { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 6px 4px; text-align: center; min-width: 56px; }
table.sheet th { background: var(--th-bg); position: sticky; top: 0; z-index: 2; }
table.sheet th.name, table.sheet td.name { position: sticky; left: 0; background: var(--panel); text-align: left; min-width: 230px; padding: 6px 12px; z-index: 1; }
table.sheet th.name { z-index: 3; background: var(--th-bg); }
table.sheet td.c-ok { background: var(--green-bg); }
table.sheet td.c-late { background: var(--amber-bg); }
table.sheet td.c-absent { background: var(--red-bg); color: var(--red); }
table.sheet td.c-weekend, table.sheet th.c-weekend { background: var(--gray-bg); }
table.sheet td.total { font-weight: 700; background: var(--row-alt); }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 12px 0 0; font-size: .92rem; }
.legend span::before { content: ""; display: inline-block; width: 16px; height: 16px; border-radius: 3px; vertical-align: -3px; margin-right: 6px; border: 1px solid var(--line); }
.legend .l-ok::before { background: var(--green-bg); }
.legend .l-late::before { background: var(--amber-bg); }
.legend .l-absent::before { background: var(--red-bg); }
.legend .l-weekend::before { background: var(--gray-bg); }

.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.fold > summary {
  cursor: pointer; font-weight: 700; font-size: 1.05rem; padding: 14px 18px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; color: var(--primary); list-style-position: inside;
}
.fold > summary:hover { background: var(--row-hover); }
.fold[open] > summary { margin-bottom: 12px; }
.presets .btn.active { background: var(--navy); color: var(--on-primary); border-color: var(--navy); }

/* ---------- employee form / card ---------- */
.form-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.photo-box {
  width: 72%; margin: 0 auto; aspect-ratio: 3 / 4; border: 2px dashed var(--input-border); border-radius: 10px; background: var(--row-alt);
  display: grid; place-items: center; overflow: hidden; text-align: center; color: var(--muted); padding: 10px;
}
.photo-box img, .photo-box video { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.tips { font-size: .9rem; color: var(--muted); margin: 12px 0 0; padding-left: 18px; }
.tips li { margin-bottom: 3px; }
.req { color: var(--red); }
.form-foot { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.card-head { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.card-photo { width: 170px; aspect-ratio: 3/4; border-radius: 10px; object-fit: cover; background: var(--gray-bg); display: grid; place-items: center; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 10px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.sync-list { list-style: none; padding: 0; margin: 0; }
.sync-list li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.notice { padding: 14px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600; }
.notice.green { background: var(--green-bg); color: var(--green); }
.notice.red { background: var(--red-bg); color: var(--red); }
.notice.amber { background: var(--amber-bg); color: var(--amber); }
.notice.blue { background: var(--blue-bg); color: var(--blue-fg); font-weight: 400; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px; width: 100%; max-width: 520px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.toast {
  position: fixed; right: 24px; bottom: 24px; background: #1f3b5c; color: #fff; padding: 16px 22px;
  border-radius: 10px; font-weight: 600; z-index: 60; max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.error { background: #b42318; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; }

@media (max-width: 900px) {
  :root { font-size: 16px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .sidebar a { white-space: nowrap; padding: 10px 12px; }
  .content { padding: 16px; }
  .form-grid, .two { grid-template-columns: 1fr; }
  .site-pick select { min-width: 0; }
}

@media print {
  .topbar, .sidebar, .toolbar, .presets, .btn { display: none !important; }
  .shell { display: block; }
  .sheet-wrap { max-height: none; overflow: visible; }
}

.event-note { display: block; font-size: .85rem; color: var(--muted); }
