/* ==========================================================================
   Design tokens — original blue/white palette, new layout system
   ========================================================================== */
:root {
    --primary-color: #1a73e8;
    --primary-hover: #1557b0;
    --primary-soft: rgba(26, 115, 232, 0.08);
    --primary-soft-strong: rgba(26, 115, 232, 0.14);
    --surface-color: #ffffff;
    --background-color: #f8f9fa;
    --surface-muted: #f1f3f4;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --text-tertiary: #80868b;
    --border-color: #dadce0;
    --border-subtle: #e8eaed;
    --error-color: #d93025;
    --error-soft: rgba(217, 48, 37, 0.08);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.06);
    --shadow-md: 0 1px 3px rgba(60, 64, 67, 0.08), 0 4px 12px rgba(60, 64, 67, 0.06);

    --gutter: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

[hidden] {
    display: none !important;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
    font-size: 14px;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* Icons */
.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-lg {
    width: 22px;
    height: 22px;
}

.zh {
    color: var(--text-tertiary);
    font-weight: 400;
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-subtle);
}

.topbar-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 10px var(--gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand img {
    display: block;
    height: 44px;
    width: auto;
}

.topbar-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-weight: 500;
    background: var(--surface-color);
    white-space: nowrap;
}

/* ==========================================================================
   Page shell
   ========================================================================== */
.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 var(--gutter) 48px;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 20px 0;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.page-title .icon {
    color: var(--text-secondary);
}

.page-title h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.page-title p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Segmented view switcher (tabs) */
.segmented {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}

.segmented::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 7px 14px;
    font: inherit;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}

.tab-btn .zh {
    font-size: 12px;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--surface-muted);
}

.tab-btn.active {
    background-color: var(--primary-color);
    color: #fff;
}

.tab-btn.active .zh {
    color: rgba(255, 255, 255, 0.75);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Layout helpers */
.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.layout-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 16px;
    align-items: start;
}

.rail {
    position: sticky;
    top: 88px;
}

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.card-title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.card-title h2 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.card-meta {
    font-size: 13px;
    color: var(--text-secondary);
}

.card-icon {
    color: var(--text-tertiary);
    width: 18px;
    height: 18px;
}

.card-body {
    padding: 20px;
}

.card-foot {
    display: flex;
    flex-wrap: wrap;   /* narrow cards (e.g. Settings at 2 columns): buttons move to a new line instead of overflowing */
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--background-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Small uppercase section labels */
.section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.section-label .zh {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px 20px;
}

.form-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.tight {
    gap: 10px 12px;
}

.form-group {
    min-width: 0;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

label .zh,
.field-label .zh {
    font-size: 12px;
}

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.section-label.group-gap {
    margin-top: 24px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    font: inherit;
    color: var(--text-primary);
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color 0.15s, box-shadow 0.15s;
}

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235f6368' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    text-overflow: ellipsis;
    cursor: pointer;
}

input:hover,
select:hover {
    border-color: #bdc1c6;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft-strong);
}

input[readonly] {
    background-color: var(--surface-muted);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.select-compact {
    width: auto;
    min-width: 220px;
    font-weight: 500;
}

/* Input with unit suffix */
.input-affix {
    position: relative;
}

.input-affix input {
    padding-right: 40px;
}

.input-affix span {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: var(--text-tertiary);
    pointer-events: none;
}

/* Product option sections: side by side when both are visible */
.product-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.product-section {
    min-width: 0;
}

.field-list {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.field-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 128px;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
}

.field-row + .field-row {
    border-top: 1px solid var(--border-subtle);
}

.field-row label {
    margin: 0;
    font-weight: 500;
}

.field-row input {
    height: 34px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    font: inherit;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
    background-color: var(--surface-muted);
}

.btn.primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn:focus-visible,
.tab-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.btn-dashed {
    border-style: dashed;
    color: var(--text-secondary);
    background: transparent;
}

.btn-dashed:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: var(--primary-soft);
}

.btn-block {
    width: 100%;
    margin-top: 16px;
}

/* ==========================================================================
   Option rows (checkbox / radio / toggle)
   ========================================================================== */
.option {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-color);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.option:hover {
    border-color: var(--border-color);
}

.option:has(input:checked) {
    border-color: var(--primary-color);
    background: var(--primary-soft);
}

.option-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.option-title {
    font-weight: 500;
    color: var(--text-primary);
}

.option-sub {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
}

input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* Option + its nested details as one block */
.option-group {
    border-radius: var(--radius-md);
}

.option-group:has(> .option-details[style*="block"]) > .option,
.option-group:has(> .option-details:not([hidden]):not([style])) > .option {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.option-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--primary-color);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    background: var(--surface-color);
}

