[hidden] { display: none !important; }
:root {
  --navy: #17263a;
  --navy-2: #263b53;
  --gold: #d0a547;
  --gold-soft: #fff5d8;
  --paper: #f4f6f8;
  --white: #ffffff;
  --ink: #17212d;
  --muted: #667281;
  --line: #dce2e8;
  --danger: #a93838;
  --shadow: 0 12px 32px rgba(21, 37, 56, 0.08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }

.topbar {
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: max(18px, env(safe-area-inset-top)) max(20px, calc((100vw - 1100px) / 2)) 20px;
  border-bottom: 4px solid var(--gold);
}
.eyebrow { margin: 0 0 4px; color: #dbe4ef; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; }
h1 { margin: 0; font-size: clamp(1.65rem, 5vw, 2.25rem); }
h2 { display: inline; margin: 0; font-size: 1.12rem; }
.topbar-actions { display: flex; align-items: end; gap: 10px; }
.language-picker { color: #dbe4ef; font-size: .7rem; min-width: 135px; }
.language-picker select { min-height: 40px; padding: 8px 10px; background: var(--white); }

.app-shell { width: min(1100px, calc(100% - 28px)); margin: 22px auto 60px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.summary-card { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 15px 18px; box-shadow: var(--shadow); }
.summary-card span { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 700; margin-bottom: 5px; }
.summary-card strong { font-size: 1.35rem; }
.summary-card.total { background: var(--navy); color: var(--white); border-color: var(--navy); }
.summary-card.total span { color: #dbe4ef; }
.cloud-panel { border-left: 4px solid #3c83f6; }
.cloud-icon { display: inline-grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; background: #e9f2ff; color: #2463c7; font-size: 1rem; }
.sync-status { padding: 6px 10px; border-radius: 999px; font-size: .76rem; font-weight: 850; }
.sync-status.online { color: #176436; background: #e5f6eb; }
.sync-status.syncing { color: #705500; background: #fff4cf; }
.sync-status.offline { color: #536273; background: #edf1f5; }
.sync-status.error { color: #8b3030; background: #f9e7e7; }
.cloud-setup-notice { margin-bottom: 12px; border: 1px solid #eed58a; background: #fff8df; color: #654d0c; padding: 11px 12px; border-radius: 10px; font-size: .85rem; }
.cloud-auth-grid { display: grid; grid-template-columns: 1.2fr 1fr auto auto; gap: 10px; align-items: end; }
.cloud-session { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.cloud-session strong, .cloud-session small { display: block; }
.cloud-session small { margin-top: 4px; color: var(--muted); }
.cloud-session-actions { display: flex; gap: 8px; }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.section-heading > div { display: flex; align-items: center; gap: 10px; }
.step { display: inline-grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; background: var(--gold); color: var(--navy); font-weight: 900; }
.save-status { color: var(--muted); font-size: 0.78rem; }
.helper { margin: -8px 0 16px; color: var(--muted); font-size: 0.86rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #3d4958; font-size: 0.78rem; font-weight: 800; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd4dd;
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  padding: 11px 12px;
  min-height: 44px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(208, 165, 71, 0.18); }
textarea { resize: vertical; }

.trade-sections { display: grid; gap: 11px; }
.trade-section { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: #fbfcfd; }
.trade-section summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 11px 14px; background: var(--navy-2); color: var(--white); cursor: pointer; font-weight: 850; }
.trade-section summary::-webkit-details-marker { display: none; }
.trade-title { display: flex; align-items: center; gap: 9px; }
.trade-title::before { content: "+"; display: inline-grid; place-items: center; width: 24px; height: 24px; border: 1px solid rgba(255,255,255,.5); border-radius: 50%; font-size: 1rem; }
.trade-section[open] .trade-title::before { content: "−"; }
.trade-total { color: #ffe8a3; white-space: nowrap; }
.trade-body { padding: 11px; }
.line-items { display: grid; gap: 9px; }
.trade-empty { color: var(--muted); font-size: .86rem; padding: 8px 2px 12px; }
.trade-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.line-item { display: grid; grid-template-columns: 1.05fr 1.45fr 0.52fr 0.68fr 0.78fr 0.82fr 0.72fr auto; gap: 8px; align-items: end; padding: 12px; background: #f8fafb; border: 1px solid var(--line); border-radius: 11px; }
.line-item .amount { align-self: center; text-align: right; min-width: 88px; font-size: 1rem; color: var(--navy); }
.remove-line { align-self: center; width: 42px; height: 42px; border: 0; border-radius: 10px; background: #f5e6e6; color: var(--danger); font-weight: 900; cursor: pointer; }

.totals-layout { display: grid; grid-template-columns: repeat(4, 1fr) 1.45fr; gap: 12px; align-items: start; }
.calculation-box { grid-row: span 2; background: #f8fafb; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.calculation-box div { display: flex; justify-content: space-between; gap: 18px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.calculation-box div:last-child { border: 0; }
.calculation-box .grand-total { background: var(--navy); color: var(--white); font-size: 1.05rem; }
.notes-label { margin-top: 15px; }
.voice-panel { border-top: 4px solid var(--gold); }
.voice-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.voice-actions.compact { margin-top: 10px; }
.mic-button { background: var(--gold); border-color: var(--gold); }
.mic-button:disabled, .button:disabled { cursor: not-allowed; opacity: .55; }
.button.danger { color: var(--danger); border-color: #dab3b3; }
.recording-attachment { margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafb; }
.recording-attachment audio { width: 100%; }
.support-note { margin: 12px 0 0; color: var(--muted); font-size: .8rem; }

.signature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.signature-block { display: grid; grid-template-columns: 1fr 150px; gap: 14px; align-items: end; }
.signature-input { border-width: 0 0 1px; border-radius: 0; padding-left: 2px; padding-right: 2px; font-family: "Segoe Script", "Bradley Hand", cursive; font-size: 1.05rem; }

.action-panel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.button { border: 1px solid var(--navy); border-radius: 10px; background: var(--white); color: var(--navy); min-height: 46px; padding: 11px 14px; font-weight: 850; cursor: pointer; }
.button:hover { filter: brightness(0.97); }
.button.primary { background: var(--navy); color: var(--white); }
.button.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.button.secondary { border-color: #bbc5cf; }
.button.small { min-height: 38px; padding: 7px 11px; font-size: 0.84rem; }

.saved-quotes { display: grid; gap: 10px; }
.saved-empty { color: var(--muted); background: #f8fafb; padding: 18px; border-radius: 10px; text-align: center; }
.saved-quote { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 13px; }
.saved-quote h3 { margin: 0 0 4px; font-size: 0.98rem; }
.saved-quote p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.saved-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.saved-actions button { border: 1px solid #cbd4dd; border-radius: 8px; background: var(--white); color: var(--navy); padding: 8px 10px; font-weight: 800; }
.saved-actions .delete { color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--navy); color: var(--white); padding: 11px 17px; border-radius: 999px; opacity: 0; pointer-events: none; transition: 0.2s ease; box-shadow: var(--shadow); text-align: center; z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .cloud-auth-grid { grid-template-columns: 1fr 1fr; }
  .cloud-session { align-items: flex-start; flex-direction: column; }
  .line-item { grid-template-columns: repeat(3, 1fr); }
  .line-item .description-field { grid-column: 1 / -1; }
  .line-item .amount { text-align: left; }
  .totals-layout { grid-template-columns: repeat(2, 1fr); }
  .calculation-box { grid-column: 1 / -1; grid-row: auto; }
  .signature-grid { grid-template-columns: 1fr; }
}

@media (max-width: 580px) {
  .topbar { padding-left: 16px; padding-right: 16px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { align-items: stretch; flex-direction: column; }
  .language-picker { min-width: 120px; }
  .topbar .button { min-height: 40px; padding: 8px 10px; }
  .app-shell { width: min(100% - 20px, 1100px); margin-top: 12px; }
  .summary-grid { gap: 7px; }
  .summary-card { padding: 12px 10px; border-radius: 11px; }
  .summary-card strong { font-size: 1.02rem; }
  .summary-card span { font-size: 0.68rem; }
  .panel { padding: 15px; border-radius: 13px; }
  .form-grid, .totals-layout { grid-template-columns: 1fr; }
  .cloud-auth-grid { grid-template-columns: 1fr; }
  .cloud-session-actions { width: 100%; }
  .cloud-session-actions .button { flex: 1; }
  .line-item { grid-template-columns: 1fr 1fr; padding: 11px; }
  .line-item .item-field, .line-item .description-field { grid-column: 1 / -1; }
  .line-item .amount { min-width: 0; }
  .signature-block { grid-template-columns: 1fr; }
  .action-panel { grid-template-columns: 1fr 1fr; }
  .action-panel .primary, .action-panel .gold { grid-column: 1 / -1; }
  .saved-quote { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .topbar { color: #000; background: #fff; border-bottom: 2px solid #000; padding: 0 0 12px; }
  .topbar .button, .topbar-actions, .summary-grid, .cloud-panel, .action-panel, .saved-panel, .remove-line, .add-trade-line, .save-status, .helper, .voice-actions, .recording-attachment, .support-note { display: none !important; }
  .app-shell { width: 100%; margin: 10px 0; }
  .panel { box-shadow: none; border-radius: 0; break-inside: avoid; }
  input, select, textarea { border: 0; padding: 2px 0; min-height: auto; appearance: none; }
  .trade-section { break-inside: avoid; border-radius: 0; }
  .trade-section summary { background: #fff; color: #000; border-bottom: 1px solid #000; padding: 6px 0; min-height: 0; }
  .trade-title::before { display: none; }
  .trade-total { color: #000; }
  .line-item { grid-template-columns: 1fr 1.5fr .5fr .6fr .7fr .7fr .7fr; break-inside: avoid; padding: 6px; }
  .signature-panel { break-inside: avoid; }
  .signature-input { min-height: 44px; border-bottom: 1px solid #000; }
}

.logo-area { display:flex; align-items:center; gap:24px; margin-bottom:22px; flex-wrap:wrap; }
.company-logo { max-width:220px; max-height:110px; object-fit:contain; }
.logo-controls { display:grid; gap:8px; }
.logo-controls small { color:#64748b; }
@media print { .logo-controls { display:none !important; } .company-logo { max-width:180px; max-height:90px; } }
