/* ─── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:          #f4f6f3;
  --surface:     #ffffff;
  --muted-bg:    #eef1ed;
  --ink:         #17201b;
  --muted:       #60706a;
  --border:      #d8ddd7;
  --green:       #06c755;
  --green-dk:    #059847;
  --shadow-sm:   0 1px 4px rgba(20,34,26,.06);
  --shadow:      0 4px 18px rgba(20,34,26,.08);
  --radius:      10px;

  /* Status badge palette */
  --amber-bg:#fef9c3; --amber-ink:#713f12;
  --blue-bg: #dbeafe; --blue-ink: #1e3a8a;
  --purple-bg:#f3e8ff;--purple-ink:#581c87;
  --orange-bg:#ffedd5;--orange-ink:#7c2d12;
  --teal-bg: #ccfbf1; --teal-ink: #134e4a;
  --indigo-bg:#e0e7ff;--indigo-ink:#312e81;
  --yellow-bg:#fef3c7;--yellow-ink:#78350f;
  --green-bg: #dcfce7; --green-ink:#14532d;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  font-size: 15px;
}

button, input, select, textarea { font: inherit; }

h1, h2, h3, p { margin: 0; }

textarea { resize: vertical; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--green);
  cursor: pointer;
  transition: background .12s, transform .1s, opacity .12s;
}
button:hover  { background: var(--green-dk); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.btn-cancel {
  background: var(--muted-bg);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-cancel:hover { background: var(--border); }

/* ─── Shell ──────────────────────────────────────────────────────────────── */
.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 52px;
}

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.eyebrow {
  margin: 0 0 3px;
  color: var(--green-dk);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

h1 { font-size: clamp(24px, 4vw, 38px); line-height: 1.15; }
h2 { font-size: 16px; }

/* ─── View toggle ────────────────────────────────────────────────────────── */
.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--muted-bg);
  border-radius: 9px;
  padding: 3px;
}
.view-btn {
  border: 0;
  border-radius: 7px;
  padding: 6px 18px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
.view-btn:hover { background: rgba(255,255,255,.5); transform: none; }
.view-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

/* ─── Summary grid ───────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.metric-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.metric strong { font-size: 30px; line-height: 1; }

/* ─── Workspace ──────────────────────────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: 290px minmax(0,1fr);
  gap: 14px;
  align-items: start;
}

.panel, .case-area {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.panel { padding: 18px; }

/* ─── Form (create) ──────────────────────────────────────────────────────── */
.form { display: grid; gap: 8px; margin-top: 12px; }

label { color: var(--muted); font-size: 13px; font-weight: 700; }

.inline-control {
  display: grid;
  grid-template-columns: minmax(0,1fr) 72px;
  gap: 8px;
}

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea { padding: 8px 10px; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(6,199,85,.14);
}

/* ─── Status palette / chips ─────────────────────────────────────────────── */
.quick-status { margin-top: 22px; }

.chip-all {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 10px 0 8px;
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--muted-bg);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.chip-all:hover { border-color: var(--green); transform: none; }
.chip-all.active { background: var(--green); border-color: var(--green); color: #fff; }

.status-palette { display: flex; flex-wrap: wrap; gap: 6px; }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--muted-bg);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.status-chip:hover { border-color: var(--chip-color, var(--green)); transform: none; }
.status-chip.active {
  background: var(--chip-color, var(--green));
  border-color: var(--chip-color, var(--green));
  color: #fff;
}
.chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 3px;
  border-radius: 999px;
  background: rgba(0,0,0,.12);
  font-size: 10px;
  font-weight: 700;
}
.status-chip.active .chip-count { background: rgba(255,255,255,.25); }

/* ─── Case area ──────────────────────────────────────────────────────────── */
.case-area { min-height: 500px; padding: 18px; }

.case-toolbar {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(180px,240px);
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}
.case-toolbar p { margin-top: 4px; color: var(--muted); font-size: 12px; }

.search { min-height: 36px; }

/* ─── Message ────────────────────────────────────────────────────────────── */
.message {
  margin-bottom: 12px;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: #0f5132;
  background: #dcfce7;
}
.message.error { color: #842029; background: #f8d7da; }

/* ─── Case list ──────────────────────────────────────────────────────────── */
.case-list { display: grid; gap: 10px; }

.case-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--surface);
  transition: box-shadow .15s;
}
.case-card:hover { box-shadow: var(--shadow); }

