@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;500;600;700;800;900&display=swap");

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #17202c;
  --muted: #667085;
  --line: #d8dee8;
  --line-strong: #202a37;
  --brand: #d71920;
  --brand-dark: #a70f16;
  --brand-soft: #fff1f2;
  --ink: #111827;
  --ok: #0f8a5f;
  --warn: #b7791f;
  --danger: #b42318;
  --blue: #2563eb;
  --shadow: 0 16px 42px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --font: "Noto Sans Thai", "Sarabun", "Leelawadee UI", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #ffffff 0, #f7f9fc 260px, var(--bg) 100%);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hidden {
  display: none !important;
}

.login-screen,
.setup-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(135deg, rgba(215, 25, 32, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(29, 78, 216, 0.08), transparent 38%),
    #f7f9fc;
}

.login-card,
.setup-panel {
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.setup-panel img,
.login-brand img {
  width: 72px;
  height: 48px;
  object-fit: contain;
}

.login-brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.login-brand h1,
.setup-panel h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

.login-brand p,
.setup-panel p {
  margin: 5px 0 0;
  color: var(--muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #eef2f7;
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 18px;
}

.auth-tab {
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 10px;
  font-weight: 700;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 12px rgba(16, 24, 40, 0.08);
}

.auth-form,
.compact-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.02);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #84a8ff;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.auth-form button,
.setup-panel button,
.topbar-actions button,
.editor-actions button,
.section-heading button,
.compact-form button,
#saveTermsBtn,
.report-filters button {
  background: var(--brand);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  box-shadow: 0 10px 20px rgba(215, 25, 32, 0.18);
}

.text-button {
  background: transparent;
  color: var(--blue);
  margin-top: 12px;
  padding: 8px 0;
  font-weight: 700;
}

.form-message {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

code {
  display: block;
  margin: 14px 0;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  overflow-wrap: anywhere;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  padding: 18px 16px;
  border-right: 1px solid var(--line);
  box-shadow: 10px 0 30px rgba(15, 23, 42, 0.04);
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 26px;
}

.brand-mark {
  width: 62px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.brand-mark img {
  width: 52px;
  height: 32px;
  object-fit: contain;
}

.sidebar-brand strong {
  display: block;
  font-size: 18px;
}

.sidebar-brand span {
  color: var(--muted);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #475467;
  border-radius: 8px;
  padding: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}

.nav-item.active,
.nav-item:hover {
  background: #fff5f5;
  color: var(--brand-dark);
  border-color: #ffd1d3;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.sidebar-footer strong {
  color: var(--text);
}

.sidebar-footer button {
  background: #253244;
  color: white;
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 800;
}

.content {
  min-width: 0;
  padding: 24px 28px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
}

.topbar p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.topbar-actions button:nth-child(2) {
  background: #253244;
  box-shadow: 0 10px 20px rgba(37, 50, 68, 0.16);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.workspace-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.quote-list-panel,
.quote-editor,
.data-panel,
.report-filters,
.editor-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.quote-list-panel {
  position: sticky;
  top: 24px;
  padding: 16px;
}

.panel-title-row,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-title-row h2,
.section-heading h2,
.data-panel h2 {
  margin: 0;
  font-size: 17px;
}

.panel-title-row span {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  background: #eef2f7;
  border-radius: 99px;
  font-weight: 900;
}

.quote-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.quote-card {
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.03);
}

.quote-card.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.12);
}

.quote-card-head,
.quote-card strong,
.quote-card span,
.quote-card small {
  display: block;
}

.quote-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.quote-card strong {
  font-size: 14px;
}

.quote-card em {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #fff5f5;
  color: var(--brand-dark);
  border: 1px solid #ffd1d3;
  padding: 3px 8px;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.quote-card span {
  margin-top: 4px;
  color: var(--text);
}

.quote-card small {
  color: var(--muted);
}

.quote-editor {
  display: grid;
  gap: 12px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.editor-band {
  padding: 18px 20px;
}

.editor-band .section-heading {
  border-bottom: 1px solid #edf1f6;
  padding-bottom: 12px;
}

.section-heading h2::before,
.panel-title-row h2::before,
.data-panel h2::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 16px;
  margin-right: 8px;
  border-radius: 99px;
  background: var(--brand);
  vertical-align: -2px;
}

.document-strip {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(260px, 1.2fr);
  gap: 12px;
  align-items: stretch;
}

.document-tile,
.document-strip p {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
  padding: 14px 16px;
}

.document-tile {
  border-left: 4px solid var(--brand);
}

.document-tile span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.document-tile strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
  letter-spacing: 0;
}

.document-tile.muted-tile {
  border-left-color: #cbd5e1;
  opacity: 0.72;
}

.document-strip p {
  display: grid;
  align-items: center;
  color: #475467;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.55;
}

.agent-section {
  border-left: 4px solid #f59e0b;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: span 3;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 99px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.pending {
  background: #fff7ed;
  color: var(--warn);
}

.status-pill.approved {
  background: #ecfdf3;
  color: var(--ok);
}

.status-pill.rejected {
  background: #fef3f2;
  color: var(--danger);
}

.line-table-wrap {
  margin-top: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.03);
}

