:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1a1d24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f5fff;
  --brand-ink: #0a3fb3;
  --accent: #ff7a00;
  --danger: #d92d20;
  --ok: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "PingFang SC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* HEADER */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; }
.brand-name { font-weight: 700; }
.brand-sub { color: var(--muted); font-size: 12px; }

.header-actions { display: flex; gap: 8px; align-items: center; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font-weight: 500; font-size: 13px;
  cursor: pointer; transition: .12s; line-height: 1;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; text-decoration: none; }
.btn-ghost { background: #fff; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-icon { padding: 4px 8px; font-size: 12px; }

/* SHELL */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 110px); }
.sidebar {
  background: #fff; border-right: 1px solid var(--line);
  padding: 16px 10px; display: flex; flex-direction: column; justify-content: space-between;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: block; text-align: left; background: transparent; border: 0;
  padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--ink); font: inherit;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active { background: #e8efff; color: var(--brand-ink); font-weight: 600; }

.sidebar-foot { padding: 8px 12px; }
.privacy-pill { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; padding: 8px 10px; border-radius: 8px; font-size: 12px; }

.workspace { padding: 24px; max-width: 100%; overflow-x: auto; }

h1 { font-size: 22px; margin: 0 0 6px; }
h3 { font-size: 14px; margin: 22px 0 8px; color: #374151; text-transform: uppercase; letter-spacing: .05em; }

/* FORM */
.row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.field.grow { flex: 1 1 240px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: #fff; padding: 8px 10px;
  border-radius: 8px; font: inherit; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,95,255,.15); }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }

/* CARDS */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card-label { color: var(--muted); font-size: 12px; }
.card-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.dash-actions { display: flex; gap: 8px; }

/* DOC GRID */
.doc-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr); gap: 20px; align-items: flex-start; }
@media (max-width: 1100px) { .doc-grid { grid-template-columns: 1fr; } }
.doc-form { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.doc-preview { position: sticky; top: 70px; }

/* TABLES */
.items-table, .data-table { width: 100%; border-collapse: collapse; margin-top: 8px; background: #fff; }
.items-table th, .items-table td, .data-table th, .data-table td {
  border-bottom: 1px solid var(--line); padding: 8px; text-align: left; font-size: 13px;
  vertical-align: middle;
}
.items-table th, .data-table th { background: #f9fafb; color: #374151; font-weight: 600; font-size: 12px; }
.items-table input { width: 100%; border: 1px solid transparent; padding: 6px; border-radius: 6px; background: #fff; }
.items-table input:focus { border-color: var(--brand); }
.items-table input[type=number] { text-align: right; }
.items-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.items-actions select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); }

.totals-readout {
  display: flex; flex-direction: column; gap: 4px; max-width: 320px; margin-left: auto;
  padding: 10px 0; font-size: 13px;
}
.totals-readout > div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.totals-readout > div:last-child { border-bottom: 0; font-weight: 700; font-size: 15px; color: var(--brand-ink); }

/* PREVIEW SHEET */
.a4-sheet {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px; min-height: 1000px; font-size: 12px;
}

/* CALLOUT */
.callout { background: #f0f7ff; border: 1px solid #c8def9; border-radius: var(--radius); padding: 14px 16px; margin-top: 18px; }
.callout h4 { margin: 0 0 6px; }

/* FOOTER */
.app-foot { text-align: center; padding: 14px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); background: #fff; }

/* HELP PAGE */
.help-page { max-width: 800px; margin: 30px auto; padding: 0 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.help-page article { padding: 24px 30px; }
.help-page h1 { font-size: 24px; margin-top: 18px; }
.help-page h2 { font-size: 17px; margin-top: 24px; color: #111827; }
.help-page hr { border: 0; border-top: 1px solid var(--line); margin: 30px 0; }

/* PRINT-ONLY */
.print-only { display: none; }
