:root {
  --bg: #ece8e1;
  --paper: #fffdf8;
  --paper-2: #f7f3ec;
  --sidebar: #171e28;
  --sidebar-2: #1f2835;
  --sidebar-text: #c5cdd8;
  --sidebar-muted: #8b95a5;
  --accent: #c45d26;
  --accent-2: #1e6f62;
  --ink: #1c232c;
  --muted: #6b7380;
  --line: #d9d1c4;
  --line-strong: #c4baab;
  --header: #ebe4d8;
  --edit: #fff7dc;
  --ok: #1e6f62;
  --warn: #b45309;
  --danger: #b42318;
  --info: #1d4e89;
  --shadow: 0 10px 30px rgba(23, 30, 40, 0.08);
  --radius: 10px;
  --sidebar-w: 216px;
  --sidebar-collapsed-w: 0px;
  --font: "IBM Plex Sans JP", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --mono: "IBM Plex Sans JP", "Yu Gothic UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: 0.01em;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

.app {
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  transition: grid-template-columns 0.18s ease;
}
.app.nav-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 1fr;
}
.sidebar { grid-column: 1; grid-row: 1; }
.main { grid-column: 2; grid-row: 1; min-width: 0; }

.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, #121820 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.app.nav-collapsed .sidebar {
  pointer-events: none;
}

.brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand small {
  display: block;
  color: var(--sidebar-muted);
  font-size: 10px;
  letter-spacing: 0.16em;
  margin-bottom: 4px;
}
.brand strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.brand em {
  display: block;
  margin-top: 4px;
  color: #e0a36b;
  font-style: normal;
  font-size: 11px;
}

