/* Unified visual themes. Presentation only; business behavior remains unchanged. */
:root[data-ui-theme="brand"] {
  color-scheme: light;
  --bg: #f4f4f2;
  --panel: #ffffff;
  --line: #ded8d0;
  --line-soft: #ece8e2;
  --text: #2b2824;
  --muted: #746d64;
  --brand: #9a6737;
  --primary: #9a6737;
  --brand-dark: #79502d;
  --brand-soft: #f3e9dc;
  --focus: 0 0 0 3px rgba(154, 103, 55, 0.16);
  --ui-page: #f4f4f2;
  --ui-page-rgb: 244, 244, 242;
  --ui-panel: #ffffff;
  --ui-panel-rgb: 255, 255, 255;
  --ui-panel-soft: #faf9f7;
  --ui-panel-glass: rgba(255, 255, 255, 0.94);
  --ui-chrome-glass: rgba(252, 250, 247, 0.95);
  --ui-title: #342e28;
  --ui-label: #665e55;
  --ui-border: #ded8d0;
  --ui-border-strong: #cec3b6;
  --ui-table-head: #f3f0ec;
  --ui-row-alt: #fbfaf8;
  --ui-row-hover: #f7efe5;
  --ui-row-selected: #f3e9dc;
  --ui-result-border: #d4b388;
  --ui-result-bg: #fdf9f4;
  --ui-result-value: #805129;
  --ui-accent-line: #dcc29f;
  --ui-sidebar: #fbfaf7;
  --ui-sidebar-border: #e5ddd2;
  --ui-sidebar-text: #40382f;
  --ui-sidebar-hover: #f3ece2;
  --ui-sidebar-active: #ead8bd;
  --ui-sidebar-active-border: #ddc39e;
  --ui-sidebar-accent: #a46f3d;
  --ui-shadow-tint: rgba(65, 49, 32, 0.1);
}

:root[data-ui-theme="blue"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #d9e0e9;
  --line-soft: #e9edf3;
  --text: #182230;
  --muted: #667085;
  --brand: #2563eb;
  --primary: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #edf4ff;
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.14);
  --ui-page: #f3f5f8;
  --ui-page-rgb: 243, 245, 248;
  --ui-panel: #ffffff;
  --ui-panel-rgb: 255, 255, 255;
  --ui-panel-soft: #f8fafc;
  --ui-panel-glass: rgba(255, 255, 255, 0.94);
  --ui-chrome-glass: rgba(255, 255, 255, 0.95);
  --ui-title: #162033;
  --ui-label: #536176;
  --ui-border: #d9e0e9;
  --ui-border-strong: #c9d4e2;
  --ui-table-head: #f6f8fb;
  --ui-row-alt: #fbfcfe;
  --ui-row-hover: #f3f7fd;
  --ui-row-selected: #edf4ff;
  --ui-result-border: #b9cdf8;
  --ui-result-bg: #f8fbff;
  --ui-result-value: #1849a9;
  --ui-accent-line: #d8e5fb;
  --ui-sidebar: #ffffff;
  --ui-sidebar-border: #dfe5ed;
  --ui-sidebar-text: #344054;
  --ui-sidebar-hover: #f6f8fb;
  --ui-sidebar-active: #edf4ff;
  --ui-sidebar-active-border: #d7e5ff;
  --ui-sidebar-accent: #2563eb;
  --ui-shadow-tint: rgba(16, 24, 40, 0.1);
}

html,
body { background-color: var(--ui-page); }

body {
  color: var(--text);
  transition: background-color 0.18s ease, color 0.18s ease;
}

body.has-custom-background {
  background-image:
    linear-gradient(
      rgba(var(--ui-page-rgb), var(--custom-background-overlay-opacity, 0.58)),
      rgba(var(--ui-page-rgb), var(--custom-background-overlay-opacity, 0.58))
    ),
    var(--custom-background-image);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}

.app,
.main { background: var(--ui-page); }
body.has-custom-background .app,
body.has-custom-background .main { background: transparent; }

body::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: var(--ui-border-strong);
  background-clip: padding-box;
}

