:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e7ef;
  --text: #16202e;
  --text-dim: #64748b;
  --accent: #3257d8;
  --accent-soft: #e8edfd;
  --planned: #3257d8;
  --confirmed: #0f9d76;
  --completed: #94a3b8;
  --danger: #c8372d;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --surface: #161b24;
    --surface-2: #1b212c;
    --border: #2a323f;
    --text: #e6eaf2;
    --text-dim: #93a1b5;
    --accent: #7d9bff;
    --accent-soft: #1e2942;
    --planned: #7d9bff;
    --confirmed: #37c79c;
    --completed: #6b7787;
    --danger: #f08a80;
    --warn: #e0b055;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -0.01em; }
h1 { font-size: 16px; }
h2 { font-size: 15px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 22px; }
.brand-sub { margin: 0; font-size: 11.5px; color: var(--text-dim); }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.is-live { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 550; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 16px;
  align-items: start;
  height: calc(100vh - 59px);
}
.layout.chat-hidden { grid-template-columns: minmax(0, 1fr); }
.layout.chat-hidden .chat { display: none; }
.workspace { min-width: 0; height: 100%; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel.is-hidden { display: none; }
.panel-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.panel-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.weeknav { display: flex; align-items: center; gap: 6px; }
.weeknav h2 { margin-left: 6px; white-space: nowrap; }
.legend { display: flex; gap: 10px; font-size: 11.5px; color: var(--text-dim); }
.legend span { display: flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }
.dot-planned { background: var(--planned); }
.dot-confirmed { background: var(--confirmed); }
.dot-completed { background: var(--completed); }

/* ---------- stats strip ---------- */
.stats {
  display: flex; gap: 10px; padding: 12px 14px; overflow-x: auto;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.stat { min-width: 128px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 18px; font-weight: 650; margin-top: 2px; }
.stat-note { font-size: 11.5px; color: var(--text-dim); }
.stat-note.is-warn { color: var(--warn); }

/* ---------- schedule grid ---------- */
.grid-scroll { overflow: auto; flex: 1; }
.grid {
  display: grid;
  grid-template-columns: 190px repeat(7, minmax(126px, 1fr)) 104px;
  min-width: 980px;
}
.gcell { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 6px; min-height: 58px; }
.gcell.head {
  position: sticky; top: 0; z-index: 3; background: var(--surface-2);
  font-size: 11.5px; font-weight: 600; color: var(--text-dim); min-height: 0; padding: 8px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.gcell.head .date { display: block; font-size: 13px; font-weight: 650; color: var(--text); letter-spacing: 0; text-transform: none; }
.gcell.head.is-today { background: var(--accent-soft); }
.gcell.head.is-today .date { color: var(--accent); }
.gcell.dept {
  grid-column: 1 / -1; background: var(--surface-2); font-size: 11px; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 5px 10px; min-height: 0; position: sticky; left: 0;
}
.gcell.name { position: sticky; left: 0; background: var(--surface); z-index: 2; }
.gcell.total { background: var(--surface-2); text-align: right; }
.emp-name { font-weight: 600; }
.emp-meta { font-size: 11.5px; color: var(--text-dim); }
.gcell.day { cursor: pointer; position: relative; }
.gcell.day:hover { background: var(--surface-2); }
.gcell.day.is-weekend { background: color-mix(in srgb, var(--bg) 60%, var(--surface)); }
.gcell.day.is-weekend:hover { background: var(--surface-2); }
.gcell.day .add-hint {
  position: absolute; inset: 6px; border: 1px dashed var(--border); border-radius: 7px;
  display: none; align-items: center; justify-content: center; color: var(--text-dim); font-size: 16px;
}
.gcell.day:hover .add-hint { display: flex; }

.chip {
  position: relative; z-index: 1;
  display: block; width: 100%; text-align: left; margin-bottom: 4px;
  border: 1px solid transparent; border-left: 3px solid var(--planned);
  background: var(--accent-soft); color: var(--text);
  border-radius: 7px; padding: 5px 7px; font: inherit; cursor: pointer;
}
.chip:last-child { margin-bottom: 0; }
.chip:hover { border-color: var(--accent); }
.chip-time { font-weight: 620; font-size: 12.5px; }
.chip-meta { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.status-confirmed { border-left-color: var(--confirmed); }
.chip.status-completed { border-left-color: var(--completed); opacity: 0.75; }
.chip.is-absent-day { opacity: 0.55; }

.absence-tag {
  display: block; border-radius: 7px; padding: 4px 7px; font-size: 11.5px;
  background: repeating-linear-gradient(45deg, transparent, transparent 5px, var(--border) 5px, var(--border) 6px);
  border: 1px dashed var(--border); color: var(--text-dim); margin-bottom: 4px;
}
.total-hours { font-weight: 650; }
.total-diff { font-size: 11.5px; color: var(--text-dim); }
.total-diff.is-over { color: var(--warn); font-weight: 600; }
.total-diff.is-under { color: var(--accent); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); z-index: 1; }
tbody tr:hover { background: var(--surface-2); }
td.actions { text-align: right; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); }

/* ---------- chat ---------- */
.chat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); height: 100%; display: flex; flex-direction: column; overflow: hidden;
}
.chat-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-sub { margin: 2px 0 0; font-size: 11.5px; color: var(--text-dim); }
.chat-head .btn { margin-left: auto; }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 100%; }
.msg-role { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin-bottom: 4px; }
.msg-body { border-radius: 10px; padding: 9px 11px; border: 1px solid var(--border); background: var(--surface-2); overflow-x: auto; }
.msg.user .msg-body { background: var(--accent-soft); border-color: transparent; }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p { margin: 6px 0; }
.msg-body ul { margin: 6px 0; padding-left: 18px; }
.msg-body table { font-size: 12.5px; margin: 8px 0; width: auto; }
.msg-body th, .msg-body td { padding: 4px 8px; }
.msg-body code { font-family: var(--mono); font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.msg-error .msg-body { border-color: var(--danger); color: var(--danger); }
.queries { margin-top: 8px; font-size: 12px; }
.queries summary { cursor: pointer; color: var(--text-dim); }
.queries pre {
  font-family: var(--mono); font-size: 11.5px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px; overflow-x: auto; margin: 6px 0 0; white-space: pre-wrap;
}
.query-purpose { color: var(--text-dim); margin-top: 6px; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
.suggestion {
  font: inherit; font-size: 12px; cursor: pointer; padding: 5px 9px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }
.chat-input { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: none; font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.chat-input textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.typing span { animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop.is-hidden, .is-hidden { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); width: min(520px, 100%); max-height: 90vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.modal-head .btn { margin-left: auto; }
.modal-body { padding: 14px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field select, .field textarea {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field .hint { font-size: 11.5px; color: var(--text-dim); }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); }
.modal-foot-buttons { margin-left: auto; display: flex; gap: 8px; }
.modal-error { color: var(--danger); font-size: 12.5px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 999px;
  font-size: 13px; z-index: 60; box-shadow: var(--shadow);
}
.toast.is-error { background: var(--danger); color: #fff; }

.empty { padding: 26px; text-align: center; color: var(--text-dim); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .chat { height: 70vh; }
  .panel { height: auto; }
  .grid-scroll { max-height: 70vh; }
}
