:root {
  --surface: #ffffff;
  --page: #f6f6f4;
  --page-alt: #f0efec;
  --ink: #16150f;
  --ink-secondary: #5c5a53;
  --ink-muted: #96938a;
  --gridline: #ebeae5;
  --gridline-strong: #dedcd4;
  --baseline: #d5d3c9;
  --border: rgba(22, 21, 15, 0.08);
  --brand: #2a78d6;
  --brand-ink: #184f95;
  --brand-tint: #eef4fc;
  --danger: #d03b3b;
  --good: #0ca30c;
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(22, 21, 15, 0.04), 0 1px 1px rgba(22, 21, 15, 0.03);
  --shadow: 0 4px 16px rgba(22, 21, 15, 0.06), 0 1px 3px rgba(22, 21, 15, 0.05);
  --shadow-lg: 0 12px 32px rgba(22, 21, 15, 0.1), 0 2px 8px rgba(22, 21, 15, 0.05);
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  font-variant-numeric: proportional-nums;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, 'SF Pro Text', system-ui, 'Segoe UI', sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--brand-ink);
}

h1,
h2,
h3 {
  margin: 0 0 0.5em;
  font-weight: 650;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 1.6rem;
}
h2 {
  font-size: 1.05rem;
}

.muted {
  color: var(--ink-muted);
}
.small {
  font-size: 0.85rem;
}

/* ---------- Layout ---------- */

.topbar {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 60px;
}

.brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.brand-logo {
  height: 24px;
  width: auto;
  display: block;
}

.nav {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
}