/* Navigation and global chrome. */
.sidebar {
  background: var(--ui-sidebar);
  border-right-color: var(--ui-sidebar-border);
  box-shadow: 1px 0 0 var(--ui-shadow-tint);
}
.logo { border-bottom-color: var(--ui-sidebar-border); color: var(--ui-title); }
.brand-caption { color: var(--muted); }
.menu-item { color: var(--ui-sidebar-text); }
.menu-item:hover {
  background: var(--ui-sidebar-hover);
  border-color: var(--ui-sidebar-active-border);
  color: var(--brand-dark);
}
.menu-item.active {
  background: var(--ui-sidebar-active);
  border-color: var(--ui-sidebar-active-border);
  color: var(--ui-title);
}
.menu-item.active::after { background: var(--ui-sidebar-accent); }
.flyout {
  background: var(--ui-panel);
  border-color: var(--ui-border);
  box-shadow: 0 14px 34px var(--ui-shadow-tint);
}
.flyout button { color: var(--ui-sidebar-text); }
.flyout button:hover { background: var(--brand-soft); color: var(--brand-dark); }

.topbar {
  background: var(--ui-panel);
  border-bottom-color: var(--ui-border);
  box-shadow: 0 1px 2px var(--ui-shadow-tint);
}
.title { color: var(--ui-title); }
.user-pill {
  border-color: var(--ui-border);
  background: var(--ui-panel-soft);
  color: var(--ui-sidebar-text);
}
body.has-custom-background .sidebar,
body.has-custom-background .topbar {
  background: rgba(var(--ui-panel-rgb), var(--custom-chrome-opacity, 0.94));
  backdrop-filter: blur(12px);
}
.site-footer { color: var(--muted); }

