:root {
  --bg0: #091321;
  --bg1: #0d1929;
  --bg2: #13243a;
  --panel: #101e30;
  --panel-strong: #17283c;
  --line: rgba(148, 163, 184, 0.16);
  --text: #edf3fa;
  --muted: #a8b6c9;
  --brand: #14b8a6;
  --brand-2: #38bdf8;
  --gold: #f5c451;
  --danger: #fb7185;
  --ok: #34d399;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(145deg, #0a1422, #101e2f 58%, #0c1827);
  overflow: hidden;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(7, 17, 31, 0.55);
  color: var(--text);
  border-radius: 9px;
  padding: 10px 12px;
  min-height: 42px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #93a4bd 50%),
    linear-gradient(135deg, #93a4bd 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
select option { background: #0f233b; color: #edf3fa; }
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  border-color: rgba(20, 184, 166, 0.7);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
  background: rgba(7, 17, 31, 0.8);
}
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #55d6c5;
  outline-offset: 2px;
}
::selection { background: rgba(20, 184, 166, 0.35); color: #f8fffe; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.3); border: 2px solid transparent; border-radius: 999px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(148, 163, 184, 0.48); }
::-webkit-scrollbar-track { background: transparent; }
input[type="search"] { padding-left: 14px; }
input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
input[type="checkbox"] { width: auto; margin-right: 8px; accent-color: var(--brand); }

/* 登录 */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 10% 0%, rgba(20, 184, 166, 0.2), transparent 55%),
    radial-gradient(800px 480px at 90% 100%, rgba(56, 189, 248, 0.16), transparent 50%),
    linear-gradient(160deg, #07111f, #0b1a2e);
}
.auth-card {
  width: min(420px, 100%);
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16, 35, 59, 0.95), rgba(11, 24, 43, 0.98));
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.auth-tab {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px;
  font-weight: 650;
}
.auth-tab.active {
  color: #042f2e;
  background: linear-gradient(135deg, #0d9488, #14b8a6 55%, #38bdf8);
  border-color: transparent;
}
.auth-form { display: grid; gap: 12px; }
.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: #c8d4e3;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.remember-row input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
}
.auth-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.filter-row select { font-size: 13px; padding: 9px 28px 9px 12px; }

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

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  background: rgba(20, 184, 166, 0.15);
  color: #99f6e4;
}
.tag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.history-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  background: color-mix(in srgb, var(--tag, #14b8a6) 22%, transparent);
  color: var(--tag, #99f6e4);
  border: 1px solid color-mix(in srgb, var(--tag, #14b8a6) 35%, transparent);
}
.tag.muted {
  --tag: #94a3b8;
  color: #cbd5e1;
}
.manage-item .title .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 4px;
}
.quote-table tfoot .foot-row td {
  background: rgba(15, 23, 42, 0.45);
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}
.quote-table tfoot .foot-label {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}
.quote-table tfoot .foot-value {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.quote-table tfoot .foot-row.total .foot-value {
  color: var(--gold);
  font-size: 16px;
}
.quote-table td.line-total,
.quote-table td.seq {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.quote-table td.line-total {
  color: var(--text);
  font-weight: 650;
}

/* 分类行居中 */
.category-row td { text-align: center; }
.category-row .cat-cell { width: 100%; }
.category-row input[data-field="category"] {
  text-align: center;
  font-weight: 700;
  color: #99f6e4;
  border-color: rgba(20, 184, 166, 0.25);
  letter-spacing: 0.06em;
}

.quote-table th { text-align: center; }
.quote-table td.ops-cell { width: 132px; }
.ops { display: flex; gap: 4px; justify-content: center; flex-wrap: nowrap; }
.mini-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 8px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
}
.mini-btn:hover { color: #fff; border-color: rgba(255,255,255,0.25); }
.mini-btn.danger:hover { color: var(--danger); border-color: rgba(251, 113, 133, 0.4); }
.mini-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.unit-cell { position: relative; }
.unit-cell input { padding-right: 8px; }
datalist { display: none; }

/* 工作区管理弹窗 */
.modal-manage {
  width: min(920px, 100%);
  max-height: min(90vh, 860px);
  overflow: auto;
}
.manage-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.manage-tab {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
}
.manage-tab.active {
  color: #ecfeff;
  border-color: rgba(20, 184, 166, 0.5);
  background: rgba(20, 184, 166, 0.18);
}
.manage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.manage-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}
.manage-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
}
.manage-item .title { font-weight: 650; }
.manage-item .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.manage-item .actions { display: flex; gap: 6px; }
.manage-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.check-field span { display: flex; align-items: center; color: var(--text); font-size: 13px; }
.code-area {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
}
.format-field-editor {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.025);
}
.format-field-head,
.format-template-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.format-field-head > div { display: grid; gap: 3px; }
.format-field-head strong { font-size: 14px; }
.format-template-bar {
  justify-content: flex-start;
  margin: 12px 0;
  color: var(--muted);
  font-size: 12px;
}
.template-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(20,184,166,0.08);
  color: var(--text);
  font-size: 12px;
}
.template-chip:hover { border-color: var(--brand); color: #99f6e4; }
.btn-small { padding: 7px 10px; font-size: 12px; }
.format-fields-header,
.format-field-row {
  display: grid;
  grid-template-columns: 64px minmax(110px, 1fr) 120px 92px minmax(120px, 1.1fr) 52px 34px;
  gap: 8px;
  align-items: center;
}
.format-fields-header {
  padding: 0 8px 6px;
  color: var(--muted);
  font-size: 11px;
}
.format-field-row {
  padding: 9px 8px;
  border-top: 1px solid var(--line);
}
.format-field-row input,
.format-field-row select { min-width: 0; width: 100%; }
.field-order-actions { display: flex; gap: 4px; }
.field-order-actions button,
.remove-format-field {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: var(--muted);
}
.field-order-actions button:hover { color: var(--text); border-color: var(--brand); }
.remove-format-field:hover { color: var(--danger); border-color: var(--danger); }
.required-toggle { display: flex; justify-content: center; }
.required-toggle input { width: auto; }
.format-field-tip { margin: 9px 4px 0; }
.format-sample {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.format-sample-title { margin-bottom: 8px; font-size: 12px; font-weight: 650; color: var(--text); }
.format-sample-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.format-sample table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 11px; }
.format-sample th { background: rgba(20,184,166,0.18); color: #ccfbf1; font-weight: 650; }
.format-sample th, .format-sample td { padding: 7px 8px; text-align: center; border-right: 1px solid var(--line); }
.format-sample th:last-child, .format-sample td:last-child { border-right: 0; }
.format-sample td { color: var(--muted); border-top: 1px solid var(--line); white-space: nowrap; }
.required-mark { color: var(--danger); }
.inline-add {
  display: flex;
  gap: 8px;
  width: min(420px, 100%);
}
.chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: none;
}
.unit-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  font-size: 13px;
}
.unit-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
}
.unit-chip button:hover { color: var(--danger); background: rgba(251,113,133,0.12); }
.badge-default {
  margin-left: 8px;
  font-size: 11px;
  color: #fde68a;
  border: 1px solid rgba(245, 196, 81, 0.35);
  border-radius: 999px;
  padding: 1px 8px;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(12, 24, 42, 0.92), rgba(8, 16, 30, 0.96));
  backdrop-filter: blur(18px);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 6px 14px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #042f2e;
  background: linear-gradient(135deg, var(--brand), #5eead4 55%, var(--gold));
  box-shadow: 0 10px 30px rgba(20, 184, 166, 0.35);
}
.brand-name {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: 0.02em;
}
.brand-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text);
  background: transparent;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, #0d9488, #14b8a6 45%, #38bdf8);
  color: #042f2e;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(20, 184, 166, 0.28);
}
.btn-soft {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}
.btn-soft:hover { background: rgba(255, 255, 255, 0.09); }
.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.btn-danger-soft {
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.28);
  color: #fecdd3;
}
.icon { font-weight: 700; margin-right: 4px; }

