:root {
  color-scheme: light;
  --base-white: #ffffff;
  --base-black: #000000;
  --blue-50: #e9f3fa;
  --blue-500: #027bfb;
  --green-500: #25ae3e;
  --orange-300: #fff7ed;
  --orange-500: #fa7315;
  --red-500: #ef4a40;
  --grey-50: #f8f8fa;
  --grey-75: #f6f6f6;
  --grey-100: #efefef;
  --grey-150: #ececef;
  --grey-200: #ededed;
  --grey-250: #d9d9e0;
  --grey-300: #d1d1d6;
  --grey-500: #808185;
  --text-primary: var(--base-black);
  --text-secondary: var(--base-white);
  --text-tertiary: var(--grey-500);
  --text-accent: var(--blue-500);
  --text-danger: var(--red-500);
  --text-success: var(--green-500);
  --buttons-bg-primary: var(--base-black);
  --buttons-bg-accent: var(--blue-500);
  --buttons-bg-secondary: var(--base-white);
  --buttons-bg-disable: var(--grey-100);
  --fill-app: #f4f7fc;
  --fill-surface-default: var(--base-white);
  --fill-surface-muted: var(--grey-50);
  --fill-surface-select: rgba(2,123,251,.10);
  --card-bg-pr: var(--grey-50);
  --card-bg-sec: var(--base-white);
  --stroke-default: var(--grey-250);
  --stroke-accent: var(--blue-500);
  --separator-gray: var(--grey-200);
  --badge-bg-blue-10: rgba(2,123,251,.10);
  --badge-bg-green-10: rgba(37,174,62,.10);
  --badge-txt-blue: var(--blue-500);
  --badge-txt-green: var(--green-500);
  --font-display: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --shadow-panel: 0 12px 36px rgba(31,49,78,.06);
  --shadow-dialog: 0 28px 90px rgba(16,27,44,.20);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--fill-app); }