/* Compact personalisation controls. */
.theme-toolbar {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px;
  border: 1px solid var(--ui-border);
  border-radius: 7px;
  background: var(--ui-panel-soft);
}
.theme-toolbar::before {
  content: "主题";
  padding-left: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.theme-switcher { display: inline-flex; align-items: center; gap: 2px; }
.theme-choice {
  min-width: 55px;
  height: 27px;
  padding: 3px 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.theme-choice:hover { background: var(--ui-panel); color: var(--text); }
.theme-choice.active {
  border-color: var(--ui-border);
  background: var(--ui-panel);
  color: var(--text);
  box-shadow: 0 1px 3px var(--ui-shadow-tint);
}
.theme-swatch {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
}
.theme-swatch-brand { background: #a46f3d; }
.theme-swatch-blue { background: #2563eb; }
.theme-file-input { display: none; }
.theme-background-btn {
  min-height: 27px !important;
  padding: 3px 7px !important;
  border-color: transparent !important;
  background: transparent !important;
  color: var(--muted) !important;
}
.theme-background-btn:hover { background: var(--ui-panel) !important; color: var(--text) !important; }
.background-settings-panel {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 230;
  width: 280px;
  padding: 12px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  background: var(--ui-panel);
  box-shadow: 0 16px 38px var(--ui-shadow-tint);
}
.background-settings-panel[hidden] { display: none; }
.background-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--ui-title);
}
.background-settings-head .icon-btn {
  width: 27px;
  height: 27px;
  min-height: 27px;
}
.background-upload-btn { width: 100%; }
.background-empty-hint {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}
.background-empty-hint[hidden],
.background-opacity-control[hidden],
.background-remove-btn[hidden] { display: none; }
.background-opacity-control {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line-soft);
}
.background-opacity-block + .background-opacity-block {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line-soft);
}
.background-opacity-label,
.background-opacity-scale {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.background-opacity-label label { color: var(--ui-label); font-size: 12px; font-weight: 700; }
.background-opacity-label output { color: var(--brand-dark); font-size: 12px; font-weight: 800; }
.background-opacity-control input[type="range"] {
  width: 100%;
  height: 22px;
  margin: 5px 0 0;
  padding: 0;
  accent-color: var(--brand);
}
.background-opacity-scale { color: var(--muted); font-size: 11px; }
.background-remove-btn { width: 100%; margin-top: 12px; }
body.has-custom-background .background-settings-panel {
  background: rgba(var(--ui-panel-rgb), 0.97);
  backdrop-filter: blur(12px);
}

/* Cards, quote workspace and information hierarchy. */
.card,
.table-wrap,
.mini-table,
.pre,
.order-copy-group,
.logistics-artwork-preview {
  border-color: var(--ui-border);
  background: var(--ui-panel);
}
body.has-custom-background .card,
body.has-custom-background .table-wrap {
  background: rgba(var(--ui-panel-rgb), var(--custom-module-opacity, 0.92));
  backdrop-filter: blur(8px);
}
body.has-custom-background .card .table-wrap {
  background: transparent;
  backdrop-filter: none;
}
.card { box-shadow: 0 1px 3px var(--ui-shadow-tint); }
.card h3 {
  border-bottom-color: var(--line-soft);
  color: var(--ui-title);
}
.quote-result-card {
  border-color: var(--ui-result-border);
  background: var(--ui-panel);
  box-shadow: 0 7px 20px color-mix(in srgb, var(--brand) 13%, transparent);
}
.quote-result-card h3 { color: var(--brand-dark); border-bottom-color: var(--ui-accent-line); }
.quote-details-card,
.quote-support-card { border-color: var(--ui-border); background: var(--ui-panel); }
.quote-result-column .summary-text {
  border-color: var(--ui-accent-line);
  background: var(--ui-result-bg);
}
.quote-result-column .metric {
  border-color: var(--ui-border);
  background: var(--ui-panel-soft);
}
.quote-result-column .metric .value,
.sales-analysis-metric .value { color: var(--ui-result-value); }
.customer-profile-strip { border-top-color: var(--line-soft); border-left-color: var(--ui-accent-line); }
.customer-profile-head,
.section-title { color: var(--ui-title); }
.section-title::before { background: var(--brand); }
.profile-row,
.param-section { border-color: var(--line-soft); }
.followup-operation-section,
.modal-section { border-color: var(--ui-border); background: var(--ui-panel-soft); }

/* Forms and buttons. */
.field label { color: var(--ui-label); }
.field input,
.field select,
.field textarea,
.followup-note-input,
.todo-followup-row input,
.todo-followup-row select,
.finance-handle-table input[type="text"],
.finance-handle-table input[type="date"],
.finance-handle-table input[type="number"],
.finance-design-plate-table input[type="text"],
.finance-design-plate-table input[type="number"],
.finance-design-plate-table select {
  border-color: var(--ui-border-strong);
  background: var(--ui-panel);
  color: var(--text);
}
.field input:hover,
.field select:hover,
.field textarea:hover { border-color: var(--brand); }
.field input:focus,
.field select:focus,
.field textarea:focus,
.followup-note-input:focus {
  border-color: var(--brand);
  box-shadow: var(--focus);
  outline: 0;
}
.field input[readonly] { background: var(--ui-panel-soft); color: var(--muted); }
input[type="checkbox"],
input[type="radio"],
.finance-handle-check input,
.finance-design-plate-check input { accent-color: var(--brand); }
.btn {
  border-color: var(--ui-border-strong);
  background: var(--ui-panel);
  color: var(--ui-sidebar-text);
}
.btn:hover { border-color: var(--brand); background: var(--ui-panel-soft); }
.btn.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.btn.primary:hover { border-color: var(--brand-dark); background: var(--brand-dark); }
.icon-btn { border-color: var(--ui-border-strong); background: var(--ui-panel); color: var(--ui-sidebar-text); }
.icon-btn:hover { border-color: var(--brand); background: var(--ui-panel-soft); color: var(--brand-dark); }
.todo-trigger { border-color: var(--ui-border); background: var(--ui-panel-soft); }

/* Operational tables and compact lists. */
.filter-row { border-bottom-color: var(--line-soft); }
th,
.mini-table th,
.followup-table th.group { background: var(--ui-table-head); color: var(--ui-label); }
th,
td { border-bottom-color: var(--line-soft); }
.data-table td { color: var(--ui-sidebar-text); }
.data-table tbody tr:nth-child(even) td,
.followup-table tbody tr:nth-child(even) td { background: var(--ui-row-alt); }
.data-table tbody tr:hover td,
.followup-table tbody tr:hover td { background: var(--ui-row-hover); }
.order-copy-group,
.pre,
.logistics-artwork-preview { background: var(--ui-panel-soft); }
.kv { border-bottom-color: var(--line-soft); }
.logistics-pickup-cell pre { color: var(--ui-sidebar-text); }
.repeat-order-note { color: #8a5b00; }

/* Drawers, dialogs and lightweight surfaces. */
.modal-backdrop { background: rgba(26, 23, 20, 0.46); }
.modal {
  border-color: var(--ui-border-strong);
  background: var(--ui-panel);
  box-shadow: 0 24px 64px var(--ui-shadow-tint);
}
.modal-header,
.modal-footer { border-color: var(--ui-border); background: var(--ui-panel-soft); }
.modal-title { color: var(--ui-title); }
.deal-options-row { background: var(--ui-panel-soft); }
.todo-drawer { border-left-color: var(--ui-border); background: var(--ui-page); }
.todo-drawer-header,
.todo-drawer-toolbar,
.todo-item { border-color: var(--ui-border); background: var(--ui-panel); }
.todo-group-title,
.todo-item-head strong,
.todo-empty strong { color: var(--ui-title); }
.todo-item { box-shadow: 0 2px 8px var(--ui-shadow-tint); }
.todo-followup-row select { color: var(--text); }
.toast { background: var(--ui-title); }

/* Sales and finance pages use the same surface language. */
.sales-analysis-metric,
.sales-old-customer-item,
.sales-monthly-item,
.finance-handle-summary > div,
.finance-design-plate-summary > div {
  border-color: var(--ui-border);
  background: var(--ui-panel-soft);
}
.sales-analysis-metric { box-shadow: 0 2px 8px var(--ui-shadow-tint); }
.sales-monthly-item .month { color: var(--brand-dark); }
.sales-monthly-item .summary { color: var(--ui-sidebar-text); }
.finance-handle-row.settled,
.finance-design-plate-row.settled { background: var(--ui-row-selected); }

/* The module slider affects content surfaces only; controls and dialogs stay solid. */
body.has-custom-background .mini-table,
body.has-custom-background .pre,
body.has-custom-background .order-copy-group,
body.has-custom-background .logistics-artwork-preview,
body.has-custom-background .quote-result-card,
body.has-custom-background .quote-details-card,
body.has-custom-background .quote-support-card,
body.has-custom-background .quote-result-column .summary-text,
body.has-custom-background .quote-result-column .metric,
body.has-custom-background .followup-operation-section,
body.has-custom-background .sales-analysis-metric,
body.has-custom-background .sales-old-customer-item,
body.has-custom-background .sales-monthly-item,
body.has-custom-background .finance-handle-summary > div,
body.has-custom-background .finance-design-plate-summary > div {
  background: rgba(var(--ui-panel-rgb), var(--custom-module-opacity, 0.92));
  backdrop-filter: blur(8px);
}
body.has-custom-background th,
body.has-custom-background .mini-table th,
body.has-custom-background .followup-table th.group {
  background: rgba(var(--ui-page-rgb), var(--custom-module-opacity, 0.92));
}
body.has-custom-background .data-table tbody tr:nth-child(even) td,
body.has-custom-background .followup-table tbody tr:nth-child(even) td {
  background: rgba(var(--ui-panel-rgb), var(--custom-module-soft-opacity, 0.74));
}
body.has-custom-background .data-table tbody tr:hover td,
body.has-custom-background .followup-table tbody tr:hover td {
  background: rgba(var(--ui-page-rgb), var(--custom-module-opacity, 0.92));
}

/* Login uses the same selected theme and optional personal background. */
.login-screen { background: var(--ui-page); }
body.has-custom-background .login-screen { background: transparent; }
.login-card {
  border-color: var(--ui-border);
  background: var(--ui-panel-glass);
  box-shadow: 0 16px 42px var(--ui-shadow-tint);
  backdrop-filter: blur(12px);
}
.login-card::before { background: var(--brand-soft); color: var(--brand-dark); }
.login-card h1 { color: var(--ui-title); }
.login-legal { color: var(--muted); }
.login-legal a:hover { color: var(--brand-dark); }

@media (max-width: 1500px) {
  .theme-choice { min-width: 30px; padding-inline: 6px; }
  .theme-choice > span:last-child { display: none; }
}

@media (max-width: 1120px) {
  .theme-toolbar { display: none; }
}
