:root {
  color-scheme: light;
  --bg: #f7fafc;
  --surface: #ffffff;
  --text: #0b1728;
  --muted: #5b6b7d;
  --line: #dbe6ef;
  --cyan: #51c7f4;
  --cyan-deep: #0e7490;
  --green: #68c872;
  --green-deep: #2d8a46;
  --danger: #b33a3a;
  --warning-bg: #fff4dd;
  --warning-border: #e5c16b;
  --shadow: 0 18px 50px rgba(11, 23, 40, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Noto Sans", "Noto Sans Lao", system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
textarea { resize: none; min-height: 46px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--cyan-deep);
  box-shadow: 0 0 0 3px rgba(81, 199, 244, 0.22);
}
input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--cyan-deep); }
label { display: grid; gap: 7px; margin: 13px 0; color: var(--muted); font-size: 13px; }
a { color: inherit; text-decoration: none; }
.hidden, [hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 58px;
  padding: calc(8px + env(safe-area-inset-top)) max(16px, calc((100% - 920px) / 2)) 8px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { font-size: 19px; letter-spacing: 0.02em; }
.brand-copy small { color: var(--muted); font-size: 11px; letter-spacing: 0.07em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.icon-button {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}
.ui-language select {
  width: auto; min-width: 88px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 9px;
  font-size: 13px;
}

.workspace {
  display: flex; flex-direction: column;
  width: 100%; max-width: 920px;
  height: calc(100dvh - 58px);
  margin: 0 auto;
  padding: 0 max(14px, calc((100% - 840px) / 2));
}
.capability-banner {
  margin: 10px 0 2px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: #6a4b12;
  font-size: 12px;
}
.capability-banner.live {
  border-color: rgba(46, 139, 70, 0.28);
  background: #eaf8ef;
  color: #175c31;
}

.chat-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 2px 18px;
  scrollbar-width: thin;
}
.quick-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 4px 2px 10px;
}
.chip {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 13px;
  font-size: 13px;
}
.chip:hover { border-color: var(--cyan); }

