:root {
  --bg: #eef0e9;
  --paper: #fbfbf7;
  --header-shade: #e3e2d5;
  --line: #b9bcae;
  --line-soft: #d6d8cb;
  --ink: #23261f;
  --ink-muted: #6b6e60;
  --ink-faint: #9a9d8e;
  --accent: #e07f00;
  --accent-ink: #7a4200;
  --accent-soft: #f7e2c2;
  --sidebar-bg: #262e29;
  --sidebar-ink: #cdd2c6;
  --sidebar-ink-dim: #8d9488;
  --st-open: #3f7fd1;
  --st-closed: #3f8a5c;
  --font-ui: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}
:root[data-theme="dark"] {
  --bg: #1b1e1a;
  --paper: #23261f;
  --header-shade: #2c2f26;
  --line: #454a3d;
  --line-soft: #34372c;
  --ink: #e6e7de;
  --ink-muted: #a4a89a;
  --ink-faint: #767a6c;
  --accent: #f0973a;
  --accent-ink: #ffdcab;
  --accent-soft: #4a3315;
  --sidebar-bg: #14170f;
  --sidebar-ink: #d3d6c9;
  --sidebar-ink-dim: #767c6c;
  --st-open: #6ea3e8;
  --st-closed: #66b989;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.55;
}
button, a.btn { font-family: inherit; }

.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 196px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 6px;
}
.brand .mark {
  width: 22px; height: 22px;
  border-radius: 4px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #201200;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.brand .name { font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em; color: #fff; }
.brand .name small { display: block; font-weight: 400; font-size: 10.5px; color: var(--sidebar-ink-dim); }

.nav-group { margin-bottom: 4px; }
.nav-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--sidebar-ink-dim);
  padding: 10px 16px 4px;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 16px 8px 14px;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--sidebar-ink);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.05); }