.case-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.plate { display: block; font-size: 19px; font-weight: 800; letter-spacing: .02em; }
.case-id { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-family: monospace; }

/* ── Status badge ── */
.badge {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--muted-bg);
  color: var(--ink);
}
.badge[data-color="amber"]  { background: var(--amber-bg);  color: var(--amber-ink); }
.badge[data-color="blue"]   { background: var(--blue-bg);   color: var(--blue-ink); }
.badge[data-color="purple"] { background: var(--purple-bg); color: var(--purple-ink); }
.badge[data-color="orange"] { background: var(--orange-bg); color: var(--orange-ink); }
.badge[data-color="teal"]   { background: var(--teal-bg);   color: var(--teal-ink); }
.badge[data-color="indigo"] { background: var(--indigo-bg); color: var(--indigo-ink); }
.badge[data-color="yellow"] { background: var(--yellow-bg); color: var(--yellow-ink); }
.badge[data-color="green"]  { background: var(--green-bg);  color: var(--green-ink); }

.case-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 4px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

/* Work dates row */
.case-dates {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}
.sep-arrow { color: var(--border); }
.case-dates.hidden { display: none; }

/* Owner / note row */
.case-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}
.case-extra.hidden { display: none; }

/* Status form */
.status-form {
  display: grid;
  grid-template-columns: minmax(0,1fr) 64px 34px 34px;
  gap: 6px;
  align-items: center;
}
.btn-update { font-size: 13px; padding: 0 6px; min-height: 34px; }

.btn-edit {
  min-height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 14px;
  padding: 0;
  border-radius: 8px;
}
.btn-edit:hover { background: var(--muted-bg); transform: none; }

.btn-delete {
  min-height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  color: #c0392b;
  font-size: 14px;
  padding: 0;
  border-radius: 8px;
}
.btn-delete:hover { background: #fff5f5; border-color: #c0392b; transform: none; }

/* Empty state */
.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 280px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
.empty-state strong { color: var(--ink); font-size: 17px; }

/* ─── Calendar ───────────────────────────────────────────────────────────── */
.cal-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.cal-nav h2 { flex: 1; text-align: center; font-size: 17px; }
.cal-nav button {
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 20px;
  background: var(--muted-bg);
  color: var(--ink);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.cal-nav button:hover { background: var(--border); transform: none; }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--muted-bg);
  font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0,1fr));
  gap: 1px;
  background: var(--border);
}

.cal-head {
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--muted-bg);
}

.cal-cell {
  min-height: 96px;
  padding: 6px;
  background: var(--surface);
  vertical-align: top;
  position: relative;
}
.cal-empty { background: var(--bg); }
.cal-today { background: #f0fdf4; }
.cal-today .cal-day-num { color: var(--green-dk); font-weight: 800; }

.cal-day-num {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.cal-events { display: flex; flex-direction: column; gap: 2px; }

.cal-event {
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  opacity: .9;
  transition: opacity .1s;
}
.cal-event:hover { opacity: 1; }
.cal-delivery { opacity: .75; }

.cal-more {
  font-size: 10px;
  color: var(--muted);
  padding-left: 3px;
  cursor: default;
}

/* ─── Edit modal ─────────────────────────────────────────────────────────── */
dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  max-width: 500px;
  width: calc(100% - 32px);
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
}
dialog::backdrop { background: rgba(0,0,0,.45); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; }

.btn-icon-close {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--muted-bg);
  color: var(--muted);
  font-size: 14px;
  border: 0;
}
.btn-icon-close:hover { background: var(--border); transform: none; }

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 12px;
}

.field-group { display: flex; flex-direction: column; gap: 4px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.modal-footer button { min-height: 36px; padding: 0 18px; font-size: 14px; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .shell { width: calc(100% - 20px); padding-top: 14px; }

  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: space-between; }

  .summary-grid { gap: 8px; }
  .metric { padding: 12px 14px; }
  .metric strong { font-size: 24px; }

  .case-toolbar { grid-template-columns: 1fr; }

  .inline-control { grid-template-columns: 1fr; }

  .status-form {
    grid-template-columns: minmax(0,1fr) 58px 32px 32px;
    gap: 4px;
  }

  .field-row { grid-template-columns: 1fr; }

  .cal-cell { min-height: 64px; }
  .cal-event { font-size: 10px; }
}
