/* ====== Tokens ====== */
:root {
  --bg: #f7f5f0;
  --bg-card: #ffffff;
  --bg-soft: #f1ede5;
  --ink: #1a1a1a;
  --ink-2: #5a5752;
  --ink-3: #8c8a85;
  --line: #e8e3d8;
  --line-2: #ddd6c7;
  --accent: #c2410c;       /* terracotta */
  --accent-soft: #fef0e6;
  --accent-ink: #7c2d12;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #a16207;
  --warn-soft: #fef9c3;
  --danger: #be123c;
  --danger-soft: #ffe4e6;
  --info: #1e40af;
  --info-soft: #dbeafe;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(20,20,20,.04);
  --shadow: 0 4px 18px rgba(40, 30, 10, .06);
  --shadow-lg: 0 14px 40px rgba(40, 30, 10, .12);

  --font-sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 0% 0%, rgba(194, 65, 12, .04), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(120, 113, 108, .05), transparent 40%);
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--ink-3); font-size: 13px; }
.error-msg { color: var(--danger); font-size: 13px; padding: 8px 10px; background: var(--danger-soft); border-radius: 8px; }
.error-msg[hidden] { display: none; }

/* ====== Login ====== */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px;
  box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-logo {
  display: inline-grid;
  place-items: center;
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--accent), #ea580c);
  color: #fff;
  border-radius: 16px;
  font-size: 28px;
  margin-bottom: 12px;
  box-shadow: 0 6px 20px rgba(194, 65, 12, .25);
}
.login-header h1 { font-size: 22px; margin-bottom: 4px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.form input, .form select, .form textarea {
  padding: 11px 12px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
  transition: all .15s ease;
}
.form input:focus, .form select:focus, .form textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(194, 65, 12, .12);
}
.login-hint {
  margin-top: 24px;
  padding: 14px;
  background: var(--bg-soft);
  border-radius: 10px;
  font-size: 12px;
  color: var(--ink-2);
}
.login-hint strong { display: block; margin-bottom: 8px; color: var(--ink); }
.hint-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.hint-grid span {
  font-family: var(--font-mono);
  font-size: 11px;
  background: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 14px;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; transform: translateY(-1px); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 22px; color: var(--ink-3);
  transition: all .15s;
}
.btn-icon:hover { background: var(--bg-soft); color: var(--ink); }
.btn-text {
  background: none;
  border: none;
  color: var(--ink-2);
  font-size: 13px;
  padding: 6px 0;
  text-align: left;
}
.btn-text:hover { color: var(--accent); }

/* ====== Layout ====== */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #ea580c);
  color: #fff;
  border-radius: 10px;
  font-size: 20px;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: .05em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  transition: all .15s ease;
}
.nav-item:hover { background: var(--bg-soft); color: var(--ink); }
.nav-item.active {
  background: var(--ink);
  color: #fff;
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px;
  font-size: 14px;
  color: var(--ink-3);
}
.admin-only { display: none; }
.is-admin .admin-only { display: flex; }

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--bg-soft);
  border-radius: 10px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 14px;
}
.user-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }

/* ====== Main ====== */
.main { min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 28px 36px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.topbar h2 { font-size: 24px; }
.clock {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.content { padding: 28px 36px 60px; }

/* ====== Cards ====== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 900px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* Stat card */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label {
  font-size: 12px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
.stat-value-sm { font-size: 22px; font-weight: 600; font-family: var(--font-sans); }
.stat-foot { font-size: 12px; color: var(--ink-3); }

/* ====== Check-in panel ====== */
.checkin-hero {
  background: linear-gradient(135deg, #1c1917, #292524);
  color: #fff;
  border-radius: var(--radius);
  padding: 32px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
  position: relative;
  overflow: hidden;
}
.checkin-hero::before {
  content: '';
  position: absolute;
  top: -40%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(194, 65, 12, .35), transparent 70%);
  pointer-events: none;
}
.checkin-hero > * { position: relative; }
.hero-time {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.hero-date {
  font-size: 14px;
  color: rgba(255, 255, 255, .7);
  margin-top: 8px;
  text-transform: capitalize;
}
.hero-status {
  font-size: 13px;
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, .1);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .15);
}
.hero-status.is-active {
  background: rgba(34, 197, 94, .15);
  border-color: rgba(34, 197, 94, .35);
  color: #86efac;
}
.dot {
  width: 8px; height: 8px;
  background: currentColor;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}
.hero-actions { display: flex; flex-direction: column; gap: 10px; min-width: 200px; }
.btn-big {
  padding: 16px 24px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  border: none;
}
.btn-checkin { background: var(--accent); color: #fff; }
.btn-checkin:hover { background: #ea580c; }
.btn-checkout { background: rgba(255, 255, 255, .12); color: #fff; border: 1px solid rgba(255, 255, 255, .2); }
.btn-checkout:hover { background: rgba(255, 255, 255, .2); }

/* ====== Tables ====== */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table th, .table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.table th {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  background: var(--bg-soft);
}
.table tbody tr:hover { background: var(--bg-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.mono { font-family: var(--font-mono); }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge-muted { background: var(--bg-soft); color: var(--ink-2); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ====== Calendar ====== */
.calendar {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.calendar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.calendar-title { font-size: 18px; font-weight: 600; text-transform: capitalize; }
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  color: var(--ink-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 0;
}
.cal-cell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  background: #fff;
  position: relative;
  cursor: pointer;
  transition: all .15s ease;
  min-height: 80px;
  aspect-ratio: auto;
}
.cal-cell:hover { border-color: var(--accent); transform: translateY(-1px); }
.cal-cell.is-other { opacity: .35; cursor: default; }
.cal-cell.is-today { background: var(--accent-soft); border-color: var(--accent); }
.cal-cell.is-selected { box-shadow: 0 0 0 2px var(--accent); }
.cal-day { font-size: 14px; font-weight: 600; }
.cal-pills { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.cal-pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-pill.morning { background: #ea580c; }
.cal-pill.afternoon { background: #1e40af; }
.cal-pill.night { background: #4c1d95; }

/* ====== Checklist ====== */
.checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: all .15s ease;
}
.check-item:hover { border-color: var(--line-2); }
.check-item.is-done {
  background: var(--ok-soft);
  border-color: #86efac;
}
.check-item.is-done .check-title { text-decoration: line-through; opacity: .6; }
.check-box {
  width: 22px; height: 22px;
  border: 2px solid var(--line-2);
  border-radius: 6px;
  display: grid; place-items: center;
  background: #fff;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all .15s ease;
}
.check-item.is-done .check-box {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.check-box svg { width: 14px; height: 14px; }
.check-content { flex: 1; }
.check-title { font-weight: 500; font-size: 14px; }
.check-desc { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.check-meta { font-size: 11px; color: var(--ink-3); margin-top: 6px; font-family: var(--font-mono); }

/* ====== Toast ====== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .25s ease;
  max-width: 360px;
}
.toast.success { background: var(--ok); }
.toast.error { background: var(--danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ====== Modal ====== */
.modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 15, 10, .55);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--bg-card);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-body { padding: 20px; overflow-y: auto; }

/* ====== Tabs ====== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.tab {
  background: transparent;
  border: none;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s ease;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* ====== Empty state ====== */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-3);
}
.empty-icon { font-size: 36px; margin-bottom: 8px; opacity: .4; }

/* ====== Misc ====== */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: #fff;
}
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.spacer { flex: 1; }

/* ====== Weekly Grid (Admin Schedule) ====== */
.wg-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg-card); }
.wg-header { display: flex; border-bottom: 2px solid var(--line); background: var(--bg-soft); position: sticky; top: 0; z-index: 5; }
.wg-axis-head { width: 52px; flex-shrink: 0; border-right: 1px solid var(--line); }
.wg-day-head { flex: 1; text-align: center; padding: 10px 4px; font-size: 13px; font-weight: 600; border-left: 1px solid var(--line); }
.wg-day-head.is-today { background: var(--accent-soft); color: var(--accent-ink); }
.wg-day-date { font-size: 11px; font-weight: 400; color: var(--ink-3); margin-top: 1px; }
.wg-scroll { overflow-y: auto; max-height: 62vh; }
.wg-body { display: flex; }
.wg-axis { width: 52px; flex-shrink: 0; position: relative; border-right: 1px solid var(--line); }
.wg-time-label { position: absolute; right: 6px; font-size: 10px; color: var(--ink-3); white-space: nowrap; transform: translateY(-50%); }
.wg-cols { display: flex; flex: 1; }
.wg-day-col { flex: 1; position: relative; border-left: 1px solid var(--line); min-width: 0; }
.wg-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); opacity: .5; pointer-events: none; }
.wg-line-half { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); opacity: .35; pointer-events: none; }
.wg-block {
  position: absolute;
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 11px;
  overflow: hidden;
  border-left: 3px solid transparent;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, z-index 0s;
  cursor: default;
  z-index: 1;
}
.wg-block:hover { box-shadow: var(--shadow); z-index: 10; }
.wg-block.morning { background: #fff3ed; border-left-color: #ea580c; color: #7c2d12; }
.wg-block.afternoon { background: #eff6ff; border-left-color: #1e40af; color: #1e3a8a; }
.wg-block.night { background: #f5f3ff; border-left-color: #4c1d95; color: #3b0764; }
.wg-block.wg-cancelled { opacity: .55; }
.wg-block-label { position: absolute; z-index: 10; font-size: 11px; cursor: pointer; }
.wg-block-label.morning { color: #7c2d12; }
.wg-block-label.afternoon { color: #1e3a8a; }
.wg-block-label.night { color: #3b0764; }
.wg-block-label.wg-cancelled { opacity: .55; }
.wg-block-name { font-weight: 600; white-space: nowrap; line-height: 1.3; }
.wg-block-shift { font-size: 10px; opacity: .75; white-space: nowrap; margin-top: 1px; }
.wg-approve-btn { margin-top: 4px; font-size: 10px; padding: 2px 6px; line-height: 1.4; }
/* freetime row */
.wg-freetime-row { display: flex; border-bottom: 1px solid var(--line); background: var(--bg-soft); min-height: 36px; }
.wg-freetime-label { width: 52px; flex-shrink: 0; font-size: 10px; color: var(--ink-3); padding: 4px 6px; display: flex; align-items: center; justify-content: flex-end; border-right: 1px solid var(--line); }
.wg-freetime-cell { flex: 1; border-left: 1px solid var(--line); padding: 4px 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 36px; }
.wg-ft-pill { background: var(--bg-card); border: 1px solid var(--line-2); border-radius: 4px; padding: 2px 6px; font-size: 11px; display: flex; align-items: center; gap: 4px; white-space: nowrap; }

/* Responsive */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { flex: 1 1 30%; }
  .topbar, .content { padding-left: 18px; padding-right: 18px; }
  .checkin-hero { grid-template-columns: 1fr; padding: 22px; }
  .hero-time { font-size: 40px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
