:root {
  --blue: #174f9e;
  --blue-dark: #103b78;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0eb;
  --surface: #ffffff;
  --background: #f3f6fa;
  --danger: #b42318;
  --shadow: 0 8px 26px rgba(22, 32, 51, 0.08);
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { margin: 0; color: var(--ink); background: var(--background); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 82px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { width: 96px; height: 58px; object-fit: contain; border-radius: 6px; background: #080b13; }
.brand h1 { margin: 0; font-size: clamp(1.15rem, 3vw, 1.6rem); line-height: 1.15; }
.brand p { margin: 3px 0 0; font-size: 0.78rem; font-weight: 700; color: var(--blue); letter-spacing: 0.05em; }
.header-actions { display: flex; gap: 8px; align-items: center; }

.app-shell { width: min(1180px, 100%); margin: 0 auto; padding: 18px 18px 112px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.estimate-banner { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; margin-bottom: 16px; }
.estimate-banner strong { display: block; font-size: 1.55rem; margin-top: 3px; }
.eyebrow { color: var(--blue); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; }
.estimate-date { text-align: right; color: var(--muted); font-weight: 650; }
.form-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-column { display: flex; flex-direction: column; gap: 16px; }
.form-section { padding: 18px; }
.form-section h2 { margin: 0 0 16px; font-size: 1.08rem; }

label { display: flex; flex-direction: column; gap: 7px; color: #344054; font-size: 0.88rem; font-weight: 700; }
label + label { margin-top: 13px; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid #b9c5d5;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 79, 158, 0.14); }
.two-up { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.two-up label + label { margin-top: 0; }

.pricing-card { border-color: #afc6e8; }
.summary-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; font-size: 1.02rem; }
.summary-row.muted { color: var(--muted); font-size: 0.92rem; }
.discount-row { display: grid; grid-template-columns: 1fr 90px; gap: 10px; padding: 10px 0; }
.discount-row label + label { margin-top: 0; }
.total-row { border-top: 2px solid var(--ink); margin-top: 7px; padding-top: 16px; font-size: 1.55rem; }
.total-row strong { color: var(--blue-dark); }

.button, .icon-button {
  min-height: 46px;
  border: 1px solid var(--blue);
  border-radius: 10px;
  padding: 10px 16px;
  color: var(--blue);
  background: #fff;
  font-weight: 750;
  cursor: pointer;
}
.button:hover, .icon-button:hover { background: #edf4ff; }
.button.primary { background: var(--blue); color: #fff; }
.button.primary:hover { background: var(--blue-dark); }
.button.secondary { color: #344054; border-color: #bdc7d5; }
.button.small { min-height: 38px; padding: 7px 10px; font-size: 0.82rem; }
.action-bar {
  position: fixed;
  z-index: 18;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100% - 24px));
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 14px 36px rgba(22, 32, 51, 0.2);
  backdrop-filter: blur(10px);
}
.action-bar .button { padding-left: 8px; padding-right: 8px; }

.modal { width: min(920px, calc(100% - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35); }
.modal::backdrop { background: rgba(11, 16, 32, 0.66); backdrop-filter: blur(2px); }
.modal-header { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.close-button { width: 44px; height: 44px; border: 0; border-radius: 50%; background: #edf1f6; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; background: #fff; border-top: 1px solid var(--line); }
.preview-content { padding: 20px; background: #eef2f7; overflow: auto; }
.settings-scroll { max-height: calc(100vh - 150px); padding: 20px; overflow: auto; }
.settings-section + .settings-section { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 24px; }
.settings-section h3 { margin: 0 0 15px; }
.settings-section p { margin: 4px 0 0; color: var(--muted); font-size: 0.86rem; }
.section-heading-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.pricing-settings { display: grid; gap: 10px; }
.pricing-setting-row { display: grid; grid-template-columns: 150px minmax(160px, 1fr) 185px; gap: 10px; align-items: end; padding: 11px; border: 1px solid var(--line); border-radius: 11px; }
.pricing-setting-row > strong { align-self: center; font-size: 0.88rem; }
.pricing-setting-row label { font-size: 0.78rem; }
.pricing-setting-row input { min-height: 42px; }
.sticky-actions { position: sticky; bottom: 0; }

.history-list { min-height: 180px; max-height: 70vh; overflow: auto; padding: 16px; }
.history-empty { color: var(--muted); text-align: center; padding: 48px 20px; }
.history-card { display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.history-card + .history-card { margin-top: 10px; }
.history-card .number { color: var(--blue); font-weight: 800; }
.history-card h3 { margin: 0 0 3px; font-size: 1rem; }
.history-card p { margin: 0; color: var(--muted); font-size: 0.82rem; }
.history-card .history-total { font-weight: 800; font-size: 1.08rem; text-align: right; }
.history-card button { grid-column: 3; }

.estimate-sheet, .customer-estimate {
  width: 8.5in;
  min-height: 11in;
  margin: 0 auto;
  padding: 0.5in;
  color: #111827;
  background: #fff;
  font-family: Arial, sans-serif;
}
.estimate-sheet { display: none; width: auto; min-height: 0; padding: 0; }
.customer-estimate { min-height: auto; width: min(8.5in, 100%); box-shadow: 0 12px 30px rgba(0,0,0,.15); }
.document-header { display: grid; grid-template-columns: 220px 1fr; gap: 22px; align-items: start; }
.document-logo { max-width: 210px; max-height: 92px; object-fit: contain; object-position: left top; }
.company-contact { min-width: 0; text-align: right; font-size: 10pt; line-height: 1.4; overflow-wrap: anywhere; }
.document-title { text-align: center; margin: 14px 0 18px; }
.document-title h1 { margin: 0; font-size: 20pt; }
.document-title p { margin: 4px 0 0; font-size: 12pt; font-weight: 700; letter-spacing: .08em; }
.document-info { display: grid; grid-template-columns: 1.7fr 1fr; gap: 12px; padding: 12px; border: 1px solid #9ca3af; background: #f6f7f9; font-size: 10pt; line-height: 1.45; }
.document-info .estimate-meta { text-align: right; }
.line-items { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 18px; font-size: 9.5pt; }
.line-items th:first-child { width: 43%; }
.line-items th, .line-items td { padding: 8px 7px; border: 1px solid #d1d5db; }
.line-items th { background: #e9edf2; text-align: left; }
.line-items th:not(:first-child), .line-items td:not(:first-child) { text-align: right; }
.document-totals { width: 240px; margin: 18px 0 0 auto; border-collapse: collapse; font-size: 10pt; }
.document-totals td { padding: 6px; text-align: right; }
.document-totals .grand-total td { border-top: 1.5px solid #111; font-size: 13pt; font-weight: 800; }
.document-notes { margin-top: 18px; font-size: 9.5pt; line-height: 1.45; }
.document-footer { margin-top: 22px; text-align: center; font-size: 8.5pt; color: #4b5563; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 92px; transform: translate(-50%, 24px); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 10px; color: #fff; background: #172033; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }

@media (max-width: 760px) {
  .app-header { align-items: flex-start; }
  .brand img { width: 72px; height: 48px; }
  .brand p { display: none; }
  .header-actions { flex-direction: column; align-items: stretch; }
  .header-actions button { min-height: 38px; padding: 7px 10px; font-size: .8rem; }
  .app-shell { padding: 12px 12px 116px; }
  .form-layout { grid-template-columns: 1fr; }
  .two-up { grid-template-columns: 1fr; }
  .two-up label + label { margin-top: 0; }
  .action-bar { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .action-bar .button { min-height: 50px; font-size: .76rem; padding: 6px 3px; }
  .pricing-setting-row { grid-template-columns: 1fr; }
  .section-heading-row { flex-direction: column; }
  .history-card { grid-template-columns: 72px 1fr; }
  .history-card .history-total { grid-column: 1 / -1; text-align: left; }
  .history-card button { grid-column: 1 / -1; }
  .customer-estimate { padding: 22px 16px; }
  .document-header { grid-template-columns: 106px minmax(0, 1fr); gap: 12px; }
  .document-logo { max-width: 102px; max-height: 64px; }
  .company-contact { font-size: 7.5pt; }
  .document-info { grid-template-columns: 1fr; }
  .document-info .estimate-meta { text-align: left; }
  .line-items { font-size: 8pt; }
  .line-items th, .line-items td { padding: 6px 4px; }
}

@media print {
  @page { size: letter; margin: 0; }
  body { background: #fff; }
  .no-print, dialog, .toast { display: none !important; }
  .estimate-sheet { display: block !important; margin: 0; box-shadow: none; }
}