.navlink {
  color: var(--ink-secondary);
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.89rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.navlink:hover {
  background: var(--page-alt);
  color: var(--ink);
}

.navlink.active {
  color: var(--brand-ink);
  background: var(--brand-tint);
  font-weight: 600;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.userinfo {
  font-size: 0.86rem;
  color: var(--ink-secondary);
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 72px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

/* ---------- Panels & cards ---------- */

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

.panel-highlight {
  border-color: rgba(42, 120, 214, 0.25);
  background: var(--brand-tint);
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 14px 0;
}
.kv dt {
  color: var(--ink-muted);
  font-size: 0.85rem;
}
.kv dd {
  margin: 0;
}
.kv code {
  font-size: 1.05rem;
  background: var(--page-alt);
  padding: 3px 9px;
  border-radius: 6px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.87rem;
  color: var(--ink-secondary);
}

.field input,
.field select,
.field textarea {
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  padding: 9px 12px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.mini-input:focus,
.note-input:focus,
.status-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.16);
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.checkbox-field input {
  width: auto;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

textarea {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  resize: vertical;
}

.inline-form {
  display: inline;
}

.inline-edit-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.mini-input {
  font: inherit;
  font-size: 0.88rem;
  padding: 5px 8px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  max-width: 140px;
}

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

.btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 17px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 2px rgba(42, 120, 214, 0.25);
}
.btn-primary:hover {
  background: var(--brand-ink);
}

.btn-secondary {
  background: var(--page-alt);
  color: var(--ink);
  border-color: transparent;
}
.btn-secondary:hover {
  background: var(--gridline-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-secondary);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--page-alt);
  color: var(--ink);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: rgba(208, 59, 59, 0.3);
}
.btn-danger-ghost:hover {
  background: #fdeeed;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.81rem;
}
.btn-xs {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* ---------- Flash / alerts ---------- */

.flash {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.flash-error {
  background: #fdeeed;
  color: #7a1f1f;
  border: 1px solid rgba(208, 59, 59, 0.25);
}
.flash-info {
  background: var(--brand-tint);
  color: #123a66;
  border: 1px solid rgba(42, 120, 214, 0.25);
}

/* ---------- Auth page ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 0%, var(--page-alt), var(--page) 60%);
}
.auth-card {
  width: 100%;
  max-width: 368px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: block;
  height: 52px;
  width: auto;
  margin: 0 auto 18px;
}
.auth-title {
  margin-bottom: 4px;
  text-align: center;
}
.auth-sub {
  color: var(--ink-muted);
  margin-top: 0;
  margin-bottom: 24px;
  font-size: 0.9rem;
  text-align: center;
}
.auth-alt-link {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 0;
  font-size: 0.85rem;
}

/* ---------- Legend ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 0.82rem;
  color: var(--ink-secondary);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* ---------- Week nav ---------- */

.week-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.week-label {
  font-weight: 600;
  font-size: 0.92rem;
}

/* ---------- Employee week grid ---------- */

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  overflow-x: auto;
}

.day-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 124px;
  box-shadow: var(--shadow-sm);
}
.day-col.is-today {
  border-color: var(--brand);
  box-shadow: 0 0 0 1.5px var(--brand) inset;
}

.day-head {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-secondary);
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}
.day-date {
  font-weight: 400;
  color: var(--ink-muted);
  font-size: 0.74rem;
}

.cell {
  border: 1px solid;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.84rem;
  font-weight: 600;
  min-height: 56px;
}
.cell-empty {
  color: var(--ink-muted);
  border: 1px dashed var(--gridline-strong);
  font-weight: 400;
  align-items: center;
  justify-content: center;
  display: flex;
}
.cell-time {
  font-weight: 400;
  font-size: 0.77rem;
}
.cell-note {
  font-weight: 400;
  font-size: 0.77rem;
  color: var(--ink-secondary);
}

/* ---------- Manager grid table ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.grid-table,
.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.87rem;
}

.grid-table th,
.grid-table td,
.data-table th,
.data-table td {
  border-bottom: 1px solid var(--gridline);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

.grid-table tbody tr:last-child td,
.data-table tbody tr:last-child td {
  border-bottom: none;
}

.grid-table tbody tr:hover td,
.data-table tbody tr:hover td {
  background: var(--page-alt);
}

.grid-table thead th,
.data-table thead th {
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--gridline-strong);
}

.grid-table th.is-today,
.grid-table td.is-today {
  background: var(--brand-tint);
}
.grid-table tbody tr:hover td.is-today {
  background: #e5eefb;
}

.th-date {
  font-weight: 400;
  text-transform: none;
  color: var(--ink-muted);
}

.row-head {
  white-space: nowrap;
  font-weight: 600;
  background: var(--surface);
  position: sticky;
  left: 0;
}
.row-sub {
  display: block;
  font-weight: 400;
  color: var(--ink-muted);
  font-size: 0.74rem;
}
.row-head-cell {
  font-weight: 600;
  white-space: nowrap;
}
.row-inactive {
  opacity: 0.5;
}

.edit-cell {
  min-width: 150px;
}

.status-select {
  width: 100%;
  font: inherit;
  font-size: 0.81rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  margin-bottom: 4px;
  background: var(--page-alt);
  color: var(--ink-secondary);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.status-select.status-ON {
  background: #e3f6e3;
  color: #0a6b0a;
}
.status-select.status-OFF {
  background: #ececea;
  color: #4a4945;
}
.status-select.status-HOLIDAY {
  background: #e4eefc;
  color: #184f95;
}
.status-select.status-LATE {
  background: #fcefd7;
  color: #7a4e00;
}
.status-select.status-MIA {
  background: #fbe6e5;
  color: #a12727;
}

.note-input {
  width: 100%;
  font-size: 0.77rem;
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gridline-strong);
}

.save-pending {
  box-shadow: 0 0 0 2px rgba(42, 120, 214, 0.4) !important;
}
.save-ok {
  box-shadow: 0 0 0 2px rgba(12, 163, 12, 0.4) !important;
}
.save-error {
  box-shadow: 0 0 0 2px rgba(208, 59, 59, 0.5) !important;
}

/* ---------- Pills / badges ---------- */

.pill {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.pill-ok {
  background: #e3f6e3;
  color: #0a6b0a;
}
.pill-muted {
  background: var(--page-alt);
  color: var(--ink-muted);
}

.role-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.role-ADMIN {
  background: #fcefd7;
  color: #7a4e00;
}
.role-MANAGER {
  background: #e4eefc;
  color: #184f95;
}
.role-EMPLOYEE {
  background: #ececea;
  color: #4a4945;
}
.role-VIEWER {
  background: #f1eafc;
  color: #5b2f9e;
}

/* ---------- Report table & bars ---------- */

.num-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.total-cell {
  font-weight: 700;
}
.bar-cell {
  min-width: 180px;
}
.bar-track {
  height: 13px;
  background: var(--page-alt);
  border-radius: 4px;
  display: flex;
  gap: 2px;
  overflow: hidden;
}
.bar-seg {
  height: 100%;
  min-width: 3px;
  border-radius: 2px;
}

.quick-ranges {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Notes ---------- */

.note-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.note-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}
.note-content {
  margin-bottom: 8px;
}
.note-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .topbar-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 18px;
  }
  .nav {
    order: 3;
    width: 100%;
  }
  .week-grid {
    grid-template-columns: 1fr;
  }
}