.line-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.line-table th,
.line-table td,
.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  vertical-align: top;
  font-size: 13px;
}

.line-table th,
.data-table th {
  background: #f2f5f9;
  text-align: left;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
}

.line-table input,
.line-table select {
  min-width: 100px;
  padding: 8px;
}

.line-table .code-input {
  min-width: 140px;
}

.line-table .name-input {
  min-width: 260px;
}

.line-table .number-input {
  min-width: 92px;
  text-align: right;
}

.line-table .remove-line {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #fef3f2;
  color: var(--danger);
  font-weight: 900;
  box-shadow: none;
}

.agent-pricing-table th {
  background: #eef3f9;
  color: #182230;
}

.agent-line-row > td {
  padding: 0;
  background: #f8fafc;
}

.agent-line-item {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.agent-line-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #111827;
  padding-bottom: 2px;
}

.agent-product-row,
.agent-price-row {
  display: grid;
  gap: 10px;
  align-items: end;
}

.agent-product-row {
  grid-template-columns: 160px minmax(280px, 1fr) 160px 110px 110px;
}

.agent-price-row {
  grid-template-columns: minmax(210px, 1fr) 130px 130px 130px 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.agent-price-row--dealer {
  border-left: 4px solid var(--brand);
}

.agent-price-row--customer {
  border-left: 4px solid var(--blue);
  grid-template-columns: minmax(210px, 1fr) 130px 130px 140px;
}

.agent-price-label strong,
.agent-price-total strong {
  display: block;
  color: #111827;
}

.agent-price-label span,
.agent-price-total span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.agent-price-total {
  min-height: 42px;
  display: grid;
  align-content: center;
  justify-items: end;
  border-left: 1px solid var(--line);
  padding-left: 10px;
  background: #f8fafc;
  border-radius: 6px;
  padding: 8px 10px;
}

.agent-total,
.customer-total {
  font-size: 15px;
}

.summary-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.summary-panel {
  display: grid;
  gap: 0;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  align-self: start;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.06);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #edf1f6;
  padding: 10px 0;
  font-size: 13px;
}

.summary-row strong {
  white-space: nowrap;
  color: #111827;
}

.summary-row.total {
  border: 0;
  font-size: 18px;
  color: var(--brand-dark);
  padding-top: 12px;
}

.summary-row.total strong {
  color: var(--brand-dark);
}

.summary-row.summary-note {
  color: var(--blue);
  font-weight: 800;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
}

.outcome-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.outcome-control button {
  min-height: 38px;
  border-radius: 7px;
  background: #fff;
  color: #475467;
  border: 1px solid var(--line);
  font-weight: 900;
}

