:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --ink: #18211d;
  --muted: #68726c;
  --paper: #fffefa;
  --canvas: #f1f0eb;
  --line: #d9ddd7;
  --green: #176b4d;
  --green-soft: #e3f0e9;
  --red: #a23c35;
  --red-soft: #f7e7e4;
  --amber: #9a6518;
  --amber-soft: #f6ecd8;
  --blue: #335f82;
  --blue-soft: #e5edf3;
  --shadow: 0 16px 45px rgba(30, 39, 34, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template: 72px 1fr / 220px 1fr;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}

.brand, .topbar-actions, .status-dot {
  display: flex;
  align-items: center;
}

.brand { gap: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--green);
  color: white;
  font-family: Georgia, serif;
  font-size: 20px;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.topbar-actions { gap: 18px; }
.status-dot { gap: 7px; color: var(--muted); font-size: 12px; }
.status-dot i { width: 7px; height: 7px; border-radius: 50%; background: #30a46c; }

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
  font-size: 20px;
}
.icon-button:hover { background: #f3f5f2; }

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: #202a25;
  color: #e9eee9;
}

.sidebar nav { display: grid; gap: 6px; }
.nav-item {
  width: 100%;
  height: 44px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: #bfc9c2;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: #29362f; color: white; }
.nav-item.active { background: #e7eee9; color: #193e2f; font-weight: 700; }
.nav-icon { font-size: 17px; text-align: center; }
.nav-item b {
  min-width: 20px;
  padding: 2px 5px;
  background: #34433a;
  color: #d8dfda;
  font-size: 10px;
  text-align: center;
}
.nav-item.active b { background: #c7dbce; color: #174d37; }

.principle {
  margin-top: auto;
  padding: 18px 12px;
  border-top: 1px solid #3b4740;
}
.principle span { display: block; margin-bottom: 8px; color: #8fa096; font-size: 11px; }
.principle strong { font-family: Georgia, "Noto Serif TC", serif; font-size: 18px; line-height: 1.55; }

main {
  min-width: 0;
  padding: 30px clamp(22px, 4vw, 54px) 60px;
  overflow: hidden;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(27px, 3vw, 38px); letter-spacing: 0; }
.page-head p { margin-bottom: 0; color: var(--muted); font-size: 14px; }

.date-block { text-align: right; }
.date-block strong { display: block; font-size: 17px; }
.date-block span { color: var(--muted); font-size: 12px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.metric {
  min-height: 116px;
  padding: 22px;
  border-right: 1px solid var(--line);
}
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 9px 0 7px; font-size: 30px; }
.metric small { color: var(--green); font-size: 11px; font-weight: 700; }
.metric small.warn { color: var(--red); }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 30px 0 12px;
}
.section-title h2 { margin: 0; font-size: 16px; }
.section-title span { color: var(--muted); font-size: 12px; }

.workflow {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--paper);
  border: 1px solid var(--line);
}
.flow-step {
  position: relative;
  min-height: 130px;
  padding: 20px;
  border-right: 1px solid var(--line);
}
.flow-step:last-child { border-right: 0; }
.flow-step:not(:last-child)::after {
  content: "›";
  position: absolute;
  z-index: 1;
  top: 48px;
  right: -9px;
  width: 18px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--paper);
  color: #a5aea8;
  font-size: 24px;
}
.step-number { color: var(--green); font-size: 11px; font-weight: 800; }
.flow-step strong { display: block; margin: 13px 0 6px; font-size: 14px; }
.flow-step p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.notice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  padding: 17px 19px;
  background: var(--blue-soft);
  border-left: 3px solid var(--blue);
  font-size: 13px;
  line-height: 1.65;
}
.notice strong { display: block; margin-bottom: 2px; }
.notice p { margin: 0; color: #455865; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.segmented {
  display: inline-flex;
  padding: 3px;
  background: #e3e4df;
}
.segment {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.segment.active { background: white; color: var(--ink); font-weight: 700; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.primary, .secondary, .danger-button {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.primary { background: var(--green); color: white; }
.primary:hover { background: #105b40; }
.secondary { border-color: var(--line); background: white; }
.secondary:hover { background: #f5f5f1; }
.danger-button { background: var(--red-soft); color: var(--red); }

.radar-list, .invoice-list { display: grid; gap: 10px; }
.radar-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1.3fr) minmax(190px, .7fr) 130px;
  align-items: center;
  gap: 17px;
  padding: 17px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.risk-bar { width: 4px; height: 42px; background: var(--amber); }
.risk-bar.high { background: var(--red); }
.radar-row h3 { margin: 0 0 5px; font-size: 14px; }
.meta { color: var(--muted); font-size: 11px; }
.radar-summary { margin: 0; color: #4b5750; font-size: 12px; line-height: 1.6; }
.row-actions { text-align: right; }
.tag {
  display: inline-block;
  padding: 4px 7px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 10px;
  font-weight: 800;
}
.tag.high { background: var(--red-soft); color: var(--red); }
.tag.ok { background: var(--green-soft); color: var(--green); }

.split-layout {
  display: grid;
  grid-template-columns: minmax(300px, .8fr) minmax(380px, 1.2fr);
  gap: 18px;
}
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 14px; }
.panel-body { padding: 18px; }
.role-switch { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }

.chat {
  min-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: #edf0eb;
}
.bubble {
  max-width: 83%;
  padding: 12px 14px;
  background: white;
  font-size: 13px;
  line-height: 1.6;
  box-shadow: 0 3px 10px rgba(33,43,37,.06);
}
.bubble.user { align-self: flex-end; background: #ccebcf; }
.bubble small { display: block; margin-top: 7px; color: var(--muted); font-size: 10px; }
.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  background: white;
  border-top: 1px solid var(--line);
}
.chat-compose input {
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #fafaf7;
}

.approval-card { border-left: 4px solid var(--amber); }
.approval-card dl {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  margin: 0 0 20px;
  font-size: 12px;
}
.approval-card dt { color: var(--muted); }
.approval-card dd { margin: 0; font-weight: 650; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); }
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f7f7f3; color: var(--muted); font-size: 10px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.hours { font-variant-numeric: tabular-nums; font-weight: 800; }
.description-warning { color: var(--red); font-weight: 700; }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.summary-strip > div { padding: 17px 18px; border-right: 1px solid var(--line); }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip span, .invoice-total span { display: block; color: var(--muted); font-size: 11px; }
.summary-strip strong { display: block; margin-top: 5px; font-size: 21px; }

.invoice {
  padding: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.invoice-top {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}
.invoice-top h2 { margin: 4px 0 5px; font-size: 17px; }
.invoice-total { text-align: right; }
.invoice-total strong { display: block; margin-top: 4px; font-size: 25px; }
.invoice-lines { display: grid; gap: 8px; }
.invoice-line {
  display: grid;
  grid-template-columns: 90px 1fr 90px 110px;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #eceee9;
  font-size: 12px;
}
.invoice-line span:last-child { text-align: right; font-weight: 700; }
.invoice-warning { margin-top: 16px; padding: 12px; background: var(--amber-soft); color: #72501e; font-size: 12px; }
.invoice-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; }

.empty { padding: 50px 20px; color: var(--muted); text-align: center; }
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  max-width: 360px;
  padding: 13px 17px;
  background: #18211d;
  color: white;
  font-size: 12px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-shell { display: block; min-height: 100vh; padding-top: 64px; }
  .topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    height: 64px;
    padding: 0 16px;
  }
  .sidebar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 4;
    height: 62px;
    padding: 6px 8px;
    border-top: 1px solid #374139;
  }
  .sidebar nav { height: 100%; grid-template-columns: repeat(5, 1fr); gap: 2px; }
  .nav-item { height: 50px; grid-template: 22px 15px / 1fr; gap: 0; padding: 3px; text-align: center; font-size: 9px; }
  .nav-item .nav-icon { font-size: 17px; }
  .nav-item b, .principle { display: none; }
  main { padding: 22px 16px 92px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .workflow { grid-template-columns: 1fr; }
  .flow-step { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .flow-step:last-child { border-bottom: 0; }
  .flow-step::after { display: none !important; }
  .split-layout { grid-template-columns: 1fr; }
  .radar-row { grid-template-columns: 7px 1fr; }
  .radar-summary, .row-actions { grid-column: 2; text-align: left; }
}

@media (max-width: 560px) {
  .brand span, .status-dot { display: none; }
  .page-head { align-items: flex-start; }
  .date-block { display: none; }
  .metric { min-height: 100px; padding: 16px; }
  .metric strong { font-size: 24px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .segmented { display: grid; grid-template-columns: repeat(3, 1fr); }
  .summary-strip { grid-template-columns: 1fr; }
  .summary-strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .summary-strip > div:last-child { border-bottom: 0; }
  .invoice-top, .invoice-footer { align-items: flex-start; flex-direction: column; }
  .invoice-total { text-align: left; }
  .invoice-line { grid-template-columns: 75px 1fr; }
  .invoice-line span:nth-child(3), .invoice-line span:nth-child(4) { text-align: left; }
}
