:root {
  --bg: #efe8dc;
  --ink: #1b1916;
  --muted: #5d574e;
  --paper: #fffdf8;
  --line: #d8cfc0;
  --brand: #0f4c3a;
  --brand-2: #1b7f4e;
  --red: #b42318;
  --amber: #b54708;
  --blue: #175cd3;
  --gray: #667085;
  --dark: #3f1d1d;
  --green-bg: #d1fadf;
  --red-bg: #fee4e2;
  --amber-bg: #fef0c7;
  --blue-bg: #d1e9ff;
  --gray-bg: #f2f4f7;
  --dark-bg: #d0b4b4;
  --xxx: #08663a;
  --xx: #175cd3;
  --x: #2e90fa;
  --o: #b54708;
  --oo: #912018;
  --block: #4a1c1c;
  --shadow: 0 10px 30px rgba(40, 28, 10, 0.08);
  font-family: "Segoe UI", "IBM Plex Sans", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body.locked { overflow: hidden; }
body.locked .app { display: none; }
body:not(.locked) .gate { display: none !important; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #14352c;
}
.gate-card {
  width: min(420px, 100%);
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate-card .brand { color: var(--ink); }
.gate-card .brand p { color: var(--muted); }
.gate-card h2 { margin: 8px 0 0; }
.gate-card .lang-switch { margin: 0; }
.gate-card .lang-btn { background: #efe8dc; color: #14352c; border-color: var(--line); }
.gate-card .lang-btn.active { background: #f0c14b; border-color: #f0c14b; }
.gate-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
.gate-card input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
.gate-error { margin: 0; color: var(--red); font-size: 0.85rem; }
.gate-error[hidden] { display: none !important; }
.rail .btn#btn-logout { width: 100%; background: transparent; color: #f4efe6; border-color: #2a564a; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
}

.rail {
  background: #14352c;
  color: #f4efe6;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 1.05rem; }
.brand p { margin: 2px 0 0; color: #c9d9d2; font-size: 0.78rem; }
.lang-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: -6px;
}
.lang-btn {
  border: 1px solid #2a564a;
  background: #1a4439;
  color: #c9d9d2;
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.lang-btn.active {
  background: #f0c14b;
  color: #14352c;
  border-color: #f0c14b;
}
.mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: #f0c14b; color: #14352c;
  display: grid; place-items: center; font-weight: 800;
}

.rail-section h2 {
  margin: 0 0 6px;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c9d9d2;
}
.hint { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.rail .hint { color: #b7c8c1; }

.list-stack { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  width: 100%;
  text-align: left;
  border: 1px solid #2a564a;
  background: #1a4439;
  color: #f4efe6;
  border-radius: 10px;
  padding: 10px 12px;
}
.list-item small { display: block; color: #b7c8c1; margin-top: 3px; }
.list-item.active { background: #f4efe6; color: #14352c; border-color: #f4efe6; }
.list-item.active small { color: #5d574e; }
.badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f0c14b;
  color: #14352c;
  margin-left: 6px;
  font-weight: 700;
}

.main { padding: 22px 26px 40px; min-width: 0; }
.main-bar { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; }
.title-block h2 { margin: 0; font-size: 1.6rem; }
.kicker { margin: 0; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; color: var(--muted); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--ink);
}
.btn.primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0 10px;
  padding: 0;
  list-style: none;
}
.step {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
}
.step .n {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: #14352c;
  color: #f4efe6;
  font-size: 0.75rem;
  font-weight: 800;
  margin-right: 6px;
}
.step strong { display: inline; }
.step small { display: block; color: var(--muted); margin-top: 4px; font-size: 0.75rem; }
.step.active { outline: 2px solid var(--brand); background: #e8f6ee; }
.step.done { border-color: #abefc6; }
.callout {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #14352c;
  color: #f4efe6;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.callout p { margin: 0; }
.callout .btn.primary { background: #f0c14b; color: #14352c; border-color: #f0c14b; }
.empty-run {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 22px 18px;
  background: #fcfaf5;
  margin-bottom: 14px;
}
.empty-run h3 { margin: 0 0 8px; }
.source-pick { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 10px 0; }
.source-pick .radio { display: block; margin: 6px 0; }
@media (max-width: 980px) {
  .steps { grid-template-columns: 1fr 1fr; }
}

.tabs { display: flex; gap: 6px; margin: 18px 0 14px; }
.tab, .seg {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 14px;
}
.tab.active, .seg.active { background: var(--ink); color: white; border-color: var(--ink); }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel.hidden, .hidden { display: none !important; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 12px; }
.panel-head h3 { margin: 0 0 4px; }

.search { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--muted); }
.search input, .search select, dialog input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  min-width: 220px;
}
.search.grow { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--gray-bg);
}
.chip.t-xxx, .cell.t-xxx, .tone-green { background: var(--green-bg); color: var(--xxx); border-color: #abefc6; }
.chip.t-xx, .chip.t-x, .cell.t-xx, .cell.t-x, .tone-blue { background: var(--blue-bg); color: var(--blue); border-color: #b2ddff; }
.chip.t-o, .cell.t-o, .tone-amber { background: var(--amber-bg); color: var(--amber); border-color: #fedf89; }
.chip.t-oo, .cell.t-oo, .tone-red { background: var(--red-bg); color: var(--red); border-color: #fecdca; }
.chip.t-block, .cell.t-block, .tone-dark { background: var(--dark-bg); color: var(--dark); }
.tone-gray { background: var(--gray-bg); color: var(--gray); }

.scroll-x { overflow: auto; max-height: calc(100vh - 280px); border: 1px solid var(--line); border-radius: 12px; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 0.72rem; min-width: max-content; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); border-right: 1px solid #eee6d8; padding: 0; }
table.grid th { position: sticky; top: 0; background: #f7f1e6; z-index: 2; font-weight: 600; }
table.grid th.name, table.grid td.name {
  position: sticky; left: 0; z-index: 3; background: #f7f1e6; min-width: 140px; padding: 6px 8px; text-align: left;
}
table.grid td.name { background: white; z-index: 1; }
table.grid thead .day { text-align: center; padding: 6px 4px 0; }
table.grid thead .shifts { text-align: center; color: var(--muted); font-size: 0.62rem; padding-bottom: 4px; }
.cell {
  width: 28px; height: 26px; display: grid; place-items: center;
  border: 0; background: transparent; padding: 0; font-size: 0.62rem; font-weight: 700;
}
.cell.editable:hover { outline: 2px solid var(--brand); outline-offset: -2px; }
.cell.assigned { box-shadow: inset 0 0 0 2px #111; }

.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.stat {
  background: #f7f1e6;
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 110px;
}
.stat b { display: block; font-size: 1.15rem; }
.stat span { color: var(--muted); font-size: 0.75rem; }

.segmented { display: flex; gap: 4px; background: #f3eee4; padding: 3px; border-radius: 999px; }

.schedule-wrap { max-height: 420px; margin-bottom: 16px; }
table.schedule { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.schedule th, table.schedule td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: center;
}
table.schedule th { background: #14352c; color: #f4efe6; position: sticky; top: 0; z-index: 1; }
table.schedule td.meta { text-align: left; font-weight: 600; background: #fcfaf5; }
table.schedule td.name-cell { font-weight: 700; }

.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.day-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: white;
  text-align: left;
}
.day-card h4 { margin: 0 0 6px; font-size: 0.82rem; }
.day-card .slot {
  display: flex; justify-content: space-between; gap: 6px;
  font-size: 0.72rem; padding: 3px 5px; border-radius: 6px; margin-bottom: 3px;
}
.day-card.active { outline: 2px solid var(--brand); }

.detail-card, .constraint-card, .assign-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fcfaf5;
}
.detail-card h3, .constraint-card h3, .assign-card h3 { margin: 0 0 8px; font-size: 1rem; }
.slot-row { display: grid; grid-template-columns: 40px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.reason { color: var(--muted); font-size: 0.8rem; margin: 2px 0 0; }

.person-toolbar { margin-bottom: 12px; }
.person-layout { display: grid; grid-template-columns: 280px 1fr; gap: 12px; }
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .person-layout { grid-template-columns: 1fr; }
}

.mini-month { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.mini-day {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  font-size: 0.68rem;
  min-height: 52px;
}
.mini-day strong { display: block; }
.constraint-card ul { margin: 6px 0 0; padding-left: 18px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  width: min(460px, 92vw);
  background: var(--paper);
}
dialog::backdrop { background: rgba(20, 16, 10, 0.35); }
dialog h3 { margin: 0 0 8px; }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 0 0; margin: 0; }
.token-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.token-picker button { min-width: 64px; }

#toast {
  position: fixed; bottom: 18px; right: 18px;
  background: #14352c; color: white; padding: 10px 14px;
  border-radius: 10px; z-index: 20;
}
#toast[hidden] { display: none !important; }
#busy {
  position: fixed; inset: 0; background: rgba(20,16,10,0.45);
  place-items: center; color: white; z-index: 30;
  pointer-events: all;
}
#busy[hidden] {
  display: none !important;
  pointer-events: none;
}
#busy:not([hidden]) {
  display: grid;
}
.spinner {
  width: 36px; height: 36px; border: 3px solid #fff4; border-top-color: white;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty { color: var(--muted); padding: 16px; }
