:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9e0e7;
  --line-soft: #e8edf2;
  --text: #16202a;
  --muted: #647282;
  --blue: #1769e0;
  --blue-dark: #0f56bd;
  --amber: #ffb020;
  --amber-soft: #fff4d6;
  --green-soft: #e8f6ef;
  --green-line: #b8dfca;
  --red-soft: #fff0f0;
  --red-line: #e8b5b5;
  --shadow: 0 10px 30px rgba(22, 32, 42, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body { margin: 0; font-family: Arial, sans-serif; color: var(--text); background: var(--bg); font-variant-numeric: tabular-nums; }

.skip-link { position: absolute; left: 16px; top: -48px; z-index: 10; padding: 8px 12px; background: var(--text); color: #fff; border-radius: 6px; }
.skip-link:focus-visible { top: 12px; }
.app-shell { display: grid; grid-template-columns: 190px minmax(0, 1fr); min-height: 100vh; }
.app-shell.sidebar-collapsed { grid-template-columns: 52px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; align-self: start; height: 100vh; padding: 22px 14px; background: var(--panel); border-right: 1px solid var(--line); }
.sidebar-toggle { width: 100%; padding: 0 4px; background: #fff; color: var(--blue); border-color: var(--line); }
.sidebar-toggle:hover { background: #eef5ff; }
.sidebar-collapsed .sidebar { padding: 8px; }
.sidebar-collapsed .sidebar nav { margin-top: 8px; }
.sidebar nav { display: grid; gap: 5px; margin-top: 22px; }
.sidebar-logout-form { margin-top: 16px; }
.sidebar-logout { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: transparent; color: var(--muted); border-color: transparent; text-align: left; }
.sidebar-logout:hover { background: #eef5ff; color: var(--blue); }
.sidebar-collapsed .sidebar-logout { justify-content: center; padding: 10px 0; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; color: var(--muted); font-size: 14px; font-weight: 700; text-decoration: none; }
.side-icon { width: 16px; font-size: 18px; line-height: 1; text-align: center; }
.sidebar-collapsed .side-link { justify-content: center; padding: 10px 0; }
.sidebar-collapsed .side-label { display: none; }
.side-link:hover, .side-link.active { background: #eef5ff; color: var(--blue); }
.page-content { min-width: 0; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.login-card { display: grid; gap: 14px; width: min(360px, 100%); padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: 8px; }
.login-card label { color: var(--muted); font-size: 12px; font-weight: 700; }
.login-card .error { margin: 0; }

.app-header { display: grid; align-items: center; gap: 22px; padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
.version-label { margin-left: 8px; color: var(--blue); font-size: 12px; font-weight: 700; vertical-align: middle; }
h1, h2 { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }

.upload-panel { min-width: 420px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; }
.upload-panel label, .field label, .drawer-body label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.upload-row { display: flex; gap: 8px; align-items: center; }
.status-date-range > label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.header-date-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) 30px; gap: 5px; align-items: center; }
.header-date-row .secondary { min-width: 0; width: 30px; padding: 0; }

.status-strip { display: flex; align-items: end; gap: 18px; padding: 10px 22px; background: #eef3f8; border-bottom: 1px solid var(--line); }
.import-status { display: flex; flex: 1; flex-wrap: wrap; gap: 8px; align-items: center; }
.status-strip span { display: inline-flex; gap: 6px; align-items: center; min-height: 28px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 13px; }
.status-strip strong { color: var(--text); }
.warning-stat { background: var(--amber-soft) !important; }
.status-date-range { flex: 0 1 clamp(340px, 30vw, 560px); min-width: 0; }

.notice, .error { margin: 12px 22px 0; padding: 10px 12px; border-radius: 8px; }
.notice { background: var(--green-soft); border: 1px solid var(--green-line); }
.error { background: var(--red-soft); border: 1px solid var(--red-line); }

.workspace { padding: 16px 22px 22px; }
.import-workspace { display: grid; gap: 16px; max-width: 620px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.field { min-width: 0; }
.field-search { grid-column: span 2; min-width: 260px; }
.multi-filter { position: relative; }
.multi-filter summary { display: flex; align-items: center; height: 36px; padding: 0 10px; border: 1px solid #bfc9d4; border-radius: 6px; background: #fff; cursor: pointer; list-style: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-filter summary::-webkit-details-marker { display: none; }
.multi-filter-menu { position: absolute; z-index: 5; min-width: 180px; max-height: 240px; overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
.multi-filter-menu label { display: block; padding: 5px 4px; color: var(--text); cursor: pointer; }
.multi-filter-menu input { width: 14px; height: 14px; padding: 0; vertical-align: middle; }

input, select, textarea, button { width: 100%; border: 1px solid #bfc9d4; border-radius: 6px; padding: 0 10px; background-color: #fff; color: var(--text); font: inherit; }
input, select, button { height: 36px; }
textarea { padding: 8px 10px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid rgba(23, 105, 224, 0.28); outline-offset: 2px; border-color: var(--blue); }
button { cursor: pointer; background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 700; }
button:hover { background: var(--blue-dark); }
button:active { transform: translateY(1px); }
.secondary { min-width: 82px; background: #fff; color: var(--blue); }
.secondary:hover { background: #eef5ff; }

.toggle-group { display: flex; gap: 6px; align-items: center; grid-column: span 2; min-width: 250px; }
.date-range-control input { width: 100%; }
.toggle-group label { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: #f9fbfd; white-space: nowrap; cursor: pointer; }
.toggle-group input { width: 14px; height: 14px; padding: 0; }

.table-header { display: flex; justify-content: space-between; gap: 18px; align-items: end; margin: 16px 0 8px; }
.table-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.hint { text-align: right; }

.table-shell { overflow: auto; max-height: calc(100vh - 250px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.compact-table { width: 100%; min-width: 1120px; table-layout: fixed; border-collapse: separate; border-spacing: 0; }
.compact-table th, .compact-table td { border-bottom: 1px solid var(--line-soft); padding: 7px 10px; text-align: left; font-size: 13px; vertical-align: top; line-height: 1.25; }
.compact-table th { position: sticky; top: 0; z-index: 1; background: #eaf0f5; color: #263747; font-size: 12px; font-weight: 800; }
.compact-table tbody tr:hover { background: #f7fbff; }
.compact-table th:nth-child(1), .compact-table td:nth-child(1) { width: 48px; }
.compact-table th:nth-child(2), .compact-table td:nth-child(2) { width: 105px; }
.compact-table th:nth-child(3), .compact-table td:nth-child(3) { width: 100px; }
.compact-table th:nth-child(4), .compact-table td:nth-child(4) { width: 90px; }
.compact-table th:nth-child(5), .compact-table td:nth-child(5) { width: 165px; }
.compact-table th:nth-child(6), .compact-table td:nth-child(6) { width: 165px; }
.compact-table th:nth-child(7), .compact-table td:nth-child(7) { width: 160px; }
.compact-table th:nth-child(8), .compact-table td:nth-child(8) { width: 180px; }
.compact-table th:nth-child(9), .compact-table td:nth-child(9) { width: 190px; }
.compact-table th:nth-child(10), .compact-table td:nth-child(10) { width: 120px; }.line-cell span { display: block; margin-bottom: 2px; white-space: normal; overflow-wrap: anywhere; }
.customer-cell span:first-child { font-size: 15px; font-weight: 700; }
.booked-cell span:first-child, .booked-cell span:nth-child(2), .payment-cell span:first-child, .payment-cell span:nth-child(2) { font-weight: 700; }
.mono { font-family: Consolas, monospace; }
.quiet { color: #8a97a5; }
.remark { white-space: normal; overflow-wrap: anywhere; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 6px; font-weight: 700; overflow-wrap: anywhere; }
.status-open { background: transparent; color: var(--text); padding-left: 0; }
.status-close { background: #dff3e6; color: #116329; }
.category-pill { display: inline-flex; min-height: 24px; padding: 3px 8px; border-radius: 6px; font-weight: 700; }
.category-normal { background: #eef3f8; color: #405163; }
.category-free, .category-cancelled { background: #edf9f0; color: #116329; }
.status-review { background: #d8232a; color: #fff; }
.warn-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 26px; padding: 0 8px; border-radius: 999px; background: var(--amber); color: #241a00; font-weight: 800; cursor: pointer; list-style: none; }
.warn-badge::-webkit-details-marker { display: none; }
.warning-popover { position: relative; }
.warning-list { position: absolute; z-index: 3; min-width: 300px; max-width: 440px; margin-top: 8px; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 14px 34px rgba(22, 32, 42, 0.18); white-space: normal; }
.warning-list p { margin: 0 0 8px; color: var(--muted); line-height: 1.35; }
.action-cell { display: grid; gap: 6px; }
.open-drawer, .history-button { height: 30px; padding: 0 10px; background: transparent; color: var(--blue); border-color: #c4dafb; }
.open-drawer:hover, .history-button:hover { background: #eef5ff; }
.history-item { display: grid; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.history-item span { color: var(--muted); overflow-wrap: anywhere; }

.empty-state { padding: 54px 24px; text-align: center; }
.empty-state p { margin: 8px 0 0; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(22, 32, 42, 0.28); }
.drawer { position: fixed; top: 0; right: 0; z-index: 21; width: min(430px, 100vw); height: 100vh; background: #fff; border-left: 1px solid var(--line); box-shadow: -18px 0 40px rgba(22, 32, 42, 0.18); transform: translateX(100%); transition: transform 140ms ease; }
.drawer.is-open { transform: translateX(0); }
.drawer form { display: flex; flex-direction: column; height: 100%; }
#historyDrawer { display: flex; flex-direction: column; }
#historyBody { flex: 1; min-height: 0; overflow: auto; }
.drawer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px; border-bottom: 1px solid var(--line); }
.drawer-sub { margin: 4px 0 0; color: var(--muted); }
.icon-button { width: 34px; height: 34px; padding: 0; background: #fff; color: var(--text); border-color: var(--line); }
.drawer-body { display: grid; gap: 8px; padding: 18px; overflow: auto; }
.date-row { display: grid; grid-template-columns: 1fr 150px; gap: 8px; }
.drawer-footer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }

@media (max-width: 1100px) {
  .app-header { gap: 14px; }
  .status-strip { align-items: stretch; flex-direction: column; }
  .status-date-range { flex-basis: auto; }
  .table-header { align-items: stretch; flex-direction: column; }
  .upload-panel { min-width: 0; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-search, .toggle-group { grid-column: 1 / -1; }
  .hint { text-align: left; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-shell.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; align-items: center; gap: 16px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-collapsed .sidebar { padding: 12px 16px; }
  .sidebar-collapsed .side-label { display: inline; }
  .sidebar-toggle { display: none; }
  .sidebar .eyebrow { margin: 0; }
  .sidebar nav { display: flex; gap: 4px; margin: 0; }
  .sidebar-logout-form { margin: 0; }
  .sidebar-logout { padding: 8px; }
  .side-link { padding: 8px; }
}

@media (min-width: 1500px) {
  .filters { grid-template-columns: minmax(260px, 1.2fr) repeat(4, minmax(120px, 1fr)) minmax(160px, 1fr) 120px; }
  .field-search, .toggle-group { grid-column: span 1; min-width: 0; }
}

.nav-link, .table-link { display: inline-block; margin-top: 6px; color: var(--blue); font-size: 13px; font-weight: 700; text-decoration: none; }
.dashboard { max-width: 1480px; margin: 0 auto; }
.dashboard-filters { grid-template-columns: 180px 180px 110px; max-width: 520px; }
.dashboard-cards { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 10px; margin-top: 16px; }
.dashboard-card { display: grid; gap: 5px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.dashboard-card span, .dashboard-card small { color: var(--muted); font-size: 12px; font-weight: 700; }
.dashboard-card strong { font-size: 28px; }
.dashboard-card.status-review { border-color: var(--red-line); background: var(--red-soft); }
.dashboard-card.status-free, .dashboard-card.status-cancelled { border-color: var(--green-line); background: var(--green-soft); }
.chart-section { margin-top: 20px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.chart-legend span::before { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 2px; content: ""; }
.legend-open::before, .segment-open { background: #4b8fea; }.legend-close::before, .segment-close { background: #55a86b; }.legend-free::before, .segment-free { background: #9ad6a8; }.legend-cancelled::before, .segment-cancelled { background: #a8b4c1; }.legend-review::before, .segment-review { background: #d8232a; }
.bar-chart { display: flex; align-items: end; gap: 10px; min-height: 310px; overflow-x: auto; padding: 12px 4px 0; border-top: 1px solid var(--line-soft); }
.chart-day { display: grid; flex: 0 0 60px; gap: 5px; align-items: end; text-align: center; font-size: 11px; }
.chart-stack { display: flex; flex-direction: column-reverse; justify-content: flex-start; width: 40px; height: 230px; margin: 0 auto; overflow: hidden; background: #f2f5f7; border-radius: 4px 4px 0 0; }
.bar-segment { display: block; width: 100%; min-height: 2px; }.chart-day strong { font-size: 11px; }.chart-day small { color: var(--muted); }.empty-chart { color: var(--muted); }
@media (max-width: 900px) { .dashboard-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dashboard-filters { grid-template-columns: 1fr 1fr; } .dashboard-filters button { grid-column: 1 / -1; } }