.outcome-control button.active {
  background: #111827;
  color: #fff;
  border-color: #111827;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.16);
}

.outcome-control button[data-outcome="win"].active {
  background: var(--ok);
  border-color: var(--ok);
}

.outcome-control button[data-outcome="loss"].active {
  background: var(--danger);
  border-color: var(--danger);
}

.danger-alert {
  margin: 14px 0 0;
  border: 1px solid #fda29b;
  background: #fff1f0;
  color: var(--danger);
  border-radius: 8px;
  padding: 12px;
  font-weight: 800;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 0 24px;
}

.editor-actions button:nth-child(2) {
  background: #253244;
  box-shadow: 0 10px 20px rgba(37, 50, 68, 0.16);
}

.editor-actions button:nth-child(3) {
  background: var(--ok);
  box-shadow: 0 10px 20px rgba(15, 138, 95, 0.16);
}

.danger-button {
  background: #fef3f2 !important;
  color: var(--danger) !important;
}

.report-filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.data-panel {
  padding: 16px;
}

.import-panel {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-left: 4px solid var(--blue);
}

.import-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.import-actions button {
  background: #111827;
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
  white-space: nowrap;
}

.masters-view .master-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.full-width {
  grid-column: 1 / -1;
}

.compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 12px 0;
}

.compact-form textarea,
.compact-form button {
  grid-column: 1 / -1;
}

.master-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.master-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.master-row small {
  display: block;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  background: #e2e8f0;
  color: #334155;
  border-radius: 7px;
  padding: 7px 9px;
  font-weight: 800;
}

.row-actions .delete-small {
  background: #fef3f2;
  color: var(--danger);
}

.terms-editor {
  margin: 12px 0;
}

.bulk-import-panel p {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.bulk-import-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.bulk-import-grid button {
  min-height: 42px;
  background: #253244;
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 800;
}

.bulk-import-grid .secondary-action {
  background: #eef2f7;
  color: #253244;
  border: 1px solid #cbd5e1;
}

.bulk-import-example {
  border: 1px solid #d7dee8;
  background: #f8fafc;
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.bulk-import-example-head {
  border-bottom: 1px solid #d7dee8;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
  padding: 8px 10px;
}

.bulk-import-example pre {
  margin: 0;
  max-height: 150px;
  overflow: auto;
  padding: 10px;
  color: #111827;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}

.bulk-import-textarea {
  min-height: 180px;
  font-family: "SFMono-Regular", Consolas, monospace;
  line-height: 1.55;
  white-space: pre;
}

/* Polished production UI */
.app-shell {
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid #e4e9f1;
  padding: 20px 16px;
}

.brand-mark {
  border-color: #eef1f5;
  box-shadow: 0 8px 18px rgba(16, 24, 40, 0.05);
}

.sidebar-brand strong {
  color: #141b24;
  font-size: 19px;
  font-weight: 900;
}

.sidebar-brand span,
.sidebar-footer {
  font-weight: 600;
}

.nav-item {
  min-height: 42px;
  border-radius: 7px;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 800;
}

.nav-item.active,
.nav-item:hover {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-color: #ffc9cf;
}

.content {
  padding: 22px 28px 36px;
}

.topbar {
  border-color: #e6ebf2;
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.06);
}

.topbar p {
  color: #697386;
  font-size: 12px;
  font-weight: 800;
}

.topbar h1 {
  color: #121a26;
  font-size: 25px;
  font-weight: 900;
}

.topbar-actions button,
.editor-actions button,
.section-heading button,
.compact-form button,
#saveTermsBtn,
.report-filters button,
.auth-form button,
.setup-panel button {
  min-height: 40px;
  border-radius: 7px;
  padding: 10px 15px;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(215, 25, 32, 0.16);
}

.workspace-layout {
  grid-template-columns: 296px minmax(760px, 1fr);
  gap: 18px;
}

.quote-list-panel,
.quote-editor,
.data-panel,
.report-filters,
.editor-band {
  border-color: #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.055);
}

.quote-list-panel {
  padding: 15px;
}

.quote-card {
  border-color: #e6ebf2;
  border-radius: 8px;
  padding: 12px 13px;
}

.quote-card.active {
  border-color: #e65b61;
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.1);
}

.quote-card strong {
  color: #121a26;
  font-weight: 900;
}

.quote-editor {
  gap: 14px;
}

.document-strip {
  grid-template-columns: minmax(210px, 0.9fr) minmax(210px, 0.9fr) minmax(320px, 1.2fr);
  gap: 12px;
}

.document-tile,
.document-strip p {
  border-color: #e1e7ef;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));
  box-shadow: 0 14px 30px rgba(16, 24, 40, 0.06);
  padding: 15px 16px;
}

.document-tile {
  position: relative;
  overflow: hidden;
  border-left: 0;
}

.document-tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--brand);
}