.search-box input {
  background: rgba(255, 255, 255, 0.03);
}

.side-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 4px 0;
}
.chip {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  padding: 0 7px;
  background: rgba(20, 184, 166, 0.15);
  color: #99f6e4;
  font-size: 11px;
}

.history-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
  min-height: 0;
}
.history-list::-webkit-scrollbar,
.main::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.history-list::-webkit-scrollbar-thumb,
.main::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 999px;
}

.history-item {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  transition: background .2s, border-color .2s, transform .15s;
}
.history-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(56, 189, 248, 0.2);
}
.history-item.active {
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.16), rgba(56, 189, 248, 0.1));
  border-color: rgba(20, 184, 166, 0.45);
  box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.15);
}
.history-main { cursor: pointer; min-width: 0; }
.history-title {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.history-money {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 12px;
}
.history-del {
  border: none;
  background: transparent;
  color: #94a3b8;
  border-radius: 8px;
  width: 36px;
  height: 36px;
}
.history-del:hover { color: var(--danger); background: rgba(251, 113, 133, 0.12); }

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 10px;
}
.stat-mini {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 0 4px;
}

.main {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 22px 24px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.eyebrow {
  color: #7dd3fc;
  letter-spacing: 0.18em;
  font-size: 11px;
  font-weight: 700;
}
.topbar h1 {
  margin: 6px 0 0;
  font-size: 28px;
  font-weight: 750;
  letter-spacing: 0.01em;
}
.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.welcome { display: grid; place-items: center; min-height: calc(100% - 80px); }
.hero-card {
  position: relative;
  width: min(920px, 100%);
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background:
    linear-gradient(145deg, rgba(15, 35, 58, 0.9), rgba(8, 18, 34, 0.92));
  box-shadow: var(--shadow);
}
.hero-glow {
  position: absolute;
  inset: auto -20% -40% 20%;
  height: 60%;
  background: radial-gradient(circle, rgba(20, 184, 166, 0.28), transparent 60%);
  filter: blur(10px);
}
.hero-content {
  position: relative;
  padding: 48px 48px 42px;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(245, 196, 81, 0.35);
  color: #fde68a;
  background: rgba(245, 196, 81, 0.08);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hero-content h2 {
  margin: 18px 0 12px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
  max-width: 16ch;
}
.hero-content p {
  margin: 0;
  color: var(--muted);
  max-width: 56ch;
  line-height: 1.7;
  font-size: 15px;
}
.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 28px 0 24px;
}
.metric {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.03);
}
.metric strong {
  display: block;
  font-size: 22px;
  margin-bottom: 4px;
  color: #f8fafc;
}
.metric span { color: var(--muted); font-size: 12px; }

