:root {
  color-scheme: light;
  --navy: #082844;
  --navy-2: #144d70;
  --gold: #d1a52f;
  --gold-soft: #f7efd8;
  --green: #18794e;
  --green-soft: #e7f5ed;
  --red: #a1394b;
  --red-soft: #fbecef;
  --amber: #9a5a08;
  --amber-soft: #fff3d6;
  --ink: #202830;
  --muted: #68737c;
  --line: #dfe5e9;
  --surface: #ffffff;
  --canvas: #f3f5f6;
  --shadow: 0 10px 30px rgba(20, 39, 54, .12);
  --header-height: 64px;
  --sidebar-width: 246px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; background: var(--canvas); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.gate {
  position: fixed;
  z-index: 5000;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 24px 16px;
  background: #eef1f2;
}

.gate::before {
  position: fixed;
  inset: 0 0 auto;
  height: 34vh;
  background: var(--navy);
  content: "";
}

.gate__panel {
  position: relative;
  width: min(100%, 460px);
  padding: 28px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--gold);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gate__brand { display: flex; align-items: center; gap: 13px; margin-bottom: 30px; }
.gate__brand img { border: 1px solid var(--line); border-radius: 6px; object-fit: contain; }
.gate__brand strong { display: block; color: var(--navy); font-size: 1.1rem; }
.gate__brand span { display: block; margin-top: 3px; color: var(--muted); font-size: .82rem; }
.gate h1 { margin: 0 0 10px; color: var(--navy); font-size: 1.45rem; line-height: 1.2; letter-spacing: 0; }
.gate p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.gate__form { display: grid; gap: 9px; margin-top: 22px; }
.gate__form label { color: var(--ink); font-size: .8rem; font-weight: 750; }
.gate__form input, .gate__form select { width: 100%; min-height: 46px; margin-bottom: 6px; border: 1px solid #cbd4d9; border-radius: 6px; padding: 10px 12px; color: var(--ink); background: #fff; }
.gate__form input:focus, .gate__form select:focus { border-color: var(--navy-2); outline: 3px solid rgba(20, 77, 112, .14); }
.gate__privacy { margin-top: 24px !important; padding-top: 18px; border-top: 1px solid var(--line); font-size: .76rem !important; }
.gate__message { margin-top: 16px !important; border-left: 3px solid var(--red); padding: 10px 12px; color: #7f2536 !important; background: var(--red-soft); }
.gate__erase { margin-top: 15px; color: var(--red) !important; }

.progress { height: 4px; margin-top: 24px; overflow: hidden; background: #e7ecef; }
.progress span { display: block; width: 38%; height: 100%; background: var(--gold); animation: loading 1.2s ease-in-out infinite alternate; }
@keyframes loading { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

.app { min-height: 100vh; }
.app-header {
  position: fixed;
  z-index: 1200;
  inset: 0 0 auto;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid #15394e;
  padding: 0 18px;
  color: #fff;
  background: var(--navy);
}

.app-header__menu { display: none; color: #fff !important; border-color: rgba(255,255,255,.25) !important; }
.app-brand { display: flex; min-width: 210px; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.app-brand img { border-radius: 5px; background: #fff; object-fit: contain; }
.app-brand strong, .app-brand small { display: block; }
.app-brand strong { font-size: .96rem; }
.app-brand small { max-width: 180px; margin-top: 2px; overflow: hidden; color: #cbd9e2; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.app-header__actions { display: flex; align-items: center; gap: 7px; margin-left: auto; }

.connection { display: inline-flex; align-items: center; gap: 7px; color: #dce8ee; font-size: .78rem; font-weight: 700; }
.connection__dot { width: 8px; height: 8px; border-radius: 50%; background: #f0aa33; }
.connection[data-state="online"] .connection__dot { background: #51c98b; }
.connection[data-state="syncing"] .connection__dot { background: var(--gold); animation: pulse .8s infinite alternate; }
.connection[data-state="error"] .connection__dot { background: #ee7788; }
@keyframes pulse { to { opacity: .35; } }

.app-layout { min-height: 100vh; padding-top: var(--header-height); }
.sidebar {
  position: fixed;
  z-index: 1100;
  inset: var(--header-height) auto 0 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.sidebar nav { flex: 1; overflow-y: auto; padding: 16px 10px; }
.nav-link {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 11px;
  margin-bottom: 3px;
  border-left: 3px solid transparent;
  padding: 8px 11px;
  color: #46525a;
  font-size: .86rem;
  font-weight: 650;
  text-decoration: none;
}
.nav-link:hover { color: var(--navy); background: #f1f5f7; }
.nav-link[aria-current="page"] { border-left-color: var(--gold); color: var(--navy); background: var(--gold-soft); }
.nav-link__icon { display: grid; width: 26px; height: 26px; place-items: center; border: 1px solid #ccd6dc; border-radius: 5px; font-size: .66rem; font-weight: 850; }
.nav-link[aria-current="page"] .nav-link__icon { border-color: #d8b956; background: #fff; }
.sidebar__footer { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 13px 14px; }
.sidebar__footer span { flex: 1; color: var(--muted); font-size: .7rem; line-height: 1.35; }
.sidebar-backdrop { position: fixed; z-index: 1050; inset: var(--header-height) 0 0; border: 0; background: rgba(10, 26, 36, .48); }

.workspace { min-height: calc(100vh - var(--header-height)); margin-left: var(--sidebar-width); padding: 28px clamp(18px, 3vw, 42px) 50px; outline: none; }
.workspace__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.workspace__head h1 { margin: 3px 0 5px; color: var(--navy); font-size: clamp(1.45rem, 2.5vw, 2rem); line-height: 1.15; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--gold-d, #745812); font-size: .68rem; font-weight: 850; text-transform: uppercase; }
.page-subtitle { max-width: 680px; margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.workspace__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 15px;
  color: var(--ink);
  background: #fff;
  font-size: .82rem;
  font-weight: 750;
  text-decoration: none;
}
.button:hover { filter: brightness(.97); }
.button:focus-visible, .icon-button:focus-visible, .row-action:focus-visible, .nav-link:focus-visible { outline: 3px solid rgba(209,165,47,.42); outline-offset: 2px; }
.button--primary { border-color: var(--navy); color: #fff; background: var(--navy); }
.button--secondary { border-color: #bdc8ce; color: var(--navy); background: #fff; }
.button--danger { border-color: var(--red); color: #fff; background: var(--red); }
.button--text { min-height: 34px; border: 0; padding: 5px 7px; color: var(--navy-2); background: transparent; }
.button--compact { min-height: 36px; border-color: rgba(255,255,255,.3); padding: 7px 11px; color: #fff; background: rgba(255,255,255,.08); }
.button[disabled], .icon-button[disabled] { cursor: not-allowed; opacity: .55; }
.icon-button { width: 38px; height: 38px; flex: 0 0 38px; border: 1px solid #cbd4d9; border-radius: 6px; padding: 0; color: var(--navy); background: #fff; font-size: 1rem; }
.app-header .icon-button { border-color: rgba(255,255,255,.25); color: #fff; background: rgba(255,255,255,.06); }
.icon-button--danger { color: #ffd8de !important; }
.count { min-width: 20px; border-radius: 10px; padding: 2px 6px; color: var(--navy); background: var(--gold); font-size: .7rem; text-align: center; }

.notice { margin-bottom: 18px; border-left: 4px solid var(--navy-2); padding: 12px 14px; color: #264150; background: #e8f1f6; font-size: .84rem; line-height: 1.45; }
.notice[data-kind="success"] { border-left-color: var(--green); color: #125b3b; background: var(--green-soft); }
.notice[data-kind="warning"] { border-left-color: var(--amber); color: #754306; background: var(--amber-soft); }
.notice[data-kind="error"] { border-left-color: var(--red); color: #7e2d3b; background: var(--red-soft); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { min-width: 0; border: 1px solid var(--line); border-top: 3px solid var(--navy-2); border-radius: 6px; padding: 16px; background: #fff; }
.metric:nth-child(2) { border-top-color: var(--green); }
.metric:nth-child(3) { border-top-color: var(--gold); }
.metric:nth-child(4) { border-top-color: var(--red); }
.metric__label { display: block; color: var(--muted); font-size: .75rem; }
.metric__value { display: block; margin-top: 7px; color: var(--navy); font-size: 1.75rem; line-height: 1; }
.metric__meta { display: block; margin-top: 8px; color: var(--muted); font-size: .7rem; }

.section { margin-top: 22px; }
.section__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 9px; }
.section__head h2 { margin: 0; color: var(--navy); font-size: 1rem; letter-spacing: 0; }
.section__head span { color: var(--muted); font-size: .76rem; }
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(270px, .65fr); gap: 18px; align-items: start; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar__search { position: relative; min-width: 220px; flex: 1; }
.toolbar input, .toolbar select, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd4d9;
  border-radius: 5px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}
.toolbar input:focus, .toolbar select:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy-2); outline: 3px solid rgba(20,77,112,.11); }
.toolbar select { width: auto; min-width: 145px; }

.data-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.data-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.data-table th { padding: 10px 12px; color: #59656d; background: #f5f7f8; font-size: .68rem; text-align: left; text-transform: uppercase; }
.data-table td { border-top: 1px solid #edf0f2; padding: 11px 12px; vertical-align: middle; }
.data-table tr:hover td { background: #fbfcfc; }
.data-table .actions { width: 1%; white-space: nowrap; text-align: right; }
.primary-text { display: block; color: var(--ink); font-weight: 750; }
.secondary-text { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }
.row-actions { display: inline-flex; gap: 4px; }
.row-action { min-width: 32px; min-height: 32px; border: 1px solid #cdd6db; border-radius: 5px; padding: 5px 8px; color: var(--navy); background: #fff; font-size: .72rem; font-weight: 750; }
.row-action--danger { border-color: #e7bec6; color: var(--red); }
.row-action--success { border-color: #b9dcc8; color: var(--green); }

.badge { display: inline-block; border-radius: 12px; padding: 3px 8px; color: #43515a; background: #edf1f3; font-size: .67rem; font-weight: 800; }
.badge--success { color: #125b3b; background: var(--green-soft); }
.badge--danger { color: #7d2d3b; background: var(--red-soft); }
.badge--warning { color: #764506; background: var(--amber-soft); }
.badge--pending { color: #614b0c; background: var(--gold-soft); }

.list { border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.list-row { display: flex; min-width: 0; align-items: center; gap: 12px; border-top: 1px solid #edf0f2; padding: 12px 14px; }
.list-row:first-child { border-top: 0; }
.list-row__main { min-width: 0; flex: 1; }
.list-row__title { overflow: hidden; color: var(--ink); font-size: .84rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.list-row__meta { margin-top: 3px; color: var(--muted); font-size: .72rem; line-height: 1.4; }

.empty-state { border: 1px dashed #c8d1d6; border-radius: 6px; padding: 42px 18px; color: var(--muted); background: rgba(255,255,255,.55); text-align: center; }
.empty-state strong { display: block; color: var(--navy); font-size: .95rem; }
.empty-state p { max-width: 440px; margin: 7px auto 0; font-size: .8rem; line-height: 1.5; }

.attendance-list { border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.attendance-row { display: grid; grid-template-columns: minmax(160px, 1fr) 116px minmax(160px, 1fr); align-items: center; gap: 12px; border-top: 1px solid #edf0f2; padding: 10px 12px; }
.attendance-row:first-child { border-top: 0; }
.attendance-row input[type="text"] { width: 100%; min-height: 36px; border: 1px solid #d7dee2; border-radius: 5px; padding: 7px 9px; }
.toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.toggle input { width: 18px; height: 18px; accent-color: var(--green); }

.birthday-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.birthday-item { border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 6px; padding: 13px; background: #fff; }
.birthday-item strong { color: var(--navy); font-size: .85rem; }
.birthday-item span { display: block; margin-top: 5px; color: var(--muted); font-size: .73rem; }

.dialog { width: min(94vw, 680px); max-height: min(90vh, 820px); border: 0; border-radius: 8px; padding: 0; color: var(--ink); background: #fff; box-shadow: 0 22px 70px rgba(7,31,48,.3); }
.dialog--small { width: min(94vw, 460px); }
.dialog::backdrop { background: rgba(7, 27, 39, .6); }
.dialog__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding: 18px 20px; }
.dialog__head h2 { margin: 3px 0 0; color: var(--navy); font-size: 1.15rem; letter-spacing: 0; }
.dialog__body { display: grid; max-height: calc(90vh - 150px); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; overflow-y: auto; padding: 20px; }
.dialog--small .dialog__body { display: block; }
.dialog__body > p { margin: 0; line-height: 1.55; }
.dialog__footer { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); padding: 14px 20px; }
.field { min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: #45515a; font-size: .74rem; font-weight: 750; }
.field textarea { min-height: 92px; resize: vertical; }
.field__hint { display: block; margin-top: 5px; color: var(--muted); font-size: .68rem; line-height: 1.4; }
.check-field { display: flex; align-items: center; gap: 8px; min-height: 42px; padding-top: 19px; color: #45515a; font-size: .78rem; font-weight: 700; }
.check-field input { width: 18px; height: 18px; accent-color: var(--navy); }

.conflict { border-left: 4px solid var(--red); }
.conflict__actions { display: flex; gap: 6px; }
.queue-code { display: inline-block; max-width: 180px; overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .66rem; text-overflow: ellipsis; white-space: nowrap; }

.toast-region { position: fixed; z-index: 6000; right: 18px; bottom: calc(18px + var(--safe-bottom)); display: grid; width: min(360px, calc(100vw - 36px)); gap: 8px; }
.toast { border-left: 4px solid var(--navy-2); border-radius: 6px; padding: 12px 14px; color: #fff; background: #263942; box-shadow: var(--shadow); font-size: .8rem; line-height: 1.4; }
.toast[data-kind="success"] { border-left-color: #73d5a3; }
.toast[data-kind="error"] { border-left-color: #ff8da0; }
.toast[data-kind="warning"] { border-left-color: #f1c75e; }

.mobile-nav { display: none; }
.noscript { position: fixed; z-index: 9000; inset: 0; margin: 0; padding: 40px 20px; color: #fff; background: var(--navy); text-align: center; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .birthday-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  :root { --header-height: 58px; }
  .app-header { gap: 9px; padding: 0 11px; }
  .app-header__menu { display: block; }
  .app-brand { min-width: 0; flex: 1; }
  .app-brand small { max-width: 130px; }
  .connection { display: none; }
  .app-header__actions .button { width: 38px; overflow: hidden; padding: 0; color: transparent; }
  .app-header__actions .button::before { color: #fff; content: "\21BB"; font-size: 1.1rem; }
  .app-header__actions .button .count { position: absolute; margin: -25px 0 0 19px; color: var(--navy); }
  .sidebar { transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.is-open { transform: translateX(0); }
  .workspace { margin-left: 0; padding: 22px 15px calc(82px + var(--safe-bottom)); }
  .workspace__head { gap: 14px; }
  .mobile-nav { position: fixed; z-index: 1000; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); background: #fff; }
  .mobile-nav .nav-link { min-width: 0; min-height: 58px; flex-direction: column; justify-content: center; gap: 2px; margin: 0; border: 0; border-top: 3px solid transparent; padding: 4px 2px; font-size: .62rem; }
  .mobile-nav .nav-link[aria-current="page"] { border-top-color: var(--gold); }
  .mobile-nav .nav-link__icon { width: auto; height: auto; border: 0; background: transparent; font-size: .62rem; }
  .data-panel { overflow-x: auto; }
  .data-table { min-width: 690px; }
}

@media (max-width: 620px) {
  .gate__panel { padding: 22px 18px; }
  .workspace__head { display: block; }
  .workspace__actions { justify-content: flex-start; margin-top: 14px; }
  .metric-grid { gap: 8px; }
  .metric { padding: 13px; }
  .metric__value { font-size: 1.45rem; }
  .birthday-grid { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; }
  .toolbar__search, .toolbar select { width: 100%; }
  .attendance-row { grid-template-columns: 1fr 100px; }
  .attendance-row input[type="text"] { grid-column: 1 / -1; }
  .dialog__body { grid-template-columns: 1fr; padding: 16px; }
  .field--wide { grid-column: auto; }
  .dialog__head, .dialog__footer { padding-inline: 16px; }
  .dialog__footer .button { flex: 1; }
}

@media print {
  .app-header, .sidebar, .mobile-nav, .workspace__actions, .toolbar, .row-actions { display: none !important; }
  .workspace { margin: 0; padding: 0; }
  body { background: #fff; }
}