.message {
  max-width: 86%;
  margin: 0 0 10px;
  padding: 11px 13px;
  border-radius: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
}
.message.assistant {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: var(--text);
}
.message.user {
  margin-left: auto;
  background: #e7f5fc;
  border: 1px solid #c7e7f5;
  border-bottom-right-radius: 5px;
}
.message.system { width: 100%; max-width: 100%; background: transparent; border: 0; padding: 6px 0; color: var(--muted); font-size: 12px; }
.message.error { background: #fdeeee; border-color: #f2c9c9; color: #7b2424; }

.composer-dock {
  flex-shrink: 0;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(247, 250, 252, 0), var(--bg) 22%);
}
.composer-inner {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  padding: 8px;
  box-shadow: var(--shadow);
}
.language-pair {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 2px 4px 7px;
  border: 0;
  border-radius: 8px;
  background: #eef6fb;
  color: var(--cyan-deep);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 700;
}
.composer-row { display: flex; align-items: flex-end; gap: 7px; }
.composer-input { flex: 1; display: flex; }
.composer-input textarea {
  border: 0;
  background: transparent;
  box-shadow: none;
  resize: none;
  max-height: 132px;
  min-height: 44px;
  padding: 10px 4px;
  font-size: 16px;
}
.composer-button, .send-button {
  flex: 0 0 44px;
  width: 44px; height: 44px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  display: grid; place-items: center;
  font-size: 19px;
}
.send-button {
  border-color: var(--cyan-deep);
  background: var(--cyan-deep);
  color: #fff;
}
.composer-button:disabled, .send-button:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-button.recording { border-color: #f2c9c9; background: #fdeeee; color: var(--danger); }
.options-link {
  display: block;
  margin: 6px 4px 1px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 15px;
  font-weight: 700;
  text-align: center;
}
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-primary { background: var(--cyan-deep); color: #fff; }
.button-secondary { border-color: var(--line); background: var(--surface); color: var(--text); }

.attachment-card, .quote-card, .result-box, .extracted-box {
  max-width: 86%;
  margin: 0 0 10px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
}
.quote-card { border-color: #b9e1f4; }
.attachment-preview { display: grid; gap: 8px; }
.attachment-preview img {
  width: 100%; max-height: 240px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f2f7fa;
}
.file-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; color: var(--muted); font-size: 12px; }
.attachment-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attachment-actions .button { min-height: 40px; font-size: 13px; }
.status-line { min-height: 20px; color: var(--muted); font-size: 13px; }
.status-line.error { color: var(--danger); }
.status-line.success { color: var(--green-deep); }
.recording-box { display: flex; align-items: center; gap: 10px; margin-top: 8px; color: var(--danger); font-weight: 600; }
.transcript-box { display: grid; gap: 7px; margin-top: 8px; }

.quote-total-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding-top: 10px; margin-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 18px; font-weight: 800;
}
.quote-breakdown { display: grid; gap: 6px; margin-top: 8px; }
.quote-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; }
.quote-row .estimated::after { content: " · ~"; color: var(--warning-border); }
.quote-expiry { color: var(--muted); font-size: 12px; margin-top: 8px; }
.quote-warning { color: #8a5b10; font-size: 12px; margin: 6px 0 0; }
.quote-reference { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.quote-total-row strong.unconfigured {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  white-space: normal;
  text-align: right;
  max-width: 72%;
}
.payment-box, .deliverable-box, .order-message-box {
  margin: 12px 0;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.payment-box h3, .deliverable-box h3, .order-message-box h3 { margin: 0 0 8px; font-size: 15px; }
.payment-qr {
  display: block;
  width: 180px;
  max-width: 65%;
  margin: 6px 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.payment-box .button, .deliverable-box .button { margin: 4px 6px 4px 0; }
.order-message { margin: 4px 0; color: var(--muted); font-size: 13px; }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(11, 23, 40, 0.4);
}
.bottom-sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 31;
  transform: translateX(-50%);
  width: min(100%, 600px);
  max-height: min(88dvh, 760px);
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  animation: sheet-in 180ms ease-out;
}
@keyframes sheet-in {
  from { transform: translate(-50%, 24px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.sheet-handle { width: 42px; height: 5px; border-radius: 999px; background: #cdd9e4; margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: #f1f5f8;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}
.sheet-note { color: var(--muted); font-size: 12px; margin: 10px 0; }
.privacy-notice {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid #c9dfea;
  border-radius: 14px;
  background: #f4fafc;
}
.privacy-notice h3 { margin: 0 0 7px; font-size: 15px; }
.privacy-notice p { margin: 0 0 8px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.privacy-notice .check-row { margin-top: 9px; }
.legal-links { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.legal-links a { color: var(--cyan-deep); font-weight: 600; }
.sheet-action:disabled { cursor: not-allowed; opacity: 0.48; }
.sheet-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0; }
.sheet-action {
  display: grid; place-items: center; gap: 7px;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.sheet-icon { font-size: 26px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; color: var(--text); font-size: 13px; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.local-orders { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.local-order {
  display: flex; align-items: center; gap: 8px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 7px 5px 11px;
  font-size: 12px;
}
.local-order button {
  border: 0; border-radius: 999px;
  background: #e7f5fc; color: var(--cyan-deep);
  padding: 4px 8px;
}

.order-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.order-head h2 { margin: 0; font-size: 20px; overflow-wrap: anywhere; }
.status-pill {
  display: inline-block; margin: 3px 5px 3px 0;
  border-radius: 999px; padding: 4px 9px;
  background: #e7f5fc; color: var(--cyan-deep);
  font-size: 12px;
}
.order-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.order-stat { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: #f9fbfd; }
.order-stat span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.order-stat strong { display: block; margin-top: 3px; overflow-wrap: anywhere; font-size: 13px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.action-row .button { flex: 1 1 160px; }
.result-box h3, .extracted-box h3 { margin: 0 0 6px; font-size: 15px; }
.result-box pre, .extracted-box pre {
  margin: 6px 0 0; padding: 0;
  background: transparent; color: var(--text);
  font-family: inherit; font-size: 15px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.simulation-label {
  display: inline-block; margin-bottom: 7px;
  border-radius: 999px; padding: 3px 8px;
  background: var(--warning-bg); color: #77500e;
  font-size: 11px;
}
.timeline { display: grid; gap: 7px; margin-top: 12px; }
.timeline-row { display: grid; grid-template-columns: 9px 1fr auto; gap: 8px; color: var(--muted); font-size: 12px; }
.timeline-dot { width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: var(--cyan-deep); }
.notice { color: var(--muted); font-size: 13px; }
.field-hint { color: var(--muted); font-size: 12px; }

.pricing-list { display: grid; gap: 8px; margin: 12px 0; }
.pricing-list div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 7px; }
.pricing-list dt { color: var(--muted); font-size: 13px; }
.pricing-list dd { margin: 0; font-weight: 700; text-align: right; }
.faq { padding: 9px 0; border-bottom: 1px solid var(--line); }
.faq summary { color: var(--text); font-weight: 600; cursor: pointer; }
.faq p { color: var(--muted); font-size: 13px; margin: 8px 0 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(118px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translateX(-50%);
  max-width: min(88%, 520px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.toast.error { background: #7b2424; }

@media (min-width: 800px) {
  .workspace { height: calc(100dvh - 58px); padding-bottom: 0; }
  .chat-messages { padding-right: 6px; }
  .message, .attachment-card, .quote-card, .result-box, .extracted-box { max-width: 72%; }
  .sheet-grid { grid-template-columns: repeat(4, 1fr); }
  .bottom-sheet { border-radius: 20px; bottom: 24px; top: auto; max-height: 720px; }
  .sheet-backdrop { backdrop-filter: blur(2px); }
}

@media (max-width: 400px) {
  .brand-logo { width: 42px; height: 42px; }
  .brand-copy strong { font-size: 17px; }
  .icon-button { width: 38px; height: 38px; }
  .ui-language select { min-width: 78px; padding: 7px 6px; }
  .composer-button, .send-button { width: 42px; height: 42px; flex-basis: 42px; }
  .sheet-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
