/* ============================================================
   ESTIMATE MANAGER — style.css
   Design system: formal business stationery aesthetic
   No frameworks, no build step.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --paper:     #FAF8F2;
  --card:      #FFFFFF;
  --ink:       #211D18;
  --ink-soft:  #5B564C;
  --ink-faint: #8D8778;
  --rule:      #DED5C0;
  --rule-soft: #EDE7D9;
  --seal:      #8C5A22;
  --seal-deep: #5E3C15;
  --seal-wash: #F4E9D8;
  --danger:    #9C4B3F;
  --focus:     #3A5A6B;
  --radius:    2px;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---------- View management ---------- */
.view { display: flex; flex-direction: column; min-height: 100vh; }
.view.hidden { display: none !important; }

/* ---------- Shared layout util ---------- */
.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- Shared buttons ---------- */
button.tool-btn {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
  white-space: nowrap;
  line-height: 1;
}
button.tool-btn:hover { border-color: var(--seal); }

button.tool-btn.primary {
  background: var(--seal);
  color: #fff;
  border-color: var(--seal);
}
button.tool-btn.primary:hover {
  background: var(--seal-deep);
  border-color: var(--seal-deep);
}

/* ghost: used for ← Back */
button.tool-btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  padding-left: 0;
}
button.tool-btn.ghost:hover {
  color: var(--ink);
  border-color: transparent;
  background: transparent;
}


/* ============================================================
   DASHBOARD VIEW
   ============================================================ */

/* Sticky header bar */
.dash-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 32px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* App name label — mono, uppercase, letter-spaced */
.app-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: .20em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Body area of dashboard */
.dash-body {
  flex: 1;
  padding: 44px 0 80px;
}

/* Section header row (title + count) */
.dash-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 22px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule-soft);
}
.dash-section-header h2 {
  font-family: 'Fraunces', serif;
  font-size: 20px;
  font-weight: 500;
  font-variation-settings: 'opsz' 20;
  color: var(--ink);
  margin: 0;
}
.dash-section-header .dash-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--ink-faint);
}

/* Responsive card grid */
.estimates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* ── Individual estimate card ── */
.estimate-card {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 20px 22px 0;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
  position: relative;
  /* Left accent stripe */
  border-left: 3px solid var(--rule);
}
.estimate-card:hover {
  border-left-color: var(--seal);
  border-color: var(--seal);
  box-shadow: 0 2px 16px -6px rgba(140,90,34,.18);
}
.estimate-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.card-eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--seal);
  margin-bottom: 3px;
}

.card-est-no {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.card-client {
  font-family: 'Inter', sans-serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-client-meta {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--ink-faint);
  margin-bottom: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 17px; /* preserve height when empty */
}

/* Date + total row */
.card-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-top: 1px solid var(--rule-soft);
}

.card-date {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--ink-faint);
}

.card-total {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  font-weight: 500;
  color: var(--seal-deep);
}

/* Card action buttons row */
.card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 0 14px;
  border-top: 1px solid var(--rule-soft);
}

.card-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
  line-height: 1.4;
}
.card-btn:hover { border-color: var(--seal); color: var(--seal); }
.card-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #fdf2f1;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 100px 20px;
}
.empty-state-title {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 400;
  font-variation-settings: 'opsz' 22;
  color: var(--ink-soft);
  margin: 0 0 8px;
}
.empty-state-sub {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--ink-faint);
  margin: 0;
}


/* ============================================================
   EDITOR VIEW
   ============================================================ */

/* Sticky toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 32px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Padding for editor wrap */
.editor-wrap {
  padding-top: 40px;
  padding-bottom: 80px;
}

/* The white document card */
.sheet {
  background: var(--card);
  border: 1px solid var(--rule);
  box-shadow:
    0 1px 2px rgba(33,29,24,.04),
    0 12px 32px -18px rgba(33,29,24,.18);
  padding: 56px 56px 44px;
}

/* ── Letterhead ── */
.letterhead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding-bottom: 26px;
  border-bottom: 2px solid var(--ink);
}

.brand input.biz-name {
  font-family: 'Fraunces', serif;
  font-size: 30px;
  font-weight: 600;
  font-variation-settings: 'opsz' 40;
  color: var(--ink);
  border: none;
  background: transparent;
  width: 100%;
  padding: 0;
  margin-bottom: 6px;
  display: block;
}

.brand textarea.biz-meta {
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  border: none;
  background: transparent;
  resize: none;
  width: 280px;
  height: 90px;
  padding: 0;
  display: block;
}

.doc-meta {
  text-align: right;
  min-width: 230px;
}

.doc-eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .18em;
  color: var(--seal);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.doc-meta .row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.doc-meta .row label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--ink-faint);
  width: 70px;
  text-align: left;
}

.doc-meta input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  border: none;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  text-align: right;
  padding: 2px 0;
  color: var(--ink);
  width: 130px;
}

/* Focus styles for all editable fields */
.doc-meta input:focus,
.brand input:focus,
.brand textarea:focus {
  outline: none;
  border-color: var(--focus);
}