.option-details[style*="block"] {
    display: flex !important;
}

.option-details label {
    margin-bottom: 0;
}

.option-details .form-grid label {
    margin-bottom: 6px;
}

.check-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
}

/* Toggle switch */
.toggle-container {
    position: relative;
}

.toggle-container input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-slider {
    position: relative;
    flex-shrink: 0;
    width: 36px;
    height: 20px;
    background-color: var(--border-color);
    border-radius: 999px;
    transition: background-color 0.2s;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3);
    transition: transform 0.2s;
}

input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

.toggle-container:has(input:focus-visible) {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.calc-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    align-items: end;
}

.calc-options .option {
    height: 58px;
}

/* ==========================================================================
   Powder-dye offer option columns
   ========================================================================== */
.option-columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.option-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.column-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.column-head h3 {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
}

.column-head .card-meta {
    font-size: 12px;
}

.icon-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: var(--primary-soft);
    color: var(--primary-color);
}

.icon-tile .icon {
    width: 18px;
    height: 18px;
}

.details-panel {
    margin-top: 4px;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--background-color);
    border: 1px solid var(--border-subtle);
}

.details-panel > div + div[style*="block"] {
    margin-top: 12px;
}

.details-panel .section-label {
    margin-bottom: 8px;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background-color: var(--surface-color);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td {
    background: var(--background-color);
}

/* Machine list in the rail */
.machine-list-container {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
}

#machine-table {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}

#machine-table th,
#machine-table td {
    padding: 8px 12px;
    white-space: nowrap;
}

#machine-table th:last-child,
#machine-table td:last-child {
    text-align: right;
}

#machine-table td .btn {
    height: 28px;
    font-size: 12px;
    color: var(--error-color);
    border-color: var(--border-subtle);
}

#machine-table td .btn:hover {
    background: var(--error-soft);
    border-color: var(--error-color);
}

#machine-table:has(#machine-list:empty) {
    display: none;
}

.empty-hint {
    display: none;
    padding: 20px 12px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.machine-list-container:has(#machine-list:empty) .empty-hint {
    display: block;
}

.summary-box {
    margin-top: 12px;
    padding: 12px 14px;
    background-color: var(--primary-soft);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    white-space: pre-line;
    line-height: 1.6;
}

.summary-box:empty {
    display: none;
}

/* ==========================================================================
   Results
   ========================================================================== */
.results-container:empty {
    display: none;
}

.results-card:has(#calc-results:empty) {
    display: none;
}

#calc-results {
    padding: 16px 20px 20px;
}

#calc-results h3 {
    display: none; /* replaced by the card heading */
}

#calc-results h4 {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.df-table {
    width: 100%;
    overflow-x: auto;
    display: block;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.df-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.df-table th,
.df-table td {
    padding: 8px 12px;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-subtle);
}

.df-table th {
    position: sticky;
    top: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background-color: var(--background-color);
}

.df-table tbody tr:last-child td {
    border-bottom: none;
}

.df-table tbody tr:hover td {
    background: var(--primary-soft);
}

/* Offer table */
.offer-table td:first-child,
.offer-table th:first-child {
    width: 120px;
    padding-left: 20px;
}