.document-tile:nth-child(2)::before {
  background: #2f6fed;
}

.document-tile span {
  color: #667085;
  font-size: 11px;
  font-weight: 900;
}

.document-tile strong {
  margin-top: 6px;
  color: #121a26;
  font-size: 21px;
  font-weight: 900;
  line-height: 1.15;
}

.document-strip p {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.65;
}

.editor-band {
  padding: 18px 20px 20px;
}

.editor-band .section-heading {
  padding-bottom: 12px;
}

.panel-title-row h2,
.section-heading h2,
.data-panel h2 {
  color: #121a26;
  font-size: 16px;
  font-weight: 900;
}

.form-grid {
  gap: 13px 14px;
}

label {
  gap: 7px;
  color: #586474;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  min-height: 40px;
  border-color: #d7dee8;
  border-radius: 7px;
  background: #ffffff;
  padding: 9px 11px;
  color: #111827;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.02);
}

textarea {
  line-height: 1.55;
}

input[readonly] {
  background: #f3f6fa;
  color: #475467;
  font-weight: 800;
}

input::placeholder,
textarea::placeholder {
  color: #98a2b3;
  font-weight: 500;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #e65b61;
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.1);
}

.status-pill {
  border-radius: 7px;
  font-size: 11px;
  font-weight: 900;
}

.line-table-wrap {
  border-color: #d9e1ec;
  border-radius: 9px;
  box-shadow: none;
}

.line-table th,
.data-table th {
  background: #f6f8fb;
  color: #273549;
  font-size: 11px;
  letter-spacing: 0;
}

.line-table th,
.line-table td,
.data-table th,
.data-table td {
  padding: 8px;
  font-size: 12.5px;
}

.line-table input,
.line-table select {
  min-height: 36px;
  padding: 7px 8px;
  font-size: 12.5px;
}

.line-table .code-input {
  min-width: 155px;
  color: var(--brand-dark);
  font-weight: 900;
}

.line-table .name-input {
  min-width: 320px;
}

.summary-layout {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.summary-panel {
  border-color: #dfe6ef;
  border-radius: 9px;
  padding: 8px 15px;
}

.summary-row {
  font-size: 12.5px;
}

.summary-row.total {
  font-size: 19px;
}

.checkbox-field,
.outcome-control {
  border-radius: 8px;
  border-color: #dfe6ef;
}

/* 100% viewport fit and modern bottom actions */
.app-shell {
  grid-template-columns: 238px minmax(0, 1fr);
  overflow-x: hidden;
}

.content {
  min-width: 0;
  overflow-x: hidden;
  padding: 20px clamp(16px, 2vw, 26px) 34px;
}

.workspace-layout {
  grid-template-columns: minmax(236px, 282px) minmax(0, 1fr);
  max-width: 100%;
}

.quote-editor,
.editor-band,
.summary-layout {
  min-width: 0;
}

.line-table-wrap {
  max-width: 100%;
}

.editor-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 14px 16px;
  border: 1px solid #dfe6ef;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -12px 34px rgba(16, 24, 40, 0.08);
  backdrop-filter: blur(10px);
}