body { margin: 0; min-width: 320px; background: var(--fill-app); color: var(--text-primary); font-family: var(--font-display); font-size: 14px; letter-spacing: -.003em; }
button, input, textarea, select { font: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar { position: sticky; top: 0; z-index: 20; height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(24px, calc((100vw - 1400px) / 2)); background: rgba(255,255,255,.94); border-bottom: 1px solid var(--separator-gray); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-logo { display: block; width: 92px; height: auto; }
.brand-divider { width: 1px; height: 25px; background: var(--stroke-default); }
.brand small { color: var(--text-tertiary); font-size: 12px; line-height: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.data-status { display: flex; align-items: center; gap: 8px; color: var(--text-tertiary); font-size: 12px; line-height: 16px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange-500); box-shadow: 0 0 0 4px rgba(250,115,21,.10); }
.data-status.ready .status-dot { background: var(--green-500); box-shadow: 0 0 0 4px rgba(37,174,62,.10); }
.user-email { color: var(--text-tertiary); font-size: 12px; line-height: 16px; }
.logout-button { font-size: 12px; padding: 6px 2px; }
.data-status.error .status-dot { background: var(--red-500); box-shadow: 0 0 0 4px rgba(239,74,64,.10); }
.reference-button, .copy-button { border: 1px solid var(--stroke-default); border-radius: 12px; background: var(--buttons-bg-secondary); color: var(--text-primary); padding: 10px 14px; font-size: 12px; line-height: 16px; font-weight: 600; transition: border-color .15s, background .15s, color .15s; }
.reference-button:hover, .copy-button:hover:not(:disabled) { border-color: var(--stroke-accent); color: var(--text-accent); background: var(--fill-surface-select); }

.workspace { width: min(1400px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 24px; flex: 1; }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 25px; }
.eyebrow { margin: 0 0 10px; color: var(--text-accent); font-size: 11px; line-height: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; max-width: 820px; font-size: clamp(34px,4vw,50px); line-height: 1.04; letter-spacing: -.035em; }
.intro p:last-child { color: var(--text-tertiary); max-width: 760px; margin: 14px 0 0; font-size: 16px; line-height: 20px; }
.main-grid { display: grid; grid-template-columns: minmax(0,.92fr) minmax(0,1.08fr); gap: 18px; align-items: start; }
.panel { background: var(--card-bg-sec); border: 1px solid var(--separator-gray); border-radius: 22px; box-shadow: var(--shadow-panel); padding: 24px; }
.request-panel { border-top: 3px solid var(--base-black); }
.response-panel { min-height: 610px; position: sticky; top: 90px; border-top: 3px solid var(--blue-500); }
.panel-heading { display: flex; gap: 12px; align-items: center; margin-bottom: 23px; }
.panel-heading h2 { margin: 0; font-size: 18px; line-height: 22px; font-weight: 700; }
.panel-heading p { margin: 3px 0 0; color: var(--text-tertiary); font-size: 12px; line-height: 14px; }
.step { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 11px; background: var(--buttons-bg-primary); color: var(--text-secondary); font-size: 14px; font-weight: 600; }
.response-heading .step { background: var(--buttons-bg-accent); }
.response-heading .copy-button { margin-left: auto; }

.field-label, .field > span, .order-line label > span { display: block; margin: 0 0 7px; color: var(--text-primary); font-size: 12px; line-height: 16px; font-weight: 600; }
.field em { color: var(--text-tertiary); font-style: normal; font-weight: 400; }
textarea, input, select { width: 100%; border: 1px solid var(--stroke-default); border-radius: 12px; background: var(--fill-surface-muted); color: var(--text-primary); outline: none; transition: border-color .15s, box-shadow .15s, background .15s; }
textarea::placeholder, input::placeholder { color: var(--text-tertiary); }
textarea:focus, input:focus, select:focus { border-color: var(--stroke-accent); box-shadow: 0 0 0 3px rgba(2,123,251,.10); background: var(--fill-surface-default); }
textarea { padding: 15px 16px; resize: vertical; font-size: 14px; line-height: 20px; }
input, select { height: 44px; padding: 0 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 15px; }

.request-actions { display: flex; align-items: center; gap: 15px; margin-top: 21px; }
.primary-button { display: flex; justify-content: space-between; align-items: center; gap: 30px; min-width: 210px; padding: 13px 16px; border: 0; border-radius: 12px; background: var(--buttons-bg-accent); color: var(--text-secondary); font-size: 16px; line-height: 21px; font-weight: 600; transition: transform .15s, background .15s, box-shadow .15s; }
.primary-button:hover { background: #006ee7; box-shadow: 0 8px 22px rgba(2,123,251,.18); transform: translateY(-1px); }
.primary-button:disabled { background: var(--buttons-bg-disable); color: var(--text-tertiary); box-shadow: none; transform: none; cursor: wait; }
.text-button, .ghost-button, .small-button { border: 0; background: transparent; color: var(--text-accent); font-weight: 600; }
.text-button { padding: 10px 4px; }
.ghost-button { border: 1px solid var(--stroke-default); padding: 10px 14px; border-radius: 12px; background: var(--buttons-bg-secondary); color: var(--text-primary); }
.ghost-button:hover { border-color: var(--stroke-accent); color: var(--text-accent); }
.small-button { padding: 8px 11px; border-radius: 10px; background: var(--fill-surface-select); }

.calculator { margin-top: 22px; border-top: 1px solid var(--separator-gray); padding-top: 19px; }
.calculator-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.calculator h3 { margin: 0; font-size: 14px; line-height: 18px; }
.calculator p { margin: 3px 0 0; color: var(--text-tertiary); font-size: 11px; line-height: 13px; }
.order-lines { display: grid; gap: 8px; }
.order-line { display: grid; grid-template-columns: minmax(0,1fr) 95px 38px 32px; gap: 8px; align-items: end; }
.line-unit { height: 44px; display: grid; place-items: center; color: var(--text-tertiary); font-size: 12px; }
.remove-line { width: 32px; height: 44px; border: 0; background: transparent; color: var(--text-tertiary); font-size: 23px; }
.remove-line:hover { color: var(--text-danger); }
.copy-button:disabled { background: var(--buttons-bg-disable); color: var(--text-tertiary); border-color: transparent; cursor: not-allowed; }
.copy-button.copied { background: var(--badge-bg-green-10); border-color: transparent; color: var(--text-success); }

.empty-state { display: grid; place-items: center; text-align: center; min-height: 460px; padding: 40px; color: var(--text-tertiary); }
.empty-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 18px; background: var(--fill-surface-select); color: var(--text-accent); font-size: 26px; margin-bottom: 14px; }
.empty-state h3 { color: var(--text-primary); margin: 0 0 8px; font-size: 18px; line-height: 22px; }
.empty-state p { max-width: 420px; margin: 0; font-size: 14px; line-height: 20px; }
.loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 460px; padding: 40px; text-align: center; }
.loading-state h3 { margin: 0 0 22px; font-size: 18px; line-height: 22px; }
.loading-icon { animation: loading-pulse 1.4s ease-in-out infinite; }
.loading-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; text-align: left; }
.loading-steps li { display: flex; align-items: center; gap: 12px; color: var(--text-tertiary); font-size: 14px; line-height: 20px; transition: color .2s; }
.loading-steps li.active { color: var(--text-primary); font-weight: 600; }
.loading-steps li.done { color: var(--text-primary); }
.loading-mark { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--stroke-default); color: var(--base-white); font-size: 11px; font-weight: 700; transition: background .2s, border-color .2s; }
.loading-steps li.active .loading-mark { border-color: var(--blue-500); border-right-color: transparent; animation: loading-spin .8s linear infinite; }
.loading-steps li.done .loading-mark { border-color: var(--blue-500); background: var(--blue-500); }
.loading-steps li.done .loading-mark::before { content: ""; width: 4px; height: 8px; margin-top: -2px; border: solid var(--base-white); border-width: 0 2px 2px 0; transform: rotate(45deg); }
@keyframes loading-spin { to { transform: rotate(360deg); } }
@keyframes loading-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.08); opacity: .7; } }
@media (prefers-reduced-motion: reduce) {
  .loading-icon, .loading-steps li.active .loading-mark { animation: none; }
  .loading-steps li.active .loading-mark { border-right-color: var(--blue-500); }
}
.email-output { min-height: 270px; background: var(--fill-surface-muted); border-color: var(--stroke-default); }
.alert { margin-bottom: 12px; padding: 11px 13px; border-radius: 10px; background: var(--orange-300); color: #9b5310; font-size: 12px; line-height: 16px; }
.tips { margin-bottom: 12px; padding: 11px 13px; border-radius: 10px; border: 1px dashed var(--border, rgba(0,0,0,.18)); font-size: 12px; line-height: 16px; }
.tips ul { margin: 6px 0 0; padding-left: 18px; }
.tips li + li { margin-top: 4px; }
.alert.error { background: rgba(239,74,64,.10); color: var(--text-danger); }
.calculation-card { margin-top: 15px; padding: 16px; border-radius: 15px; background: var(--fill-surface-muted); border: 1px solid var(--separator-gray); }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 11px; }
.section-title h3 { margin: 0; font-size: 14px; line-height: 18px; }
.section-title span { color: var(--text-tertiary); font-size: 11px; }
.calc-line, .total-line { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 6px 0; font-size: 12px; line-height: 16px; }
.calc-line small { display: block; color: var(--text-tertiary); margin-top: 2px; }
.totals { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--separator-gray); }
.total-line.discount { color: var(--text-success); }
.total-line.grand-total { font-size: 16px; line-height: 20px; font-weight: 700; padding-top: 10px; }
.sources { margin-top: 15px; border-top: 1px solid var(--separator-gray); padding-top: 13px; }
.sources summary { cursor: pointer; color: var(--text-primary); font-size: 12px; line-height: 16px; font-weight: 600; }
#sources-list { display: grid; gap: 7px; margin-top: 10px; }
.source-item { display: flex; gap: 8px; align-items: flex-start; color: var(--text-tertiary); font-size: 11px; line-height: 15px; }
.source-item::before { content: "✓"; color: var(--text-success); font-weight: 700; }
.source-item a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.feedback-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: 17px; color: var(--text-tertiary); font-size: 11px; }
.feedback-row button { border: 1px solid var(--stroke-default); border-radius: 999px; background: var(--buttons-bg-secondary); color: var(--text-tertiary); padding: 7px 11px; font-size: 11px; }
.feedback-row button:hover { border-color: var(--stroke-accent); color: var(--text-accent); }
.feedback-saved { color: var(--text-success); }
.feedback-row button.active { border-color: var(--stroke-accent); color: var(--text-accent); background: var(--fill-surface-select); }
.correction-form { display: grid; gap: 12px; margin-top: 12px; padding: 16px; border: 1px solid var(--stroke-default); border-radius: 14px; background: var(--fill-surface-default); }
.correction-form textarea { font-size: 13px; line-height: 18px; padding: 11px 13px; }
.correction-hint { margin: 0; color: var(--text-tertiary); font-size: 11px; }
.correction-actions { display: flex; gap: 8px; align-items: center; }