.nav { padding: 12px 10px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  margin-bottom: 4px;
  white-space: nowrap;
}
.nav a svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: 0.85; }
.nav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav a.active {
  background: rgba(196, 93, 38, 0.18);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav .hint {
  margin: 18px 8px 6px;
  color: var(--sidebar-muted);
  font-size: 10px;
  letter-spacing: 0.14em;
}
.nav a.disabled { opacity: 0.35; pointer-events: none; }

.side-foot {
  padding: 12px 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  color: var(--sidebar-muted);
  font-size: 11px;
}

.main {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 48px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.nav-toggle {
  height: 32px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 8px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}
.nav-toggle:hover { background: var(--paper-2); }
.nav-toggle svg { width: 16px; height: 16px; display: block; flex-shrink: 0; }
.nav-backdrop {
  display: none;
  grid-column: 1 / -1;
  grid-row: 1;
}
.topbar h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.crumb {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.role-switch {
  display: flex;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}
.role-switch button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
}
.role-switch button.on {
  background: var(--ink);
  color: #fff;
}
.userchip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
}
.userchip b { font-size: 12px; }
.userchip span { color: var(--muted); font-size: 11px; }

.content {
  padding: 10px 14px 16px;
  min-width: 0;
  min-height: 0;
  flex: 1;
  overflow: auto;
  overflow-anchor: none;
}
.content.fill {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.content.fill .sheet-wrap {
  flex: 1;
  max-height: none;
  min-height: 0;
}
.content.fill .toolbar,
.content.fill .filters,
.content.fill .note {
  flex-shrink: 0;
}

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.toolbar.compact h2 { font-size: 15px; }
.toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.toolbar h2 { margin: 0 0 2px; font-size: 16px; }
.period-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}
.period-tools > label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.period-tools select,
.period-tools input[type="month"] {
  height: 32px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 7px;
  padding: 0 8px;
  color: var(--ink);
}
.period-custom { min-width: 240px; }
.period-custom.hidden { display: none; }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  border-radius: 7px;
  padding: 7px 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.btn:hover { background: var(--paper-2); }
.btn.primary { background: var(--accent); border-color: #a84c1c; color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e8b4ae; background: #fff8f7; }
.btn.sm { padding: 5px 8px; font-size: 12px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.filters {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.filters.collapsed .filters-grid { display: none; }
.filters.collapsed .filter-actions { margin-top: 0; }
.filters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 16px;
  align-items: end;
}
.field { min-width: 0; }
.filters-grid > .field,
.filters-grid > .field-md,
.filters-grid > .field-range {
  min-width: 0;
  max-width: none;
  width: auto;
}
.filters-grid > .field-range {
  grid-column: span 2;
}
.field label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 3px;
  letter-spacing: 0.04em;
}
.field input, .field select, .field textarea, .cell-editor {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 5px;
  padding: 5px 7px;
  color: var(--ink);
  outline: none;
  height: 28px;
}
.field textarea { height: auto; min-height: 64px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .cell-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196, 93, 38, 0.15);
}
.range {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  width: 100%;
}
.range span { color: var(--muted); font-size: 11px; flex: 0 0 auto; }
.range input[type="date"],
.range input[type="number"] {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  max-width: none;
}
.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

.sheet-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  overflow-anchor: none;
  max-height: calc(100vh - 210px);
  box-shadow: var(--shadow);
}
.sheet {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 2200px;
  width: max-content;
}
.sheet th, .sheet td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 3px 6px;
  font-size: 12px;
  white-space: nowrap;
  height: 26px;
  vertical-align: middle;
}
.sheet thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--header);
  font-weight: 600;
  font-size: 11px;
  color: #4b5563;
  text-align: left;
}
.sheet thead tr.groups th {
  top: 0;
  z-index: 6;
  text-align: center;
  height: 44px;
  white-space: normal;
  line-height: 1.3;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line-strong);
}
.sheet thead tr.groups th span {
  display: block;
  font-weight: 400;
  color: #6b7380;
  font-size: 10px;
  margin-top: 2px;
}
.sheet thead tr.col-names th {
  top: 44px;
  z-index: 5;
}
.sheet thead th.g-basic { background: #ebe4d8; }
.sheet thead th.g-dest { background: #e8e0d2; }
.sheet thead th.g-after { background: #dce8e4; }
.sheet thead th.g-publish { background: #e7eef6; }
.sheet thead th.g-admin { background: #e8efe9; }
.sheet th.group-start,
.sheet td.group-start {
  border-left: 2px solid #b9b0a2;
}
.sheet tbody tr:nth-child(even) td { background: var(--paper-2); }
.sheet tbody tr:nth-child(odd) td { background: #fff; }
.sheet tbody tr:hover td { background: #f3eee3; }
.sheet tbody tr:nth-child(odd) td.sticky { background: #fff; }
.sheet tbody tr:nth-child(even) td.sticky { background: var(--paper-2); }
.sheet tbody tr:hover td.sticky { background: #f3eee3; }
.filters.collapsed .search-row { display: none; }
.sheet td.editable { cursor: cell; }
.sheet td.editing { padding: 0; background: var(--edit) !important; }
.sheet td.editing .cell-editor {
  height: 26px;
  border: 2px solid var(--accent);
  border-radius: 0;
  padding: 0 5px;
}
.sheet td.num, .sheet th.num { text-align: right; }
.sheet td.lock { color: var(--muted); cursor: default; }
.sheet td.sticky, .sheet th.sticky {
  position: sticky;
  z-index: 4;
  box-shadow: 4px 0 8px rgba(0,0,0,0.04);
}
.sheet .sticky-0 { left: 0; width: 48px; min-width: 48px; }
.sheet .sticky-1 { left: 48px; width: 88px; min-width: 88px; }
.sheet .sticky-2 { left: 136px; min-width: 148px; }
.sheet thead th.sticky { z-index: 8; top: 0; background: var(--header); }
.sheet .row-num { width: 48px; min-width: 48px; color: var(--muted); text-align: center; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}
.status.wait { background: #fff3d6; color: #9a5b00; }
.status.open { background: #dcefe9; color: #14574c; }
.pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #efe8dc;
  font-size: 11px;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(23, 30, 40, 0.46);
  z-index: 50;
  display: grid;
  place-items: start center;
  padding: 28px 16px;
  overflow: auto;
}
.modal {
  width: min(980px, 100%);
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.22);
  border: 1px solid var(--line);
}
.modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal header h3 { margin: 0; font-size: 15px; }
.modal .body { padding: 14px 16px 18px; }
.modal footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 0 0 12px 12px;
}
.section {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}
.section h4 {
  margin: 0;
  padding: 7px 10px;
  background: var(--header);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.section h4 span { color: var(--muted); font-weight: 400; margin-left: 8px; }
.section .grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 12px;
  padding: 10px;
}
.section.admin h4 { background: #e8efe9; }
.section.locked { opacity: 0.72; }
.section.call h4 { background: #e7eef6; }
.section.visit h4 { background: #e8f3ee; }
.section-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.section-pair .section { margin-bottom: 0; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 80;
  box-shadow: var(--shadow);
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.login-card h2 { margin: 0 0 18px; font-size: 20px; }
.full { width: 100%; justify-content: center; height: 38px; }

.month-list { display: flex; flex-direction: column; gap: 12px; }
.month-block {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.month-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: linear-gradient(90deg, #171e28, #2a3648);
  color: #fff;
}
.month-head h3 { margin: 0; font-size: 15px; display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.month-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  justify-content: flex-end;
}
.month-note {
  flex: 1;
  min-width: 140px;
  max-width: 380px;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px dashed rgba(255,255,255,0.28);
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  line-height: 1.4;
  cursor: cell;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.month-note.is-empty { color: rgba(255,255,255,0.42); }
.month-note.readonly {
  cursor: default;
  border-style: solid;
  border-color: rgba(255,255,255,0.12);
}
.month-note.readonly.is-empty {
  border-color: transparent;
}
.month-note.editing { padding: 0; }
.month-note .cell-editor {
  height: 30px;
  background: transparent;
  border: 0;
  color: #fff;
  box-shadow: none;
  padding: 0 8px;
}
.month-note .cell-editor:focus {
  border: 0;
  box-shadow: none;
}
.month-head h3 { margin: 0; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.month-head .tag {
  background: rgba(224,163,107,0.2);
  color: #f0c089;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}
.kpis { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.kpi {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  padding: 4px 8px;
  min-width: 92px;
}
.kpi small { display: block; color: #9aa6b5; font-size: 10px; }
.kpi b { font-size: 13px; }
.month-table { width: 100%; border-collapse: collapse; min-width: 1280px; }
.month-table th, .month-table td {
  border: 1px solid var(--line);
  padding: 5px 7px;
  font-size: 12px;
  white-space: nowrap;
}
.month-table thead th {
  background: var(--header);
  font-size: 11px;
  font-weight: 600;
}
.month-table .g1 { background: #efe6d6; }
.month-table .g2 { background: #dce8e4; }
.month-table .g3 { background: #e7e1f0; }
.month-table .g4 { background: #f3e2d6; }
.month-table .g5 { background: #dce6f2; }
.month-table tbody td { background: #fff; }
.month-table tbody tr:nth-child(even) td { background: var(--paper-2); }
.month-table td.editcell { background: var(--edit) !important; cursor: cell; }
.month-table tfoot td {
  background: #2a333f;
  color: #fff;
  font-weight: 700;
  border-color: #3d4754;
  position: sticky;
  bottom: 0;
  z-index: 2;
}
.month-table tfoot td:first-child { letter-spacing: 0.12em; }
.month-scroll {
  overflow: auto;
  overflow-anchor: none;
}

.denied {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
}
.denied h2 { margin: 0 0 8px; }

.icon-btn {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  color: var(--muted);
}
.icon-btn:hover { color: var(--danger); }

.note {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .section .grid { grid-template-columns: repeat(3, 1fr); }
  .filters-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app,
  .app.nav-collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar,
  .app.nav-collapsed .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    pointer-events: auto;
    box-shadow: 8px 0 24px rgba(0,0,0,0.25);
  }
  .app.nav-open .sidebar {
    transform: translateX(0);
  }
  .app.nav-open .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(23, 30, 40, 0.46);
    z-index: 35;
  }
  .section .grid { grid-template-columns: 1fr 1fr; }
  .section-pair { grid-template-columns: 1fr; }
  .filters-grid { grid-template-columns: 1fr; }
  .filters-grid > .field-range { grid-column: auto; }
  .sitemap-list { grid-template-columns: 1fr; }
}

.sitemap {
  min-height: 100vh;
  padding: 28px 24px 40px;
  max-width: 960px;
  margin: 0 auto;
}
.sitemap header h1 {
  margin: 0 0 4px;
  font-size: 20px;
}
.sitemap header p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.sitemap-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.sitemap-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.sitemap-item b { font-size: 14px; }
.sitemap-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  flex: 1;
}
.sitemap-item .meta {
  font-size: 11px;
  color: #8a5a2b;
}
.sitemap-accounts {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.sitemap-accounts h2 {
  margin: 0 0 8px;
  font-size: 13px;
}
.sitemap-accounts p {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink);
}