/* ── Client details ── */
.parties {
  margin-top: 30px;
}

.party-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

/* Prefix dropdown + name input in one flex row */
.client-name-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 2px;
}

.client-name-row select#clientPrefix {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  padding: 5px 2px;
  cursor: pointer;
  appearance: auto;
}
.client-name-row select#clientPrefix:focus {
  outline: none;
  border-color: var(--focus);
}

.party input,
.party textarea {
  width: 100%;
  font-family: 'Inter', sans-serif;
  border: none;
  border-bottom: 1px solid var(--rule-soft);
  background: transparent;
  padding: 5px 2px;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 2px;
}
.party input.name-field {
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--rule);
  flex: 1;
}
.party textarea {
  resize: none;
  height: 56px;
  line-height: 1.55;
}
.party input:focus,
.party textarea:focus {
  outline: none;
  border-color: var(--focus);
}

/* ── Items table ── */
.items-block { margin-top: 34px; }

table.items {
  width: 100%;
  border-collapse: collapse;
}

table.items thead th {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: left;
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--ink);
}
table.items thead th.num { text-align: right; }

table.items td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}

table.items td input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  color: var(--ink);
  padding: 3px 0;
}
table.items td.num input {
  font-family: 'IBM Plex Mono', monospace;
  text-align: right;
}
table.items td input:focus {
  outline: none;
  background: var(--seal-wash);
}

td.amount-cell {
  font-family: 'IBM Plex Mono', monospace;
  text-align: right;
  font-size: 13.5px;
  white-space: nowrap;
}

td.item-no {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--ink-faint);
  text-align: center;
  padding-top: 12px;
}

td.remove-cell { width: 28px; text-align: center; }

.remove-row {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink-faint);
  font-size: 15px;
  line-height: 1;
  padding: 4px;
}
.remove-row:hover { color: var(--danger); }

.add-row-btn {
  margin-top: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: .04em;
  background: none;
  border: 1px dashed var(--rule);
  color: var(--ink-soft);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
}
.add-row-btn:hover { border-color: var(--seal); color: var(--seal); }

/* ── Totals ── */
.totals-wrap {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.totals { width: 290px; }

.totals .line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule-soft);
}
.totals .line label { font-family: 'Inter', sans-serif; }
.totals .val { font-family: 'IBM Plex Mono', monospace; }

.totals .grand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: 14px;
  margin-top: 4px;
  border-top: 2px solid var(--ink);
}

.totals .grand > label {
  font-family: 'Fraunces', serif;
  font-size: 16px;
  font-weight: 600;
  font-variation-settings: 'opsz' 16;
}

.grand-val {
  display: flex;
  align-items: baseline;
  gap: 1px;
}

.currency-fixed {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 19px;
  font-weight: 600;
  color: var(--seal-deep);
}

.grand-input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 19px;
  font-weight: 600;
  color: var(--seal-deep);
  border: none;
  background: transparent;
  width: 120px;
  text-align: right;
  padding: 0;
}
.grand-input:focus {
  outline: none;
  border-bottom: 1px solid var(--focus);
}

/* ── Terms & conditions ── */
.terms { margin-top: 38px; }

.terms textarea {
  width: 100%;
  min-height: 96px;
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-soft);
  border: 1px solid var(--rule-soft);
  background: var(--paper);
  padding: 12px 14px;
  resize: vertical;
  border-radius: var(--radius);
}
.terms textarea:focus {
  outline: none;
  border-color: var(--focus);
}


/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: .04em;
  padding: 10px 22px;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  body { background: #fff; }

  /* Hide UI chrome */
  .toolbar,
  .dash-topbar { display: none !important; }

  /* Flatten sheet */
  .sheet {
    box-shadow: none;
    border: none;
    padding: 24px 8px;
  }

  /* Hide interactive controls */
  .add-row-btn,
  .remove-row { display: none !important; }

  /* Ensure all text prints black */
  table.items td input,
  .brand input,
  .brand textarea,
  .party input,
  .party textarea,
  .doc-meta input,
  .terms textarea,
  .grand-input,
  .client-name-row select {
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Hide the dashboard entirely when printing from editor */
  #view-dashboard { display: none !important; }
}


/* ============================================================
   RESPONSIVE — below 720 px
   ============================================================ */
@media (max-width: 720px) {
  /* Dashboard */
  .dash-topbar { padding: 14px 16px; }
  .dash-body   { padding: 28px 0 60px; }
  .estimates-grid { grid-template-columns: 1fr; }

  /* Editor toolbar */
  .toolbar { padding: 10px 16px; }
  .toolbar-actions { gap: 6px; }
  button.tool-btn { padding: 8px 12px; font-size: 12px; }

  /* Sheet */
  .sheet { padding: 28px 20px; }

  /* Letterhead stacks vertically */
  .letterhead { flex-direction: column; }
  .doc-meta {
    text-align: left;
    width: 100%;
    min-width: 0;
  }
  .doc-meta .row { justify-content: flex-start; }
  .doc-meta input { text-align: left; }

  .brand textarea.biz-meta { width: 100%; }
}
