:root {
  --ink: #17302b;
  --muted: #6b7d78;
  --line: #dce8e3;
  --panel: #ffffff;
  --canvas: #f4f8f6;
  --brand: #1f6b5a;
  --brand-dark: #12493e;
  --accent: #d89751;
  --revisit: #c56a2d;
  --revisit-background: #fff3e6;
  --calendar-hour-height: 64px;
  --calendar-visible-hours: 12;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 .35rem; color: var(--accent); font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #d8eee6, transparent 42%), var(--canvas); }
.auth-card { width: min(420px, calc(100% - 2rem)); padding: 2.5rem; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); box-shadow: 0 24px 60px #17302b16; }
.brand-logo { width: min(100%, 260px); height: auto; margin-bottom: 1.5rem; }
.stack-form { display: grid; gap: 1rem; }
label { display: grid; gap: .4rem; font-size: .9rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: .65rem .75rem; color: var(--ink); background: #fbfdfc; }
.case-edit-locked input:disabled, .case-edit-locked select:disabled { color: var(--muted); background: #edf2ef; border-color: #cbd9d2; cursor: not-allowed; opacity: 1; }
textarea { min-height: 90px; resize: vertical; }
button { border: 0; border-radius: 9px; padding: .65rem 1rem; color: var(--ink); background: #e8f1ed; }
button.primary { color: #fff; background: var(--brand); }
button.primary:hover { background: var(--brand-dark); }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar { display: flex; flex-direction: column; min-height: 100vh; padding: 1.25rem; color: #eaf6f0; background: var(--brand-dark); }
.sidebar-brand { display: grid; gap: .55rem; padding: .5rem; margin-bottom: 2rem; }
.sidebar-brand img { width: 100%; filter: brightness(0) invert(1); }
.sidebar-brand span { color: #a8cdbf; font-size: .72rem; letter-spacing: .08em; }
#main-nav { display: grid; gap: .45rem; }
#main-nav button { text-align: left; color: #d9eee6; background: transparent; }
#main-nav button:hover, #main-nav button.active { color: #fff; background: #ffffff1c; }
.sidebar-footer { display: grid; gap: .8rem; margin-top: auto; padding: 1rem .5rem .25rem; border-top: 1px solid #ffffff28; }
#user-badge { font-size: .82rem; color: #cce5db; }
.link-button { padding: 0; text-align: left; color: #f6d2a6; background: transparent; }
.content-shell { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.5rem 2.25rem; border-bottom: 1px solid var(--line); background: #ffffffb8; backdrop-filter: blur(10px); }
.topbar h1 { margin: 0; font-size: 1.55rem; }
.page-content { max-width: 1500px; padding: 1.5rem 2.25rem 3rem; }
.panel { margin-bottom: 1.25rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 8px 30px #17302b08; }
.panel h2, .panel h3 { margin-top: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .65rem; align-items: end; margin-bottom: 1rem; }
.calendar-toolbar { margin-bottom: 0; }
.calendar-nav { min-width: 2.8rem; padding-inline: .65rem; font-weight: 700; }
.toolbar label { min-width: 160px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.form-row { display: grid; grid-column: 1 / -1; gap: 1rem; }
.form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.danger-text { color: #a33f39; }
.filter-group { min-width: min(100%, 300px); }
.filter-label { display: block; margin-bottom: .4rem; font-size: .9rem; font-weight: 650; }
.filter-group .check-grid { min-height: 42px; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 9px; background: #fbfdfc; }
.filter-group .check-grid label { min-width: auto; }
.check-grid { display: flex; flex-wrap: wrap; gap: .45rem .8rem; padding: .55rem 0; }
.check-grid label { display: inline-flex; align-items: center; gap: .35rem; font-weight: 500; }
.check-grid input { width: auto; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .75rem .6rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: top; }
th { color: var(--muted); font-size: .78rem; letter-spacing: .03em; }
td.wrap { white-space: normal; }
.badge { display: inline-block; padding: .2rem .5rem; border-radius: 999px; color: var(--brand-dark); background: #e6f2ed; font-size: .78rem; }
.calendar-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem; align-items: center; }
.calendar-shell { overflow-x: auto; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.calendar-cell { min-height: 120px; padding: .55rem; background: var(--panel); }
.calendar-cell.other-month { background: #fbfdfc; }
.calendar-cell.other-month .calendar-date { color: #a3b1ac; }
.calendar-cell.today { box-shadow: inset 0 3px var(--accent); }
.calendar-date { color: var(--muted); font-size: .78rem; }
.event { position: relative; display: block; width: 100%; margin-top: .4rem; padding: .35rem .45rem; border-left: 4px solid var(--brand); border-radius: 5px; color: var(--ink); text-align: left; background: #edf6f2; font-size: .75rem; }
.event:hover, .day-event:hover { background: #dceee7; }
.event strong { display: block; overflow: hidden; text-overflow: ellipsis; }
.event span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event.revisit-event, .day-event.revisit-event { border-left-color: var(--revisit); background: var(--revisit-background); }
.event.revisit-event:hover, .day-event.revisit-event:hover { background: #ffe7cf; }
.revisit-label { position: absolute; top: .3rem; right: .45rem; color: var(--revisit); font-size: .62rem; font-weight: 700; line-height: 1; }
.event.revisit-event strong, .day-event.revisit-event strong { padding-right: 2.2rem; }
.calendar-week-caption { margin-bottom: .7rem; color: var(--muted); font-weight: 700; }
.calendar-week { display: grid; grid-template-columns: 4.5rem repeat(7, minmax(110px, 1fr)); grid-template-rows: auto auto; min-width: 820px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.week-corner, .week-day-header { min-height: 2.8rem; border-bottom: 1px solid var(--line); background: #fbfdfc; }
.week-corner { grid-column: 1; grid-row: 1; }
.week-day-header { padding: .55rem .45rem; color: var(--muted); font-size: .78rem; }
.week-day-header.today { box-shadow: inset 0 3px var(--accent); }
.week-time-axis { grid-column: 1; grid-row: 2; min-height: calc(var(--calendar-hour-height) * var(--calendar-visible-hours)); color: var(--muted); background: #fbfdfc; }
.week-timelines { grid-column: 2 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); min-height: calc(var(--calendar-hour-height) * var(--calendar-visible-hours)); }
.week-day-column { position: relative; min-height: calc(var(--calendar-hour-height) * var(--calendar-visible-hours)); border-left: 1px solid var(--line); }
.week-day-column.today { background: #fcfffd; }
.week-day-column .day-hour-row { background: linear-gradient(to bottom, transparent calc(100% - 1px), var(--line) calc(100% - 1px)); }
.week-event { font-size: .72rem; }
.calendar-day-caption { margin-bottom: .7rem; color: var(--muted); font-weight: 700; }
.calendar-day { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); min-width: 300px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.day-time-axis, .day-timeline { min-height: calc(var(--calendar-hour-height) * var(--calendar-visible-hours)); }
.day-time-axis { color: var(--muted); background: #fbfdfc; }
.day-timeline { position: relative; }
.day-hour-row { position: relative; height: var(--calendar-hour-height); border-bottom: 1px solid var(--line); }
.day-time-axis .day-hour-row span, .week-time-axis .day-hour-row span { position: absolute; top: -.55rem; right: .5rem; padding-left: .25rem; background: #fbfdfc; font-size: .72rem; }
.day-time-axis .day-hour-row:first-child span, .week-time-axis .day-hour-row:first-child span { top: .5rem; }
.day-timeline .day-hour-row { background: linear-gradient(to bottom, transparent calc(100% - 1px), var(--line) calc(100% - 1px)); }
.day-event { position: absolute; z-index: 2; left: .65rem; right: .65rem; min-height: 46px; padding: .4rem .55rem; border-left: 4px solid var(--brand); border-radius: 6px; color: var(--ink); text-align: left; background: #edf6f2; box-shadow: 0 3px 10px #17302b14; overflow: hidden; }
.day-event strong, .day-event span, .day-event small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-event strong { font-size: .82rem; }
.day-event span, .day-event small { font-size: .75rem; }
.day-event small { color: var(--muted); }
.daily-inquiry-panel { margin-top: 1.5rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfc; }
.daily-inquiry-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.daily-inquiry-heading h2 { margin: 0 0 .35rem; }
.daily-inquiry-scroll { overflow-x: auto; padding: 1rem 0 .2rem; }
.daily-inquiry-chart { display: flex; align-items: end; gap: .4rem; min-width: max-content; min-height: 205px; padding: .5rem .5rem 0; border-bottom: 1px solid var(--line); }
.daily-inquiry-bar { display: grid; grid-template-rows: 1.25rem 150px auto; width: 2.75rem; min-width: 2.75rem; text-align: center; }
.daily-inquiry-count { align-self: end; color: var(--brand-dark); font-size: .76rem; font-weight: 700; }
.daily-inquiry-track { display: flex; align-items: end; justify-content: center; }
.daily-inquiry-value { width: 1.45rem; min-height: 2px; border-radius: 7px 7px 2px 2px; background: var(--accent); }
.daily-inquiry-label { margin-top: .45rem; color: var(--muted); font-size: .68rem; line-height: 1.25; white-space: nowrap; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.report-section { margin-top: 1.5rem; }
.report-section:first-of-type { margin-top: 0; }
.report-card { padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: #fbfdfc; }
.report-card h3 { margin: 0 0 .5rem; }
.report-chart { display: grid; grid-template-columns: minmax(118px, 150px) minmax(0, 1fr); gap: 1rem; align-items: center; margin: .25rem 0 1rem; }
.report-pie { width: min(150px, 100%); aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 0 0 1px #17302b18, 0 4px 10px #17302b12; }
.report-chart-legend { display: grid; gap: .35rem; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: .8rem; }
.report-chart-legend li { display: grid; grid-template-columns: .7rem minmax(0, 1fr) auto; gap: .4rem; align-items: center; }
.report-chart-legend li strong { color: var(--ink); font-size: .78rem; }
.report-chart-swatch { width: .7rem; height: .7rem; border-radius: 2px; }
.report-chart-empty { min-height: 120px; place-items: center; color: var(--muted); background: #f4f8f6; border-radius: 10px; font-size: .85rem; }
.report-total { margin-bottom: .75rem; color: var(--brand); font-weight: 700; }
.toast { position: fixed; z-index: 10; right: 1.25rem; bottom: 1.25rem; max-width: min(420px, calc(100% - 2rem)); padding: .8rem 1rem; border-radius: 10px; color: #fff; background: var(--brand-dark); opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }
.modal { position: fixed; z-index: 5; inset: 0; display: grid; place-items: center; padding: 1rem; background: #17302b66; }
.modal-card { width: min(440px, 100%); padding: 2rem; border-radius: 18px; background: var(--panel); }
.audit-list { margin: 0; padding-left: 1.15rem; color: var(--muted); font-size: .82rem; }
.case-progress { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.case-progress h3 { margin-bottom: 1rem; }
.case-progress h4 { margin: 1.25rem 0 .65rem; }
.progress-history { display: grid; gap: .7rem; margin: 0; padding: 0; list-style: none; }
.progress-history li { padding: .75rem; border: 1px solid var(--line); border-radius: 9px; background: #fbfdfc; }
.progress-history-note { white-space: pre-wrap; }
.progress-history-meta { margin-top: .4rem; color: var(--muted); font-size: .8rem; }
.progress-history-actions { display: flex; justify-content: flex-end; margin-top: .55rem; }
@media (max-width: 900px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; top: 0; z-index: 4; min-height: 0; padding: .8rem 1rem .7rem; }
  .sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: 0; margin: 0 0 .7rem; }
  .sidebar-brand img { width: min(220px, 58vw); }
  .sidebar-brand span { font-size: .65rem; white-space: nowrap; }
  #main-nav { display: flex; gap: .35rem; overflow-x: auto; padding-bottom: .15rem; scrollbar-width: thin; }
  #main-nav button { flex: 0 0 auto; padding: .55rem .7rem; white-space: nowrap; }
  .sidebar-footer { display: flex; align-items: center; gap: .75rem; margin-top: .65rem; padding: .65rem 0 0; }
  #user-badge { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content-shell { min-width: 0; }
  .topbar { flex-direction: column; align-items: stretch; gap: .7rem; padding: .9rem .75rem; }
  .topbar h1 { font-size: 1.35rem; }
  #page-actions { width: 100%; }
  #page-actions .toolbar { width: 100%; margin-bottom: 0; overflow-x: auto; align-items: center; flex-wrap: nowrap; }
  #page-actions .toolbar label { min-width: 0; flex: 1 1 auto; }
  #page-actions .toolbar button { flex: 0 0 auto; }
  .page-content { padding: .75rem .6rem 2rem; }
  .panel { padding: .8rem; border-radius: 12px; }
  .toolbar > label, .toolbar > .filter-group { min-width: 100%; }
  .form-grid, .form-row.two, .form-row.three, .report-grid { grid-template-columns: 1fr; }
  .daily-inquiry-heading { flex-direction: column; }
  .report-chart { grid-template-columns: 1fr; }
  .report-pie { margin-inline: auto; }
  .form-grid .wide, .form-grid .full, .form-row { grid-column: auto; }
  .calendar-shell .calendar-grid { min-width: 700px; }
  .calendar-shell .calendar-week { min-width: 820px; }
  .calendar-day { min-width: 300px; }
  .calendar-cell { min-height: 90px; }
}
