:root {
  --ink: #1c1915;
  --muted: #6f675c;
  --paper: #f3efe6;
  --card: #fffdf8;
  --line: #e3d9cb;
  --side: #17211e;
  --side-2: #24312c;
  --accent: #0f6e6b;
  --accent-2: #dff4ea;
  --danger: #9f1239;
  --warn: #9a3412;
  --ok: #166534;
  --shadow: 0 16px 40px rgba(40, 28, 12, 0.08);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: Manrope, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
aside {
  background: var(--side);
  color: #f4efe4;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px; }
.mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: #d6f26a; color: #17211e;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 600; font-size: 13px;
}
.brand b { display: block; font-size: 16px; letter-spacing: -0.03em; }
.brand small { color: #b7c4bc; font-size: 12px; }
.mine-pick { max-width: 520px; }
.shift-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 24px; }
.shift-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: white;
  border-radius: 12px;
}
.shift-row.today { outline: 2px solid #0f6e6b; }

aside nav { display: flex; flex-direction: column; gap: 4px; }
aside nav button {
  text-align: left; background: transparent; border: 0; color: #d9e3dc;
  border-radius: 10px; padding: 10px 12px; font-weight: 600;
}
aside nav button[aria-current="page"] { background: var(--side-2); color: white; }
aside nav button:hover { background: rgba(255,255,255,0.06); }
.aside-foot { margin-top: auto; color: #9aada4; font-size: 12px; line-height: 1.45; padding: 0 6px; }
.aside-foot strong { color: #d6f26a; font-weight: 700; }

.main { min-width: 0; display: flex; flex-direction: column; }
header.top {
  display: flex; gap: 16px; align-items: flex-end; justify-content: space-between;
  padding: 20px 24px 12px; position: sticky; top: 0; z-index: 5;
  background: rgba(243, 239, 230, 0.92); backdrop-filter: blur(10px);
}
.top h1 { margin: 0; font-size: 28px; letter-spacing: -0.04em; line-height: 1.1; }
.top .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.search {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; min-width: 220px;
}
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-weight: 700;
}
.btn:hover { border-color: #c9bba6; }
.btn.primary { background: var(--ink); color: #f6f1e7; border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.warn { background: #fff7ed; border-color: #fdba74; color: var(--warn); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.lock {
  font-size: 12px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  border-radius: 999px; padding: 6px 10px; border: 1px solid var(--line); background: white;
}
.lock.on { background: #d6f26a; border-color: #d6f26a; }

#content { padding: 0 24px 40px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 8px; margin: 4px 0 14px; }
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 10px; white-space: nowrap; font-weight: 650; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--ink); color: white; border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
}
.stat b { display: block; font-family: var(--mono); font-size: 26px; letter-spacing: -0.04em; }
.stat span { color: var(--muted); font-size: 12px; font-weight: 650; }
.stat.bad b { color: var(--danger); }
.stat.ok b { color: var(--ok); }

.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; margin: 8px 0 16px; }
.hour {
  border: 0; background: transparent; padding: 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.hour i {
  display: block; width: 100%; height: 72px; background: #e7e0d4; border-radius: 7px 7px 3px 3px;
  position: relative; overflow: hidden;
}
.hour i span {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent);
}
.hour.low i span { background: var(--danger); }
.hour.edge i span { background: var(--warn); }
.hour em { font-style: normal; font-family: var(--mono); font-size: 11px; }
.hour small { color: var(--muted); font-size: 10px; font-family: var(--mono); }
.hour.on i { box-shadow: inset 0 0 0 2px var(--ink); }
.hour.now small { color: var(--danger); font-weight: 700; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); overflow: hidden;
}
.panel-h {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-h h2 { margin: 0; font-size: 16px; letter-spacing: -0.03em; }
.panel-h p { margin: 0; color: var(--muted); font-size: 13px; }

.gantt { overflow: auto; max-height: calc(100vh - 280px); }
.gantt-scale, .grow {
  display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 10px; align-items: center;
  padding: 0 12px;
}
.gantt-scale {
  position: sticky; top: 0; background: #fffdf8; z-index: 2;
  border-bottom: 1px solid var(--line); padding-top: 8px; padding-bottom: 6px;
  color: var(--muted); font-family: var(--mono); font-size: 10px;
}
.ticks { display: grid; grid-template-columns: repeat(24, 1fr); position: relative; }
.grow { min-height: 46px; border-bottom: 1px solid #f0e9de; }
.grow.dim { opacity: 0.28; }
.who { display: flex; gap: 10px; align-items: center; min-width: 0; }
.who .t {
  font-family: var(--mono); font-weight: 600; font-size: 18px; letter-spacing: -0.04em;
  width: 118px; flex: none; line-height: 1.15;
}
.who .t small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.who b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track {
  position: relative; height: 22px; border-radius: 7px; background: #f6f1e8;
  background-image: repeating-linear-gradient(to right, transparent, transparent calc(100% / 24 - 1px), #efe6d8 calc(100% / 24 - 1px), #efe6d8 calc(100% / 24));
}
.bar { position: absolute; top: 3px; bottom: 3px; border-radius: 5px; min-width: 2px; }
.bar.morning { background: #7dd3fc; }
.bar.day { background: #86efac; }
.bar.evening { background: #fdba74; }
.bar.night { background: #a5b4fc; }
.bar.duty15, .bar.duty2 { box-shadow: inset 0 0 0 2px #1c1915; }
.now-line { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--danger); z-index: 2; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin: 8px 0 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

.grid-wrap { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
table.grid { border-collapse: separate; border-spacing: 0; }
.grid th, .grid td { padding: 0; border-right: 1px solid #f0e9de; border-bottom: 1px solid #f0e9de; }
.grid .corner, .grid .name {
  position: sticky; left: 0; z-index: 2; background: #fffdf8; text-align: left; min-width: 252px;
}
.grid .dayhead {
  position: sticky; top: 0; z-index: 3; background: #faf6ef;
  font-weight: 700; font-size: 12px; padding: 6px 0; min-width: 74px;
}
.grid .corner { z-index: 5; top: 0; }
.grid .dayhead button { border: 0; background: transparent; width: 100%; font-weight: 750; }
.grid .dayhead small { display: block; color: var(--muted); font-weight: 650; }
.grid .dayhead.weekend { background: #f3ecdf; }
.grid .dayhead.today { background: #d6f26a; }
.grid .name button {
  border: 0; background: transparent; text-align: left; padding: 6px 10px; width: 252px;
}
.grid .name strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid .name span {
  display: block; color: var(--muted); font-size: 11px; font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dept td { background: #ebe4d6; }
.dept-label {
  display: inline-flex; align-items: center; gap: 8px;
  position: sticky; left: 10px; font-weight: 800; font-size: 12px;
  letter-spacing: 0.04em; text-transform: uppercase; padding: 7px 0;
}
.cell {
  border: 0; background: transparent; width: 74px; height: 48px; display: block;
  padding: 4px 2px;
}
.cell b, .cell small { display: block; font-family: var(--mono); font-size: 11px; line-height: 1.25; }
.cell.morning { background: #e0f2fe; }
.cell.day { background: #dcfce7; }
.cell.evening { background: #ffedd5; }
.cell.night { background: #e0e7ff; }
.cell.vacation { background: #f1f5f9; color: #64748b; }
.cell.sick { background: #ffe4e6; color: var(--danger); }
.cell.timeoff { background: #fef3c7; color: #92400e; }
.cell.makeup { background: #ccfbf1; color: #115e59; }
.cell.overtime { background: #dbeafe; color: #1e3a8a; }
.cell.off { color: #c4b8a8; }
.cell.duty15 b, .cell.duty2 b { text-decoration: underline; }
.cell.today { box-shadow: inset 0 0 0 2px var(--ink); }
.note {
  background: #fff8e8; border: 1px solid #f0e0b8; color: #6b5424;
  border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.card .when { font-family: var(--mono); font-size: 22px; letter-spacing: -0.04em; font-weight: 600; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .today-line { font-weight: 750; }
.card header { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.card.issue { border-left: 4px solid var(--danger); }
.card.issue.hours { border-left-color: #b45309; }
.card.issue a { color: inherit; font-weight: 750; }
.section-title { margin: 18px 0 8px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.heat button {
  border: 1px solid var(--line); background: white; border-radius: 12px; padding: 8px;
  text-align: left;
}
.heat button.on { box-shadow: inset 0 0 0 2px var(--ink); }
.heat b { display: block; font-size: 13px; }
.heat em { font-style: normal; font-family: var(--mono); font-size: 12px; }
.heat .bad { background: #fff1f2; }
.heat .warn { background: #fff7ed; }
.heat .ok { background: #f0fdf4; }

.hour-people { display: flex; flex-direction: column; }
.hour-people button, .person-line {
  display: grid; grid-template-columns: 92px 1fr auto; gap: 8px; align-items: center;
  padding: 8px 14px; border: 0; border-bottom: 1px solid #f3ecdf; background: transparent; text-align: left; width: 100%;
}
.person-line b, .hour-people b { font-family: var(--mono); }

.settings { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 14px; align-items: start; }
.form { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 16px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; }
label input, label select, .mins input {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff;
  font-weight: 550;
}
.mins { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.mins label { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.help { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.45; font-weight: 500; }

.backdrop {
  position: fixed; inset: 0; background: rgba(28, 25, 21, 0.46);
  display: grid; place-items: center; padding: 20px; z-index: 30;
}
.dialog {
  width: min(520px, 100%); background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); max-height: calc(100vh - 40px); overflow: auto;
}
.dialog h2 { margin: 0; font-size: 20px; letter-spacing: -0.03em; }
.dialog .head { display: flex; justify-content: space-between; gap: 8px; padding: 16px 16px 0; align-items: start; }
.phases { display: flex; gap: 4px; flex-wrap: wrap; }
.phases i {
  font-style: normal; font-family: var(--mono); font-size: 11px;
  padding: 3px 5px; border-radius: 6px; background: #f3ecdf; color: var(--muted);
}
.phases i.on { background: #d6f26a; color: var(--ink); }
#shift-form:not([data-kind="work"]):not([data-kind="duty15"]):not([data-kind="duty2"]) .times,
#employee-form:not([data-pattern="2/2"]) .phase-field { display: none; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: white; padding: 10px 14px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: 0.2s ease; z-index: 40; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { padding: 28px 8px; color: var(--muted); }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  aside { position: sticky; top: 0; height: auto; z-index: 6; flex-direction: row; align-items: center; padding: 10px; gap: 10px; }
  aside nav { flex-direction: row; overflow: auto; min-width: 0; flex: 1; }
  aside nav button { flex: none; white-space: nowrap; }
  .aside-foot, .brand small { display: none; }
  .stats, .settings { grid-template-columns: 1fr 1fr; }
  .gantt-scale, .grow { grid-template-columns: 210px 1fr; }
  .who .t { width: 72px; font-size: 15px; }
  header.top { flex-direction: column; align-items: stretch; }
  .hours { grid-template-columns: repeat(12, 1fr); }
}
@media (max-width: 640px) {
  .stats, .settings { grid-template-columns: 1fr; }
  #content, header.top { padding-left: 12px; padding-right: 12px; }
  .search { min-width: 0; width: 100%; }
}
@media print {
  aside, header.top, .chips, .no-print, #toast, #modal { display: none !important; }
  .shell { display: block; }
  .gantt { max-height: none; }
  body { background: white; }
}