.offer-table td:first-child {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--primary-color);
}

.offer-table td:last-child {
    font-weight: 500;
}

/* ==========================================================================
   Empty state (tabs not yet ported)
   ========================================================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 64px 24px;
    text-align: center;
    background: var(--surface-color);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
}

.empty-state h2 {
    font-size: 16px;
    font-weight: 600;
    margin-top: 4px;
}

.empty-state p {
    color: var(--text-secondary);
}

/* ==========================================================================
   Chemical tabs: shared components
   ========================================================================== */

/* Segmented radio group */
.seg-radio {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 2px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    max-width: 100%;
}

.seg-radio label {
    position: relative;
    margin: 0;
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}

.seg-radio input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.seg-radio label:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

.seg-radio label:has(input:checked) {
    background: var(--primary-color);
    color: #fff;
}

.seg-radio label:has(input:focus-visible) {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

/* Stat tiles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.stat {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 14px 16px;
    background: var(--surface-color);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.stat .icon-tile {
    width: 40px;
    height: 40px;
}

.stat > div {
    min-width: 0;
}

.stat-value {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.hint-line {
    margin-top: -4px;
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Warning banner */
.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-weight: 500;
    color: #b06000;
    background: #fef7e0;
    border: 1px solid #feefc3;
    border-radius: var(--radius-md);
}

.alert .zh {
    color: inherit;
    opacity: 0.8;
}

.alert .icon {
    align-self: flex-start;
    margin-top: 2px;
}

.alert.compact {
    padding: 8px 10px;
    font-size: 12px;
    gap: 8px;
}

.alert-info {
    display: block;
    font-weight: 400;
}

.alert-info:empty {
    display: none;
}

.info-note {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--primary-hover);
    background: var(--primary-soft);
    border-radius: var(--radius-md);
}

.info-note .zh {
    color: inherit;
    opacity: 0.8;
}

.df-table + h4 {
    margin-top: 20px;
}

.offer-notes {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 20px 20px;
}

.offer-notes:not(:has(> :not([hidden]))) {
    display: none;
}

.offer-notes .section-label {
    margin: 16px 0 0;
}

.offer-notes .field-row {
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

/* Status badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 999px;
    white-space: nowrap;
    background: var(--surface-muted);
    color: var(--text-secondary);
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge.on {
    background: var(--primary-soft);
    color: var(--primary-color);
}

/* Two-up card grid inside the main column */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 16px;
    align-items: start;
}

.muted-note {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--background-color);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.muted-note .zh {
    display: block;
    margin-top: 2px;
}

/* Field rows: variants */
.field-row.wide {
    grid-template-columns: minmax(0, 1fr) auto;
}

.field-row .field-label {
    margin: 0;
}

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

.readout {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    overflow-wrap: anywhere;
}

.readout.left {
    text-align: left;
}

.field-list.flush {
    padding: 0;
    border: none;
    border-radius: 0;
}

.field-list.flush .field-row {
    padding: 10px 20px;
}

