:root {
  --bg: #0f172a;
  --surface: #111827;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --accent: #22d3ee;
  --border: #1f2937;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #34d399;
  --info: #60a5fa;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  --table-surface: #0b1224;
  --table-cell: rgba(255, 255, 255, 0.03);
  --table-hover: rgba(255, 255, 255, 0.04);
}

body[data-theme="light"] {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --muted: #475569;
  --text: #0f172a;
  --accent: #0ea5e9;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warning: #eab308;
  --success: #059669;
  --info: #2563eb;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.14);
  --table-surface: #f8fafc;
  --table-cell: rgba(15, 23, 42, 0.02);
  --table-hover: rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(120% 120% at 10% 10%, rgba(34, 211, 238, 0.08), transparent 40%),
              radial-gradient(100% 100% at 90% 20%, rgba(96, 165, 250, 0.07), transparent 35%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px;
  line-height: 1.4;
}
body[data-theme="light"] {
  background: radial-gradient(120% 120% at 10% 10%, rgba(14, 165, 233, 0.14), transparent 40%),
              radial-gradient(100% 100% at 90% 20%, rgba(37, 99, 235, 0.12), transparent 35%),
              var(--bg);
}
.title-row { display: flex; align-items: center; gap: 6px; }
.title-row--with-legend { justify-content: space-between; flex-wrap: wrap; row-gap: 4px; }
.title-row h2 { margin: 0; font-size: 28px; letter-spacing: -0.01em; line-height: 1.05; }
.title-group h1 { margin: 4px 0; font-size: 26px; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); margin: 6px 0 0; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 11px; color: var(--muted); }
.badge {
  background: rgba(34, 211, 238, 0.16);
  color: var(--accent);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.status-group { display: grid; gap: 10px; align-content: start; }
.status-line { display: flex; align-items: center; gap: 8px; }
.status-line--double {
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.label { color: var(--muted); font-size: 13px; }
.value { font-weight: 600; }
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.12);
}
.chip.warn { color: var(--warning); border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.1); }
.chip.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); background: rgba(248, 113, 113, 0.08); }
.chip.ok { color: var(--success); border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.1); }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-weight: 600;
}
.button {
  cursor: pointer;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}
.button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
  border-color: rgba(96, 165, 250, 0.5);
}
.button:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; transform: none; }
.button--primary {
  background: linear-gradient(120deg, #22d3ee, #38bdf8 45%, #60a5fa);
  color: #0b1224;
  border-color: rgba(96, 165, 250, 0.5);
  box-shadow: 0 14px 32px rgba(96, 165, 250, 0.35);
}
body[data-theme="light"] .button--primary {
  background: linear-gradient(120deg, #0ea5e9, #38bdf8 45%, #3b82f6);
  color: #0f172a;
}
.button--ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(148, 163, 184, 0.4);
  color: var(--text);
  box-shadow: none;
}
body[data-theme="light"] .button--ghost {
  background: rgba(15, 23, 42, 0.04);
  border-color: rgba(148, 163, 184, 0.5);
}

.notice {
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(96, 165, 250, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--info);
  font-weight: 600;
}

main { margin-top: 0; }
.card {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 14px 10px;
  box-shadow: var(--shadow);
}
body[data-theme="light"] .card {
  background: rgba(255, 255, 255, 0.96);
}
.card-header { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: flex-start; }
.title-block { display: flex; flex-direction: column; gap: 6px; }
.status-panel {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 8px;
  display: grid;
  gap: 6px;
  align-items: start;
}
.status-panel__toggle { justify-self: start; }
.status-panel[data-collapsed="true"] .status-panel__toggle { width: auto; }
.status-panel__content { display: grid; gap: 8px; }

.status-panel[data-collapsed="true"] .status-panel__content { display: none; }
.status-panel[data-collapsed="false"] .status-panel__content { display: grid; }
.muted { color: var(--muted); margin: 6px 0 0; }
.legend { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: flex-start; }
.legend small { color: var(--muted); }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; margin-right: 4px; border: 1px solid var(--border); }
.swatch.low { background: rgba(248, 113, 113, 0.6); }
.swatch.medium { background: rgba(251, 191, 36, 0.7); }
.swatch.good { background: rgba(52, 211, 153, 0.7); }
.swatch.great { background: rgba(34, 211, 238, 0.7); }
.swatch.zero { background: rgba(148, 163, 184, 0.5); }

.grid-container {
  margin-top: 12px;
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  background: var(--table-surface);
}