.nav-item.active {
  background: rgba(224,127,0,0.14);
  border-left-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.nav-item.active svg { opacity: 1; }
.nav-item.disabled { color: var(--sidebar-ink-dim); cursor: default; }
.nav-item.disabled:hover { background: transparent; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  gap: 16px;
}
.crumb { font-size: 11.5px; color: var(--ink-faint); margin-bottom: 2px; }
.page-title { font-size: 16px; font-weight: 700; margin: 0; }
.toolbar { display: flex; gap: 8px; }
.btn {
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}
.btn:hover { background: var(--header-shade); }
.btn.primary { background: var(--accent); border-color: var(--accent-ink); color: #2a1600; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.05); }

.content { padding: 20px 22px 40px; }

.alert-error {
  border: 1px solid var(--st-closed, #bd4a3f);
  background: color-mix(in srgb, #bd4a3f 12%, var(--paper));
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 16px;
  font-size: 12.5px;
}

/* ---------- home layout ---------- */
.home-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.agenda-date { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- stat strip ---------- */
.stat-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); margin-bottom: 18px; max-width: 360px; }
.stat { background: var(--paper); padding: 11px 14px; display: flex; flex-direction: column; gap: 4px; }
.stat .n { font-family: var(--font-mono); font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11px; color: var(--ink-muted); display: flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot.open { background: var(--st-open); }
.dot.closed { background: var(--st-closed); }

/* ---------- ledger table ---------- */
.ledger-wrap { border: 1px solid var(--line); background: var(--paper); overflow-x: auto; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.ledger th {
  background: var(--header-shade);
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
table.ledger td { border: 1px solid var(--line-soft); padding: 7px 10px; vertical-align: middle; }
table.ledger tbody tr:hover { background: var(--accent-soft); }
table.ledger td a { color: inherit; }
.tid { font-family: var(--font-mono); color: var(--ink-faint); font-size: 11.5px; }
.chip { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 3px; white-space: nowrap; border: 1px solid transparent; }
.chip.open { color: var(--st-open); background: color-mix(in srgb, var(--st-open) 14%, transparent); border-color: color-mix(in srgb, var(--st-open) 35%, transparent); }
.chip.closed { color: var(--st-closed); background: color-mix(in srgb, var(--st-closed) 14%, transparent); border-color: color-mix(in srgb, var(--st-closed) 35%, transparent); }

/* ---------- pager ---------- */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px 14px;
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.pager .pager-status {
  font-size: 11.5px; color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.btn.disabled {
  color: var(--ink-faint);
  background: var(--header-shade);
  cursor: default;
  pointer-events: none;
}

/* ---------- panel ---------- */
.panel { border: 1px solid var(--line); background: var(--paper); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; background: var(--header-shade); border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 12.5px; font-weight: 700; }
.panel-head .hint { font-size: 11px; color: var(--ink-faint); }
.panel-body { padding: 16px; }

/* ---------- filter bar ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.filter-bar label {
  font-size: 10.5px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 5px;
}
.filter-bar select, .filter-bar input[type="text"] {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
}
.filter-bar input[type="text"] { width: 150px; }
.filter-bar .spacer { flex: 1; }
.filter-bar .count { font-size: 11px; color: var(--ink-faint); }

@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .stat-strip { grid-template-columns: repeat(2, 1fr); max-width: none; }
}

/* ---------- ticket detail ---------- */
.detail-header { display: flex; align-items: center; gap: 10px; }
.detail-header .tid-lg { font-family: var(--font-mono); color: var(--ink-faint); font-size: 13px; }
.detail-title { font-size: 18px; font-weight: 700; margin: 10px 0 18px; text-wrap: balance; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px 20px;
  padding: 16px;
}
.meta-item .l { font-size: 10.5px; color: var(--ink-faint); margin-bottom: 2px; }
.meta-item .v { font-size: 13px; color: var(--ink); font-variant-numeric: tabular-nums; }

.desc-block { padding: 16px; white-space: pre-wrap; font-size: 13px; line-height: 1.7; color: var(--ink); }
.desc-block.empty { color: var(--ink-faint); }

.timeline { padding: 16px; display: flex; flex-direction: column; }
.tl-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 12px;
  position: relative;
  padding-bottom: 16px;
}
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 18px;
  bottom: 0;
  width: 1px;
  background: var(--line);
}
.tl-item:last-child::before { display: none; }
.tl-dot {
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
}
.tl-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: block; }
.tl-head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; }
.tl-user { font-weight: 700; }
.tl-time { font-size: 11px; color: var(--ink-faint); font-family: var(--font-mono); }
.tl-notes { margin-top: 4px; font-size: 12.5px; color: var(--ink); white-space: pre-wrap; }
.tl-notes.empty { color: var(--ink-faint); }

/* ---------- calendar (week time grid) ---------- */
:root { --hour-h: 44px; }
.timegrid-headrow { display: flex; border: 1px solid var(--line); border-bottom: none; background: var(--header-shade); }
.timegrid-head-gutter { width: 52px; flex-shrink: 0; border-right: 1px solid var(--line); }
.timegrid-head-days { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); }
.timegrid-head-days div {
  padding: 7px 8px; font-size: 11px; font-weight: 700; color: var(--ink-muted);
  text-align: center; border-right: 1px solid var(--line-soft);
}
.timegrid-head-days div:last-child { border-right: none; }
.timegrid-head-days div b { display: block; font-family: var(--font-mono); font-size: 13px; color: var(--ink); font-weight: 700; }
.timegrid-head-days div.is-today { color: var(--accent-ink); }
.timegrid-head-days div.is-today b { color: var(--accent); }

.timegrid-wrap { display: flex; border: 1px solid var(--line); background: var(--paper); margin-bottom: 16px; }
.timegrid-gutter { width: 52px; flex-shrink: 0; position: relative; border-right: 1px solid var(--line); height: calc(var(--hour-h) * 13); }
.timegrid-gutter .hr-label {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint);
}
.timegrid-days { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); }
.timegrid-day {
  position: relative;
  height: calc(var(--hour-h) * 13);
  border-right: 1px solid var(--line-soft);
  background-image: repeating-linear-gradient(to bottom, var(--line-soft) 0, var(--line-soft) 1px, transparent 1px, transparent var(--hour-h));
}
.timegrid-day:last-child { border-right: none; }
.timegrid-day.today-col { background-color: color-mix(in srgb, var(--accent) 5%, transparent); }

.tg-event {
  position: absolute; left: 3px; right: 3px;
  border-radius: 4px; padding: 2px 6px;
  font-size: 10.5px; line-height: 1.3;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, var(--paper));
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.tg-event .t { font-family: var(--font-mono); font-size: 9.5px; opacity: 0.75; margin-right: 4px; }