.reference-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: rgba(0,0,0,.38); backdrop-filter: blur(8px); }
.reference-dialog { width: min(760px,100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--fill-surface-default); border-radius: 22px; box-shadow: var(--shadow-dialog); padding: 25px; }
.reference-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--separator-gray); }
.reference-header h2 { margin: 0; font-size: 28px; line-height: 30px; letter-spacing: -.003em; }
.reference-header .eyebrow { margin-bottom: 5px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 11px; background: var(--fill-surface-muted); color: var(--text-tertiary); font-size: 25px; }
.icon-button:hover { color: var(--text-primary); background: var(--grey-100); }
.reference-stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 9px; margin-top: 18px; }
.reference-stats > div { padding: 13px; border-radius: 13px; background: var(--fill-surface-muted); border: 1px solid var(--separator-gray); }
.reference-stats span { display: block; color: var(--text-tertiary); font-size: 10px; line-height: 13px; margin-bottom: 6px; }
.reference-stats strong { display: block; font-size: 14px; line-height: 18px; }
.reference-section { padding: 17px 0; border-bottom: 1px solid var(--separator-gray); }
.reference-section h3, .settings-heading h3 { margin: 0 0 7px; font-size: 14px; line-height: 18px; }
.reference-section p { margin: 0; color: var(--text-tertiary); font-size: 12px; line-height: 18px; white-space: pre-line; }
.price-link { display: inline-flex; margin-top: 10px; color: var(--text-accent); font-size: 12px; line-height: 16px; font-weight: 600; text-decoration: none; }
.price-link:hover { text-decoration: underline; }
.reference-discounts { display: flex; flex-wrap: wrap; gap: 7px; }
.reference-discounts span { padding: 7px 10px; border-radius: 999px; background: var(--badge-bg-blue-10); color: var(--badge-txt-blue); font-size: 11px; line-height: 13px; font-weight: 600; }
.reference-edit-button { margin-top: 19px; }
.rules-search { width: 100%; margin: 11px 0 9px; padding: 9px 12px; border: 1px solid var(--stroke-default); border-radius: 10px; background: var(--fill-surface-default); color: var(--text-primary); font: inherit; font-size: 12px; }
.rules-list { display: grid; gap: 6px; color: var(--text-tertiary); font-size: 12px; }
.rules-item { border: 1px solid var(--separator-gray); border-radius: 12px; background: var(--fill-surface-muted); }
.rules-item summary { padding: 10px 13px; cursor: pointer; color: var(--text-primary); font-size: 13px; line-height: 18px; font-weight: 600; }
.rules-item[open] summary { border-bottom: 1px solid var(--separator-gray); }
.rules-body { padding: 4px 13px 12px; color: var(--text-primary); font-size: 12px; line-height: 18px; }
.rules-body p { margin: 9px 0 0; color: var(--text-primary); white-space: normal; }
.rules-body h4 { margin: 14px 0 0; font-size: 12px; line-height: 16px; }
.rules-body ul, .rules-body ol { margin: 8px 0 0; padding-left: 18px; }
.rules-body li + li { margin-top: 4px; }
.rules-body a { color: var(--text-accent); }
.rules-body code { padding: 1px 5px; border-radius: 5px; background: var(--fill-surface-default); font-size: 11px; overflow-wrap: anywhere; }
.rules-table { margin-top: 9px; overflow-x: auto; }
.rules-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rules-table th, .rules-table td { padding: 6px 8px; border-bottom: 1px solid var(--separator-gray); text-align: left; vertical-align: top; }
.rules-table th { color: var(--text-tertiary); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.full-field { grid-column: 1 / -1; }
.settings-block { margin: 20px 0; padding: 16px; border-radius: 14px; background: var(--fill-surface-muted); border: 1px solid var(--separator-gray); }
.settings-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 11px; }
.settings-heading h3 { margin: 0; }
.settings-heading span { color: var(--text-tertiary); font-size: 10px; }
.discount-settings { display: grid; gap: 7px; }
.discount-setting-row { display: grid; grid-template-columns: 1fr 26px 1fr; gap: 8px; align-items: center; }
.discount-setting-row input { background: var(--fill-surface-default); }
.discount-setting-row span { color: var(--text-tertiary); text-align: center; }
.storage-note { margin: 10px 0 0; color: var(--text-tertiary); font-size: 11px; line-height: 16px; }
.settings-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 17px; }
.danger-text-button { border: 0; background: transparent; color: var(--text-danger); font-weight: 600; font-size: 12px; margin-left: auto; }
.settings-message { min-height: 18px; margin-top: 10px; color: var(--text-success); font-size: 12px; }
footer { display: flex; justify-content: space-between; gap: 20px; width: min(1400px,calc(100% - 48px)); margin: 0 auto; padding: 20px 0 26px; color: var(--text-tertiary); font-size: 11px; }