.gridjs-container {
  border-radius: 12px;
  background: var(--table-surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
body[data-theme="light"] .gridjs-container {
  background: rgba(15, 23, 42, 0.02);
}
.gridjs-container .gridjs-table,
.gridjs-container .gridjs-thead,
.gridjs-container .gridjs-tbody {
  border-spacing: 0;
  border-collapse: separate;
  width: 100%;
  background: var(--table-surface) !important;
}
.gridjs-th, .gridjs-td {
  background: var(--table-cell) !important;
  color: var(--text) !important;
  padding: 0 !important;
  border: 1px solid var(--border) !important;
  font-size: 13px !important;
}
.gridjs-th:first-child { padding: 10px !important; }
.gridjs-td:first-child { padding: 2px 10px !important; }
.gridjs-tr .gridjs-td,
.gridjs-tr .gridjs-th {
  padding-top: 2px !important;
  padding-bottom: 2px !important;
}
.gridjs-tr:hover .gridjs-td { background: var(--table-hover) !important; }
.gridjs-table td:first-child,
.gridjs-table th:first-child {
  text-align: left !important;
}
.gridjs-table td:not(:first-child),
.gridjs-table th:not(:first-child) {
  text-align: center;
}
.gridjs-footer {
  background: var(--table-surface);
  border-top: 1px solid var(--border);
}
.gridjs-pagination {
  padding: 10px 12px;
}
.gridjs-pagination .gridjs-pages button {
  color: var(--text);
  border-color: var(--border);
  background: var(--table-cell);
}
.mobile-day-controls {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.mobile-day-controls__label {
  display: grid;
  gap: 2px;
}

.mobile-day-controls__value {
  font-weight: 700;
  font-size: 15px;
}
.gridjs-th .gridjs-sort {
  width: 22px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  position: relative;
}
.gridjs-th .gridjs-sort span {
  display: none;
}
.gridjs-th .gridjs-sort::before,
.gridjs-th .gridjs-sort::after {
  content: '';
  border: 5px solid transparent;
  display: block;
  width: 0;
  height: 0;
}
.gridjs-th .gridjs-sort::before { border-bottom-color: var(--text); margin-bottom: -2px; }
.gridjs-th .gridjs-sort::after { border-top-color: var(--text); margin-top: -2px; }
.gridjs-th .gridjs-sort.gridjs-sort-asc::after { opacity: 0.35; }
.gridjs-th .gridjs-sort.gridjs-sort-desc::before { opacity: 0.35; }

.grid-summary {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 10px;
  justify-items: stretch;
  --day-count: 7;
  grid-template-columns: minmax(180px, 1.4fr) repeat(var(--day-count), minmax(120px, 1fr));
  align-items: stretch;
}
body[data-theme="light"] .grid-summary {
  background: rgba(15, 23, 42, 0.02);
}
.grid-summary__item {
  display: grid;
  gap: 4px;
  text-align: center;
  min-width: 120px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.grid-summary__label { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.grid-summary__value { font-weight: 700; font-variant-numeric: tabular-nums; }

.grid-summary__label-cell {
  align-items: center;
  justify-items: start;
  text-align: left;
}
.grid-summary__label-title {
  color: var(--text);
  font-weight: 700;
}

.cell-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  width: 100%;
  height: 100%;
  padding: 5px 8px;
  border-radius: 0;
  font-weight: 700;
  color: #0b1224;
  transition: transform 120ms ease, box-shadow 120ms ease;
  cursor: default;
  line-height: 1.15;
  position: relative;
  z-index: 1;
}
.cell-chip.cell-tech {
  justify-content: flex-start;
  text-align: left;
}
.cell-chip:hover { transform: none; box-shadow: none; }
.cell-low { background: rgba(248, 113, 113, 0.85); }
.cell-medium { background: rgba(251, 191, 36, 0.9); }
.cell-good { background: rgba(52, 211, 153, 0.9); }
.cell-great { background: rgba(52, 211, 153, 0.9); }
.cell-zero { background: rgba(148, 163, 184, 0.8); color: #0b1224; }
.cell-tech {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.35), rgba(34, 211, 238, 0.25));
  border: 1px solid rgba(96, 165, 250, 0.65);
  color: #fff;
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.25);
  justify-content: flex-start;
  text-align: left;
}
.cell-tech__name { color: #fff; font-weight: 700; letter-spacing: 0.01em; font-size: 0.95rem; }
.cell-hours__value {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.column-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 12px;
}
.column-day__weekday {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #a5b4fc;
}
.column-day__date {
  font-size: 13px;
  font-weight: 600;
}

.column-day.current-day-header {
  background: rgba(250, 204, 21, 0.16);
  box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.45);
}
.column-day.current-day-header .column-day__weekday,
.column-day.current-day-header .column-day__date {
  color: #facc15;
}
.cell-chip.current-day { box-shadow: inset 0 0 0 2px rgba(250, 204, 21, 0.45); }

.summary-today { border-color: rgba(250, 204, 21, 0.45); box-shadow: 0 10px 20px rgba(250, 204, 21, 0.2); }

.modal { position: fixed; inset: 0; display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 10; }
.modal.open { display: flex; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.modal__content {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  width: min(1100px, 100%);
  max-height: calc(100vh - 80px);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal__body { padding: 12px 18px 18px; overflow: auto; max-height: calc(100vh - 150px); }
.detail-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 10px; }
.icon-button { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border); color: var(--text); border-radius: 10px; width: 36px; height: 36px; cursor: pointer; font-size: 16px; }

.footer { margin-top: 30px; color: var(--muted); text-align: center; font-size: 13px; }
.empty-state { text-align: center; color: var(--muted); padding: 16px; }

/* Access gate */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 999;
}

.auth-overlay[hidden] { display: none; }

.auth-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
}

.auth-overlay__content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 20px;
  width: min(420px, calc(100% - 32px));
  box-shadow: var(--shadow);
  z-index: 1;
}

.auth-overlay h2 {
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.auth-overlay p { margin: 0 0 12px; color: var(--muted); }

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form label {
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  padding: 12px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-weight: 600;
}

.auth-actions { display: flex; justify-content: flex-end; }

.auth-locked main,
.auth-locked footer,
.auth-locked .card,
.auth-locked .status-panel,
.auth-locked .grid-container,
.auth-locked .gridjs-container,
.auth-locked .gridjs-table,
.auth-locked .modal,
.auth-locked .title-block,
.auth-locked .legend {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

@media (max-width: 960px) {
  body { padding: 16px; }
  .card-header { grid-template-columns: 1fr; }
  .controls { width: 100%; }
  .status-panel { width: 100%; }
  .mobile-day-controls { display: flex; width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .mobile-day-controls .button { flex: 0 0 auto; }
}