.tkt-pill, .gh-pill {
  display: inline-block; font-family: var(--font-mono); font-size: 9.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 8px; margin-left: 4px; text-decoration: none;
}
.tkt-pill { background: var(--header-shade); color: var(--ink-muted); border: 1px solid var(--line); }
.gh-pill {
  background: color-mix(in srgb, #7a5fc7 16%, var(--header-shade));
  color: #7a5fc7; border: 1px solid color-mix(in srgb, #7a5fc7 40%, transparent);
}

.timegrid-day { cursor: crosshair; user-select: none; }
.tg-event { cursor: pointer; }
.tg-select {
  position: absolute; left: 3px; right: 3px; z-index: 4;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border: 1px dashed var(--accent); border-radius: 4px; pointer-events: none;
}
.tg-resize-handle { position: absolute; left: 0; right: 0; height: 7px; cursor: ns-resize; z-index: 5; }
.tg-resize-handle.top { top: -3px; }
.tg-resize-handle.bottom { bottom: -3px; }
.tg-event:hover .tg-resize-handle { background: color-mix(in srgb, var(--accent) 45%, transparent); }

/* ---------- popover (click-to-operate) ---------- */
.popover {
  position: fixed; z-index: 50; width: 250px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 7px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.22);
  padding: 13px; display: none; font-size: 12px;
}
.popover.open { display: block; }
.popover .close-x { position: absolute; top: 6px; right: 9px; background: none; border: none; cursor: pointer; color: var(--ink-faint); font-size: 15px; line-height: 1; }
.popover h4 { margin: 0 14px 8px 0; font-size: 12.5px; font-weight: 700; }
.popover .meta { color: var(--ink-faint); font-size: 11px; margin-bottom: 8px; font-family: var(--font-mono); }
.popover .pv-actions { display: flex; flex-direction: column; gap: 6px; }
.popover .pv-actions .btn { text-align: left; width: 100%; }
.popover textarea, .popover input.pv-input {
  width: 100%; font-family: inherit; font-size: 12px; border: 1px solid var(--line);
  border-radius: 4px; padding: 6px; color: var(--ink); background: var(--paper); margin-bottom: 8px;
}
.popover textarea { resize: vertical; min-height: 44px; }
.popover .pv-row { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- issue autocomplete ---------- */
.issue-autocomplete { position: relative; max-width: 260px; }
.issue-suggest {
  display: none;
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 51;
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  max-height: 220px; overflow-y: auto;
}
.issue-suggest.open { display: block; }
.issue-suggest .item {
  display: block; width: 100%; text-align: left;
  padding: 6px 9px; font-size: 12px; color: var(--ink);
  background: none; border: none; border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.issue-suggest .item:last-child { border-bottom: none; }
.issue-suggest .item:hover { background: var(--accent-soft); }
.issue-suggest .item .tid { font-family: var(--font-mono); color: var(--ink-faint); margin-right: 6px; }
.issue-suggest .empty { padding: 6px 9px; font-size: 12px; color: var(--ink-faint); }

/* ---------- login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 320px;
  max-width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}
.login-card .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.login-card .brand .mark {
  width: 22px; height: 22px;
  border-radius: 4px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #201200;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.login-card .brand .name { font-size: 13px; font-weight: 700; color: var(--ink); }
.login-card .btn.primary { width: 100%; padding: 8px 13px; margin-top: 4px; }

.field { margin-bottom: 12px; }
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
.field-grid .field.field-full { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .field-grid { grid-template-columns: 1fr; }
}
.field label {
  display: block;
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
}
.field textarea { resize: vertical; }
.field .hint { font-size: 11px; color: var(--ink-faint); }
.checkbox-list { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checkbox-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink); }
.checkbox-item input[type="checkbox"] { accent-color: var(--accent); }
.settings-sections { display: flex; flex-direction: column; gap: 16px; max-width: 880px; }
.ledger .row-actions { display: flex; gap: 6px; }
.ledger .row-actions .btn { padding: 3px 8px; font-size: 11px; }
.errors {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}
.errors li {
  font-size: 11.5px;
  color: var(--st-closed, #bd4a3f);
  margin-bottom: 4px;
}