@media (max-width: 980px) {
  .main-grid { grid-template-columns: 1fr; }
  .response-panel { position: static; min-height: 520px; }
  .workspace { width: min(760px,calc(100% - 32px)); }
  .topbar { padding: 0 16px; }
  footer { width: calc(100% - 32px); }
}
@media (max-width: 620px) {
  .topbar { height: 64px; }
  .brand-logo { width: 76px; }
  .brand-divider { height: 22px; }
  .brand small { font-size: 11px; }
  .data-status, .user-email { display: none; }
  .topbar-actions { gap: 8px; }
  .reference-button { padding: 8px 10px; font-size: 11px; }
  .workspace { padding-top: 27px; }
  .intro { align-items: start; }
  .intro .ghost-button { display: none; }
  h1 { font-size: 32px; line-height: 1.06; }
  .intro p:last-child { font-size: 14px; line-height: 18px; }
  .panel { border-radius: 17px; padding: 17px; }
  .form-row { grid-template-columns: 1fr; }
  .request-actions { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .order-line { grid-template-columns: minmax(0,1fr) 78px 30px; }
  .order-line .quantity-field { grid-column: 2; }
  .remove-line { grid-column: 3; }
  .line-unit { display: none; }
  footer { flex-direction: column; }
  .reference-overlay { padding: 0; place-items: stretch; }
  .reference-dialog { width: 100%; max-height: 100vh; min-height: 100vh; border-radius: 0; padding: 18px; }
  .reference-stats { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .full-field { grid-column: auto; }
  .discount-setting-row { grid-template-columns: 1fr 20px 1fr; }
  .settings-actions { align-items: stretch; flex-direction: column; }
  .settings-actions .primary-button, .settings-actions .ghost-button { width: 100%; }
  .danger-text-button { margin-left: 0; padding: 8px; }
}

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); }
.login-card .brand { margin-bottom: 26px; }
.login-card h1 { margin: 0 0 8px; font-size: 26px; line-height: 30px; }
.login-card > p { margin: 0 0 22px; color: var(--text-tertiary); font-size: 14px; line-height: 20px; }
.login-card form { display: grid; gap: 14px; }
.login-card .primary-button { width: 100%; }
.login-message { min-height: 18px; margin: 0; font-size: 12px; line-height: 16px; color: var(--text-tertiary); }
.login-message.error { color: var(--text-danger); }
.code-input { font-size: 22px; letter-spacing: .35em; text-align: center; }
.refresh-prices { margin-top: 10px; font-size: 12px; }
.storage-note.error { color: var(--text-danger); }
.ask-ai { display: block; margin: -6px 0 8px; font-size: 12px; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; font-size: 13px; color: var(--text-tertiary); }
.preset-button { padding: 7px 12px; border: 1px solid var(--grey-250); border-radius: 999px; background: transparent; color: var(--text-accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.preset-button:hover { border-color: var(--text-accent); }