/* Toggle switch placed in a card header */
.switch {
    position: relative;
    display: inline-flex;
    margin: 0;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch:has(input:focus-visible) {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 999px;
}

.card:has(> .card-head .switch input:not(:checked)) .card-title h2 {
    color: var(--text-secondary);
}

.card:has(> .card-head .switch input:not(:checked)) > .card-head {
    border-bottom-color: transparent;
}

.option-columns.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.option-details .field-label {
    margin-bottom: 0;
}

/* Salt / soda usage tables */
.usage-table td:nth-child(2),
.usage-table td:nth-child(3),
.usage-table th:nth-child(2),
.usage-table th:nth-child(3) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.usage-table th:first-child,
.usage-table td:first-child {
    padding-left: 20px;
}

.usage-table th:last-child,
.usage-table td:last-child {
    padding-right: 20px;
}

.usage-table tbody tr:last-child td {
    border-bottom: 1px solid var(--border-subtle);
}

.usage-table .total-row td {
    font-weight: 600;
    background: var(--background-color);
}

.summary-list {
    list-style: none;
    margin-top: 12px;
}

.summary-list:empty {
    display: none;
}

.summary-list li {
    padding: 8px 12px;
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.summary-list li + li {
    margin-top: 6px;
}

/* Live offer panel in the right rail */
.offer-card {
    max-height: calc(100vh - 112px);
    overflow-y: auto;
}

.rail .offer-table th:first-child,
.rail .offer-table td:first-child {
    width: 64px;
}

.table-wrap .empty-hint {
    margin: 12px 20px;
}

.table-wrap:has(tbody:empty) table {
    display: none;
}

.table-wrap:has(tbody:empty) .empty-hint {
    display: block;
}

.rail-subhead {
    margin: 0;
    padding: 14px 20px 6px;
    border-top: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Configurator: collapsible sections + combined offer panel
   ========================================================================== */
/* One container per section: header on top, its cards in a tinted well below,
   and an accent bar down the left edge that ties them together */
.config-section {
    scroll-margin-top: 88px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.section-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    list-style: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s;
}

.section-head::-webkit-details-marker {
    display: none;
}

.section-head:hover {
    background: var(--background-color);
}

.config-section[open] > .section-head {
    border-bottom: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.section-head:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.section-title {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.section-title h2 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.section-head .chevron {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
    transition: transform 0.2s;
}

.config-section[open] > .section-head .chevron {
    transform: rotate(180deg);
}

.config-section > .section-body {
    padding: 16px;
    background: var(--surface-muted);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.config-stack {
    gap: 24px;
}

.offer-group + .offer-group {
    border-top: 1px solid var(--border-subtle);
}

.offer-group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
}

.offer-group-head .icon {
    color: var(--primary-color);
}

.offer-group-head:hover {
    color: var(--primary-color);
}

.offer-group-head .count {
    margin-left: auto;
    min-width: 24px;
    padding: 1px 8px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    color: var(--primary-color);
    background: var(--primary-soft);
    border-radius: 999px;
}

.offer-group .rail-subhead {
    border-top: none;
    padding-top: 10px;
}

.offer-group .offer-notes {
    padding-top: 4px;
}

/* ==========================================================================
   Quotation: pricing tables, summary, document actions
   ========================================================================== */
.table-scroll {
    overflow-x: auto;
}

.price-table {
    min-width: 640px;
}

.price-table th,
.price-table td {
    padding: 8px 10px;
    vertical-align: middle;
}

.price-table th:first-child,
.price-table td:first-child {
    padding-left: 20px;
}

.price-table .col-qty {
    width: 92px;
}

.price-table .col-price {
    width: 150px;
}

.price-table .col-total {
    width: 140px;
    text-align: right;
    white-space: nowrap;
}

.price-table th:nth-child(4) {
    text-align: right;
}

.price-table .col-action {
    width: 52px;
    padding-right: 16px;
    text-align: right;
}

.price-table input,
.price-table select {
    height: 34px;
}

.input-affix.prefix input {
    padding-left: 28px;
    padding-right: 10px;
}

.input-affix.prefix span {
    left: 10px;
    right: auto;
}

.icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    color: var(--text-secondary);
}

.icon-btn:hover {
    color: var(--error-color);
    border-color: var(--error-color);
    background: var(--error-soft);
}

.price-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--background-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.price-total {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-secondary);
}

.price-total strong {
    margin-left: 8px;
    font-size: 15px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.price-card:has(> .card-head .switch input:not(:checked)) > .card-head {
    border-bottom-color: transparent;
}

.summary-rows {
    padding: 8px 20px;
}

.summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.summary-row label {
    margin: 0;
}

.summary-row strong {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.summary-row.excluded strong {
    font-weight: 400;
    color: var(--text-tertiary);
}

.summary-row.grand strong {
    font-size: 15px;
}

.summary-row.final {
    border-bottom: none;
}

.summary-row.final strong {
    font-size: 20px;
    color: var(--primary-color);
}

.summary-row .select-compact {
    min-width: 0;
    width: 150px;
    height: 34px;
}

.doc-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 20px 20px;
    border-top: 1px solid var(--border-subtle);
}

.doc-actions .btn-block {
    margin-top: 0;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.doc-status {
    padding: 8px 10px;
    font-size: 12px;
    border-radius: var(--radius-md);
    overflow-wrap: anywhere;
}

.doc-status.info {
    color: var(--text-secondary);
    background: var(--background-color);
}

.doc-status.success {
    color: #137333;
    background: #e6f4ea;
}

.doc-status.error {
    color: var(--error-color);
    background: var(--error-soft);
}

.engineer-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 140px 140px;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
}

.engineer-row + .engineer-row {
    border-top: 1px solid var(--border-subtle);
}

.engineer-row .field-label {
    margin: 0;
}

.engineer-row input {
    height: 34px;
    padding-right: 52px;
}

/* Settings */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 16px;
    align-items: start;
}

.card-body.stack {
    gap: 12px;
}

/* ==========================================================================
   History
   ========================================================================== */
.search-field {
    position: relative;
}

.search-field .icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
}

.search-field input {
    padding-left: 38px;
    background: var(--surface-color);
}

.history-group > .version-list {
    margin: 0;
    border: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    box-shadow: none;
}

.version-list {
    list-style: none;
    padding: 0;
}

.version-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
}

.version-item + .version-item {
    border-top: 1px solid var(--border-subtle);
}

.version-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.version-title {
    font-weight: 500;
    overflow-wrap: anywhere;
}

.version-meta {
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.version-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.version-actions .btn {
    height: 32px;
}

.version-list.compact .version-item {
    padding: 10px 20px;
}

.version-list.compact .version-title {
    font-size: 13px;
}

.version-list:empty {
    display: none;
}

.hist-auto-status {
    margin: 0;
    padding: 10px 20px 0;
}

.hist-auto-empty {
    display: block;
}

.topbar-meta .btn {
    height: 34px;
}

/* ==========================================================================
   Settings: Kingdee masterdata & prices
   ========================================================================== */
.kd-card {
    grid-column: 1 / -1;
}

.kd-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 16px;
}

.kd-toolbar .form-group {
    min-width: 220px;
}

.kd-groups-field {
    flex: 1;
}

.kd-inline {
    display: flex;
    gap: 8px;
}

.kd-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    background: var(--background-color);
}