.editor-actions button {
  min-width: 112px;
}

.editor-actions .primary-action {
  background: var(--brand);
}

.editor-actions .dark-action {
  background: #253244;
  box-shadow: 0 10px 20px rgba(37, 50, 68, 0.16);
}

.editor-actions .success-action {
  background: var(--ok);
  box-shadow: 0 10px 20px rgba(15, 138, 95, 0.16);
}

.editor-actions .print-action {
  margin-left: auto;
  background: #111827;
  box-shadow: 0 10px 20px rgba(17, 24, 39, 0.18);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: 420px;
  border-radius: 10px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  padding: 13px 16px;
  font-weight: 800;
}

.print-sheet {
  display: none;
}

@media (max-width: 1200px) {
  .workspace-layout,
  .summary-layout,
  .document-strip,
  .report-filters,
  .metric-grid,
  .masters-view .master-grid {
    grid-template-columns: 1fr;
  }

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

  .bulk-import-grid label {
    grid-column: 1 / -1;
  }

  .quote-list-panel {
    position: static;
  }

  .agent-product-row,
  .agent-price-row,
  .agent-price-row--customer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .agent-price-label,
  .agent-price-total {
    grid-column: 1 / -1;
  }

  .agent-price-total {
    justify-items: start;
    border-left: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .form-grid,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .span-2,
  .span-3,
  .full-width {
    grid-column: auto;
  }

  .content {
    padding: 14px;
  }

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

  .topbar-actions,
  .editor-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .editor-actions .print-action {
    margin-left: 0;
  }

  .bulk-import-grid {
    grid-template-columns: 1fr;
  }

  .bulk-import-grid label {
    grid-column: auto;
  }

  .import-panel {
    align-items: stretch;
    flex-direction: column;
  }
}

@media print {
  body {
    background: white;
  }

  .app-shell,
  .login-screen,
  .setup-screen,
  .toast {
    display: none !important;
  }

  .print-sheet {
    display: block;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 8mm 8mm 7mm;
    background: white;
    color: #111827;
    font-family: "Noto Sans Thai", "Tahoma", sans-serif;
    font-size: 8.4px;
    line-height: 1.26;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }

  .print-document {
    display: grid;
    grid-template-rows: auto auto auto auto auto auto;
    align-content: start;
    min-height: 282mm;
    border: 1px solid #111827;
    break-after: page;
  }

  .print-document:last-child {
    break-after: auto;
  }

  .print-header {
    display: grid;
    grid-template-columns: 1.45fr 0.65fr;
    border-bottom: 1px solid #111827;
  }

  .print-company,
  .print-title {
    padding: 5px 7px;
  }

  .print-company {
    display: grid;
    grid-template-columns: 62px 1fr;
    gap: 7px;
    align-items: start;
    border-right: 1px solid #111827;
  }

  .print-logo {
    width: 58px;
    height: 37px;
    display: grid;
    place-items: center;
  }

  .print-logo img {
    width: 58px;
    height: 37px;
    object-fit: contain;
  }

  .print-logo span {
    display: none;
    color: #d71920;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 0;
  }

  .print-company strong,
  .print-title strong {
    display: block;
    font-size: 10px;
    line-height: 1.25;
  }

  .print-company div:last-child {
    line-height: 1.2;
  }

  .print-company span {
    font-size: 8px;
    line-height: 1.2;
  }

  .print-title {
    display: grid;
    align-content: center;
    justify-items: center;
    text-align: center;
    background: #fbfcfe;
  }

  .print-title span {
    font-size: 9.2px;
    font-weight: 800;
  }

  .print-title h1 {
    margin: 1px 0 2px;
    color: #111827;
    font-size: 17px;
    letter-spacing: 0;
    line-height: 1.05;
  }

  .print-title strong {
    min-width: 76%;
    border-top: 1px solid #111827;
    padding-top: 3px;
    font-size: 8.2px;
    font-weight: 800;
  }

  .print-info-grid {
    display: grid;
    grid-template-columns: 1.08fr 1.08fr 0.92fr 0.92fr;
    border-bottom: 1px solid #111827;
  }

  .print-box {
    min-height: 20px;
    padding: 3.2px 5px;
    border-right: 1px solid #111827;
    border-bottom: 1px solid #111827;
  }

  .print-box:nth-child(4n) {
    border-right: 1px solid #111827;
  }

  .print-box--span-2 {
    grid-column: span 2;
  }

  .print-box label {
    display: block;
    color: #2f3847;
    font-size: 7px;
    font-weight: 800;
    line-height: 1.15;
  }

  .print-box strong {
    display: block;
    margin-top: 1px;
    color: #111827;
    font-size: 8.5px;
    font-weight: 800;
    line-height: 1.18;
  }

  .print-lines {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    border-bottom: 1px solid #111827;
  }

  .print-lines th,
  .print-lines td {
    border-right: 1px solid #111827;
    border-bottom: 1px solid #111827;
    padding: 3px 4.5px;
    vertical-align: top;
    overflow-wrap: anywhere;
  }

  .print-lines th {
    text-align: center;
    font-size: 7.5px;
    line-height: 1.15;
    background: #f6f7f9;
  }

  .print-lines tbody tr {
    height: 6.2mm;
  }

  .print-lines td {
    font-size: 8.1px;
    line-height: 1.18;
  }

  .print-lines td:nth-child(1),
  .print-lines td:nth-child(4),
  .print-lines td:nth-child(5) {
    vertical-align: middle;
  }

  .print-lines td:last-child,
  .print-lines th:last-child {
    border-right: 0;
  }

  .num {
    text-align: right;
  }

  .center {
    text-align: center;
  }

  .print-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid #111827;
  }

  .print-terms,
  .print-totals {
    padding: 6px;
  }

  .print-terms {
    border-right: 1px solid #111827;
    white-space: pre-line;
    font-size: 7.8px;
  }

  .print-total-row {
    display: grid;
    grid-template-columns: 1fr 90px;
    border-bottom: 1px solid #111827;
  }

  .print-total-row span,
  .print-total-row strong {
    padding: 4px;
  }

  .print-total-row strong {
    text-align: right;
    border-left: 1px solid #111827;
  }

  .print-approvals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 7px 10px;
    border-top: 1px solid #111827;
  }

  .signature-box {
    min-height: 43px;
    border: 1px solid #111827;
    border-radius: 5px;
    padding: 6px;
    text-align: center;
  }

  .signature-line {
    min-height: 15px;
    margin-top: 10px;
    border-top: 1px solid #111827;
    padding-top: 4px;
  }

  .signature-box small {
    display: block;
    margin-top: 3px;
    font-size: 7.4px;
  }

  .signature-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 5px;
    font-size: 7.4px;
  }

  .purchase-confirmation {
    border-top: 1px solid #111827;
    padding: 7px 10px 6px;
  }

  .purchase-confirmation h3 {
    margin: 0 0 3px;
    color: #d71920;
    font-size: 9.4px;
    line-height: 1.2;
  }

  .purchase-confirmation h3 span {
    margin-left: 5px;
    font-size: 9px;
    font-weight: 900;
  }

  .purchase-confirmation p {
    margin: 0 0 10px;
    font-size: 7.8px;
  }

  .purchase-fields {
    display: grid;
    grid-template-columns: 1.25fr 0.85fr 0.85fr;
    gap: 14px 16px;
  }

  .purchase-line {
    height: 16px;
    border-bottom: 1px solid #111827;
    margin-bottom: 3px;
  }

  .purchase-field strong,
  .purchase-field small {
    display: block;
    font-size: 7.3px;
    line-height: 1.15;
  }

  .purchase-field small {
    color: #374151;
  }
}