.editor {
  display: grid;
  gap: 16px;
}
.panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.025));
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.04em;
}
.hint { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid-4, .grid-2 {
  display: grid;
  gap: 12px;
}
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}
.field.full { grid-column: 1 / -1; }
.field span { padding-left: 2px; }

.two-col {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
}
.quote-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  background: rgba(7, 17, 31, 0.35);
}
.quote-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(180deg, #123047, #0e2740);
  color: #cde7ff;
  font-size: 12px;
  font-weight: 650;
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.quote-table td {
  padding: 8px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  vertical-align: middle;
}
.quote-table tbody tr:hover td { background: rgba(56, 189, 248, 0.04); }
.quote-table input {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.quote-table .seq {
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.quote-table .money,
.quote-table .line-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: #f8fafc;
  padding-right: 12px;
}
.quote-table tfoot td {
  background: rgba(15, 23, 42, 0.55);
  border-bottom: none;
  padding: 12px 10px;
}
.tfoot-label {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}
.total-row td {
  border-top: 1px solid rgba(20, 184, 166, 0.35);
}
.total-row .money {
  color: var(--gold);
  font-size: 18px;
}

.category-row td {
  background: linear-gradient(90deg, rgba(20, 184, 166, 0.14), rgba(56, 189, 248, 0.05));
}
.category-row input {
  font-weight: 700;
  color: #99f6e4;
  border-color: rgba(20, 184, 166, 0.25);
}
.ops {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.mini-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
}
.mini-btn:hover { color: #fff; border-color: rgba(255,255,255,0.25); }
.mini-btn.danger:hover { color: var(--danger); border-color: rgba(251, 113, 133, 0.4); }

.notes {
  display: grid;
  gap: 8px;
}
.note-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  min-width: 220px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(52, 211, 153, 0.35);
  background: rgba(6, 28, 24, 0.92);
  color: #d1fae5;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.toast.error {
  border-color: rgba(251, 113, 133, 0.4);
  background: rgba(50, 12, 24, 0.92);
  color: #ffe4e6;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 14, 0.62);
  backdrop-filter: blur(8px);
}
.modal[hidden], [hidden] { display: none !important; }
.modal-card {
  width: min(640px, 100%);
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #10233b, #0b182b);
  box-shadow: var(--shadow);
  padding: 18px;
}
.modal-wide {
  width: min(980px, 100%);
  height: min(88vh, 920px);
  display: flex;
  flex-direction: column;
}
.modal-card[role="dialog"] { overflow: auto; }
.modal-manage { width: min(1180px, 100%); }
.modal-manage .manage-pane { min-height: 0; overflow: auto; padding-right: 3px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-head h3 { margin: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 18px;
}
#previewFrame {
  flex: 1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.empty-history {
  color: var(--muted);
  font-size: 13px;
  padding: 18px 8px;
  text-align: center;
  line-height: 1.6;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 280px 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .hero-content { padding: 32px 28px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100%;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .history-list { max-height: 240px; }
  .topbar { flex-direction: column; }
  .hero-metrics { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .format-fields-header { display: none; }
  .format-field-row {
    grid-template-columns: 58px 1fr 1fr;
    align-items: end;
  }
  .format-field-row .field-placeholder { grid-column: 2 / 4; }
}

/* UI refinement: quieter workbench, clearer task hierarchy, safer intermediate widths. */
.auth-screen {
  background: #091321;
}
.auth-card {
  border-radius: 16px;
  background: #101e30;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
}
.brand-mark {
  background: #2dd4bf;
  box-shadow: 0 8px 22px rgba(20, 184, 166, 0.22);
}
.btn {
  min-height: 40px;
  border-radius: 10px;
  transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
}
.btn:hover { transform: none; }
.btn-primary {
  background: #19b7a5;
  color: #062c2a;
  box-shadow: 0 8px 18px rgba(20, 184, 166, 0.2);
}
.btn-primary:hover { background: #2dd4bf; box-shadow: 0 10px 22px rgba(20, 184, 166, 0.26); }
.btn-soft { background: #17283c; border-color: #2a4059; }
.btn-soft:hover { background: #1d334b; border-color: #3e5b78; }
.btn-ghost { background: transparent; border-color: #263b54; }
.btn-ghost:hover { background: #14263a; border-color: #3a5874; color: var(--text); }
.btn-danger-soft { background: rgba(251, 113, 133, 0.1); border-color: rgba(251, 113, 133, 0.28); }

.app-shell { grid-template-columns: minmax(248px, 280px) minmax(0, 1fr); }
.sidebar {
  padding: 18px 14px;
  gap: 12px;
  background: #0d1a2a;
  backdrop-filter: none;
}
.brand-block { padding: 4px 5px 10px; }
.brand-name { font-size: 17px; }
.sidebar .btn-primary { min-height: 46px; }
.search-box input, .filter-row select { background: #101f32; border-color: #263b54; }
.history-list { gap: 6px; }
.history-item { border-radius: 11px; padding: 11px; background: #102034; }
.history-item:hover { background: #172b42; border-color: #31506d; }
.history-item.active { background: #143247; border-color: rgba(45, 212, 191, 0.52); box-shadow: inset 3px 0 0 #2dd4bf; }
.sidebar-footer { gap: 8px; border-top-color: #22374e; }

.main { padding: 24px 28px 42px; }
.topbar { align-items: center; margin-bottom: 20px; }
.topbar-copy { min-width: 0; flex: 1 1 auto; }
.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 2.5vw, 32px);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions { max-width: 62%; min-width: 0; }

.welcome { min-height: 0; place-items: stretch; padding: 8px 0 20px; }
.welcome-grid {
  width: min(980px, 100%);
  margin: auto;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, .88fr);
  gap: 16px;
  align-items: stretch;
}
.welcome-card {
  border: 1px solid #263d56;
  border-radius: 14px;
  background: #101f32;
  box-shadow: none;
}
.welcome-primary { padding: 36px; display: flex; flex-direction: column; justify-content: center; min-height: 340px; }
.welcome-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 11px;
  color: #062c2a;
  background: #2dd4bf;
  font-size: 24px;
  font-weight: 700;
}
.welcome-primary h2 { max-width: 13ch; margin: 0 0 14px; font-size: clamp(30px, 4vw, 42px); line-height: 1.12; letter-spacing: -.025em; }
.welcome-primary p { max-width: 42ch; margin: 0; color: #afbdd0; line-height: 1.7; }
.welcome-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 28px; }
.welcome-note { color: var(--muted); font-size: 12px; }
.welcome-summary { padding: 24px; display: flex; flex-direction: column; justify-content: space-between; }
.summary-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid #263d56; }
.summary-heading h3 { margin: 0; font-size: 16px; }
.summary-heading span { color: var(--muted); font-size: 12px; }
.hero-metrics { grid-template-columns: 1fr; gap: 10px; margin: 18px 0; }
.metric { border: 1px solid #29415b; border-radius: 10px; padding: 14px 15px; background: #14273c; }
.metric strong { font-size: 21px; }
.summary-foot { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.editor { gap: 14px; min-width: 0; }
.panel { padding: 18px; border-radius: 14px; background: #101f32; border-color: #263d56; box-shadow: none; min-width: 0; }
.panel-head { margin-bottom: 16px; }
.panel-head h3 { font-size: 16px; letter-spacing: 0; }
.hint { color: #a8b6c9; }
.field { color: #b7c4d4; }
.two-col { grid-template-columns: minmax(0, 1.18fr) minmax(280px, .82fr); gap: 14px; min-width: 0; }
.table-wrap { max-width: 100%; border-color: #29415b; background: #0d1b2c; }
.quote-table { min-width: 900px; background: #0d1b2c; }
.quote-table th { background: #17344d; color: #dbeafe; padding: 11px 10px; }
.quote-table td { padding: 9px 8px; }
.quote-table tbody tr:hover td { background: rgba(56, 189, 248, 0.06); }
.quote-table input { background: #102238; border-color: #29415b; }
.quote-table tfoot td { background: #12253a; }
.quote-table tfoot .foot-row.total .foot-value { color: #f7d774; }

.modal { background: rgba(3, 10, 18, 0.78); backdrop-filter: blur(4px); }
.modal-card { border-radius: 16px; background: #112239; border-color: #2b435d; box-shadow: 0 24px 70px rgba(0, 0, 0, .42); }
.manage-tab { border-radius: 9px; padding: 9px 13px; }
.manage-tab.active { background: #174151; border-color: rgba(45, 212, 191, 0.58); }
.format-field-editor { background: #102238; border-color: #29415b; }
.format-field-row { border-top-color: #29415b; }
.format-sample-scroll { border-color: #29415b; }
.icon-btn { min-width: 36px; min-height: 36px; }
.toast { border-radius: 10px; backdrop-filter: none; background: #123a36; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 252px minmax(0, 1fr); }
  .main { padding-left: 20px; padding-right: 20px; }
}
@media (max-width: 1040px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 12px; }
  .top-actions { max-width: none; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .top-actions .btn { flex: 0 0 auto; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .app-shell { display: block; height: auto; min-height: 100%; }
  .sidebar { border-right: 0; border-bottom: 1px solid #22374e; }
  .history-list { max-height: 220px; }
  .main { overflow: visible; padding: 18px 16px 32px; }
  .welcome-grid { grid-template-columns: 1fr; }
  .welcome-primary { min-height: 260px; }
  .welcome-summary { min-height: 0; }
  .hero-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .topbar h1 { white-space: normal; overflow: visible; }
  .panel { padding: 14px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .welcome-primary { padding: 24px; }
  .welcome-summary { padding: 18px; }
  .hero-metrics { grid-template-columns: 1fr; }
  .welcome-primary h2 { font-size: 30px; }
  .modal { padding: 10px; }
  .modal-wide { width: 100%; height: calc(100vh - 20px); max-height: none; }
  .modal-card { padding: 14px; }
  .history-del { width: 44px; height: 44px; }
  .mini-btn { min-width: 40px; min-height: 40px; }
  .field-order-actions button, .remove-format-field { width: 38px; height: 38px; }
  .template-chip { min-height: 44px; padding-inline: 12px; }
}

/* Mobile browser pass: safe areas, thumb-friendly controls, and contained horizontal scrolling. */
.format-sample-scroll {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
}
@media (max-width: 860px) {
  body {
    min-width: 320px;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .auth-screen {
    overflow-y: auto;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .auth-card { margin: auto; }
  .sidebar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .main { padding-bottom: max(32px, env(safe-area-inset-bottom)); }
  .top-actions,
  .manage-tabs {
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .top-actions::-webkit-scrollbar,
  .manage-tabs::-webkit-scrollbar { display: none; }
  .manage-tabs { flex-wrap: nowrap; overflow-x: auto; touch-action: pan-x pan-y; padding-bottom: 2px; }
  .manage-tab { flex: 0 0 auto; min-height: 44px; }
  .modal { padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .modal-card { max-height: 100%; }
  .modal-wide { height: min(92dvh, 920px); }
  .modal-manage .manage-pane { overflow: visible; }
}
@media (max-width: 560px) {
  .auth-screen { place-items: start center; }
  .auth-card {
    width: 100%;
    margin-top: max(8px, env(safe-area-inset-top));
    padding: 22px 18px 18px;
    border-radius: 14px;
  }
  .auth-brand { margin-bottom: 18px; }
  .auth-tab,
  .remember-row { min-height: 44px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  .btn { min-height: 44px; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .panel-head > .btn { align-self: flex-start; }
  .modal-head { align-items: flex-start; }
  .modal-head .row-actions { width: auto; }
  .modal-head .row-actions .btn { flex: 0 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