.kd-filters .search-field {
    flex: 1;
    min-width: 240px;
}

.kd-filters select {
    width: auto;
    min-width: 220px;
}

.kd-filters .check-inline {
    margin: 0;
}

.kd-table {
    min-width: 900px;
    font-size: 13px;
}

.kd-table th,
.kd-table td {
    padding: 9px 12px;
    vertical-align: top;
}

.kd-table th:first-child,
.kd-table td:first-child {
    padding-left: 20px;
}

.kd-row {
    cursor: pointer;
}

.kd-row:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.kd-row.open td {
    background: var(--primary-soft);
}

.kd-num {
    font-weight: 600;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.kd-price {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.kd-muted {
    color: var(--text-secondary);
}

.kd-tag {
    display: inline-block;
    padding: 0 6px;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--surface-muted);
    border-radius: 999px;
}

.kd-detail > td {
    padding: 16px 20px 20px !important;
    background: var(--background-color);
}

.kd-facts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px 20px;
    margin-bottom: 16px;
}

.kd-fact {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.kd-fact .field-label {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.kd-detail-block + .kd-detail-block {
    margin-top: 14px;
}

.kd-price-table {
    background: var(--surface-color);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    border-collapse: separate;
    border-spacing: 0;
}

.kd-sales-pick {
    height: 30px;
    width: auto;
    max-width: 280px;
    padding: 0 28px 0 8px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.kd-history-table tr.kd-chosen td {
    background: var(--primary-soft);
}

.kd-history-table input[type="radio"] {
    margin: 0;
    accent-color: var(--primary-color);
}

.kd-pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
}

.kd-pager .kd-muted {
    margin-right: auto;
    font-size: 13px;
}

.kd-empty {
    display: block;
    margin: 16px 20px;
}

.icon.spin {
    animation: kd-spin 1s linear infinite;
}

/* Kingdee BOM tree */
.kd-caret {
    display: inline-block;
    width: 14px;
    color: var(--text-tertiary);
}

.kd-bom-cell {
    white-space: nowrap;
}

.kd-tag.calc {
    color: var(--primary-color);
    background: var(--primary-soft);
}

.kd-tag.warn {
    color: #b06000;
    background: #fef7e0;
}

.kd-tag.internal {
    color: #7b1fa2;
    background: #f3e8fd;
}

.kd-bom-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-bottom: 10px;
}

.kd-bom-head .section-label {
    margin: 0;
}

.kd-version {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.kd-version .field-label {
    margin: 0;
    white-space: nowrap;
}

.kd-version select {
    height: 32px;
    width: auto;
    max-width: 360px;
}

.kd-bom-table {
    min-width: 860px;
    background: var(--surface-color);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    border-collapse: separate;
    border-spacing: 0;
}

.kd-bom-table td,
.kd-bom-table th {
    padding: 8px 12px;
    vertical-align: top;
}

.kd-bom-table td:not(:first-child),
.kd-bom-table th:not(:first-child) {
    text-align: right;
}

.kd-bom-table tfoot td {
    font-weight: 600;
    background: var(--background-color);
    border-top: 1px solid var(--border-color);
}

.kd-tree-cell {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding-left: calc(var(--depth, 0) * 22px);
}

.kd-node-toggle,
.kd-node-spacer {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
}

.kd-node-toggle {
    padding: 0;
    font: inherit;
    line-height: 1;
    color: var(--primary-color);
    background: var(--primary-soft);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.kd-node-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

.kd-excluded td {
    color: var(--text-tertiary);
}

.kd-facts-title {
    margin-top: 18px;
}

.kd-missing-children {
    margin: 0 20px 12px;
}

@keyframes kd-spin {
    to { transform: rotate(-360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .icon.spin { animation: none; }
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    padding: 1px 5px;
    background: var(--surface-muted);
    border-radius: 4px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
    .layout-split {
        grid-template-columns: minmax(0, 1fr);
    }

    .rail {
        position: static;
    }

    .option-columns {
        grid-template-columns: minmax(0, 1fr);
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .offer-card {
        max-height: none;
    }
}

@media (max-width: 640px) {
    :root {
        --gutter: 16px;
    }

    .brand img {
        height: 32px;
    }

    .topbar-meta .pill {
        display: none;
    }

    .version-item {
        flex-wrap: wrap;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .tab-btn .zh {
        display: none;
    }

    .card-head {
        flex-wrap: wrap;
    }

    .section-head {
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .config-section > .section-body {
        padding: 10px;
    }

    .engineer-row {
        grid-template-columns: minmax(0, 1fr) 1fr;
    }

    .engineer-row .field-label {
        grid-column: 1 / -1;
    }

    .settings-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .price-total {
        margin-left: 0;
        width: 100%;
    }

    .select-compact {
        width: 100%;
    }

    .form-grid.cols-3,
    .option-columns.cols-2 {
        grid-template-columns: minmax(0, 1fr);
    }

    .card-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .stat-value {
        font-size: 18px;
    }

    .field-row {
        grid-template-columns: minmax(0, 1fr) 104px;
    }
}

/* ==========================================================================
   Login (login.html), user menu and Settings → Users
   ========================================================================== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 16px 32px;
}

.auth-shell {
    width: 100%;
    max-width: 420px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.auth-brand img {
    height: 44px;
    width: auto;
}

.auth-brand h1 {
    font-size: 18px;
    font-weight: 600;
}

.auth-brand p,
.auth-text {
    color: var(--text-secondary);
}

.auth-text .zh {
    display: block;
}

.auth-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.auth-head h2 {
    font-size: 18px;
    font-weight: 600;
}

.auth-card .btn-block {
    margin-top: 4px;
}

.code-input {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 20px !important;
    letter-spacing: 0.3em;
    text-align: center;
}

.link-btn {
    align-self: flex-start;
    padding: 0;
    font: inherit;
    font-size: 13px;
    color: var(--primary-color);
    background: none;
    border: none;
    cursor: pointer;
}

.link-btn:hover {
    text-decoration: underline;
}

.link-btn:disabled {
    color: var(--text-tertiary);
    cursor: default;
    text-decoration: none;
}

.auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
}

.auth-message {
    margin: 0 20px 20px;
}

.auth-note {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-tertiary);
    text-align: center;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 280px;
    color: var(--text-secondary);
    font-weight: 500;
}

.user-chip #user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sales users don't see the Kingdee controls that change shared state */
body[data-role="Sales"] .admin-only {
    display: none !important;
}

.usr-card {
    grid-column: 1 / -1;
}

.usr-invite {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) 160px auto;
    gap: 12px;
    align-items: end;
}

.usr-table td {
    vertical-align: top;
}

.usr-table select {
    width: auto;
    min-width: 110px;
    height: 32px;
}

.usr-sub {
    display: block;
    font-size: 12px;
    color: var(--text-tertiary);
}

.usr-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.usr-actions .btn {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
}

.badge.usr-active {
    background: #e6f4ea;
    color: #137333;
}

.badge.usr-pending {
    background: #fef7e0;
    color: #b06000;
}

.badge.usr-blocked {
    background: var(--error-soft);
    color: var(--error-color);
}

#usr-mail.warn {
    color: var(--error-color);
    font-weight: 500;
}

@media (max-width: 860px) {
    .usr-invite {
        grid-template-columns: minmax(0, 1fr);
    }

    .user-chip {
        max-width: 160px;
    }
}

/* ==========================================================================
   Calculation tab (Admin)
   ========================================================================== */
#tab-calc.active {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.calc-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.calc-toolbar .search-field {
    flex: 1 1 260px;
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
    gap: 16px;
    align-items: start;
}

.calc-formula {
    padding: 10px 12px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    background: var(--background-color);
    border-radius: var(--radius-md);
}

.calc-ref {
    color: var(--primary-hover);
    font-weight: 600;
}

.calc-rows {
    display: flex;
    flex-direction: column;
}

.calc-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 170px 150px;
    gap: 6px 12px;
    align-items: center;
    padding: 8px 6px;
    border-top: 1px solid var(--border-subtle);
}

.calc-row:first-child {
    border-top: none;
}

.calc-row label {
    margin: 0;
    font-weight: 500;
}

.calc-row.custom label::after {
    content: "●";
    margin-left: 6px;
    font-size: 9px;
    color: var(--primary-color);
    vertical-align: middle;
}

.calc-row.pending {
    background: #fef7e0;
    border-radius: var(--radius-sm);
}

.calc-row.invalid input {
    border-color: var(--error-color);
}

.calc-input {
    display: flex;
    align-items: center;
    gap: 6px;
}

.calc-input input {
    height: 32px;
    text-align: right;
}

.calc-unit {
    min-width: 34px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.calc-default {
    font-size: 12px;
    color: var(--text-secondary);
}

.calc-default .link-btn {
    font-size: 12px;
    margin-left: 4px;
}

.calc-error {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--error-color);
}

.calc-log-table td {
    vertical-align: top;
    font-size: 13px;
}

@media (max-width: 860px) {
    .calc-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .calc-row {
        grid-template-columns: minmax(0, 1fr) 150px;
    }

    .calc-default {
        grid-column: 1 / -1;
    }
}

.calc-notice .btn {
    margin-left: auto;
    flex-shrink: 0;
}
