/* ==========================================================
   BRESLOW PROPOSAL MANAGER — UI STYLES
   (Shared: login, dashboard, editor chrome)
   ========================================================== */

:root {
  --brand: #1F4E79;
  --brand-dark: #163a5a;
  --accent: #2E75B6;
  --gold: #B8860B;
  --gold-light: #FFF4CC;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --surface: #ffffff;
  --bg: #f5f3ee;
  --danger: #C00000;
  --success: #2E7D32;
  --row-alt: #f9fafb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==========================================================
   LOGIN PAGE
   ========================================================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1F4E79 0%, #2E75B6 100%);
}
.login-card {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,.2);
  width: 100%;
  max-width: 400px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .kicker {
  font-family: 'Fraunces', serif;
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .04em;
}
.login-brand h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 28px;
  margin: 4px 0 0;
  color: var(--brand);
}
.login-card label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}
.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.login-card button:hover { background: var(--brand-dark); }
.login-card .error {
  background: #fef2f2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 6px;
  margin-top: 12px;
  font-size: 13px;
}
.login-card .hint {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.login-card .hint code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* ==========================================================
   ADMIN DASHBOARD
   ========================================================== */
.admin-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.admin-header .brand .kicker {
  font-family: 'Fraunces', serif;
  font-style: italic;
  color: var(--muted);
  font-size: 12px;
}
.admin-header .brand h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 22px;
  color: var(--brand);
  margin: 0;
}
.admin-nav { display: flex; gap: 8px; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 32px 80px;
}

/* stats */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.stat-num {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--brand);
}
.stat-lbl {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: .06em;
  margin-top: 2px;
}

/* search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: white;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,117,182,.1);
}
.search-bar button {
  padding: 10px 18px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.clear-search {
  padding: 10px 14px;
  color: var(--muted);
  align-self: center;
  font-size: 13px;
}

/* table */
.table-wrap {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  background: #fafafa;
  color: var(--muted);
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--row-alt); }
.cell-primary { font-weight: 600; color: var(--ink); }
.cell-secondary { font-size: 12px; color: var(--muted); margin-top: 2px; }
.actions-col { text-align: right; width: 280px; }
.actions-cell { text-align: right; white-space: nowrap; }
.action-btn {
  display: inline-block;
  padding: 6px 10px;
  margin-left: 4px;
  font-size: 12px;
  font-weight: 500;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
  transition: all .15s;
}
.action-btn:hover {
  background: var(--row-alt);
  border-color: var(--accent);
  color: var(--brand);
  text-decoration: none;
}
.action-btn.action-danger:hover {
  background: #fef2f2;
  border-color: var(--danger);
  color: var(--danger);
}

/* badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-gold   { background: #fef3c7; color: #92400e; }

/* empty state */
.empty-state {
  text-align: center;
  padding: 80px 40px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h2 {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  color: var(--brand);
  margin: 0 0 6px;
}
.empty-state p { color: var(--muted); margin-bottom: 20px; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary {
  background: var(--brand);
  color: white;
}
.btn-primary:hover {
  background: var(--brand-dark);
  text-decoration: none;
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--row-alt);
  text-decoration: none;
}
.btn-secondary {
  background: white;
  color: var(--ink);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--row-alt);
  text-decoration: none;
}
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--brand);
  color: white;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all .2s;
  z-index: 1000;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================
   EDITOR (form + live preview layout)
   ========================================================== */
.editor-page {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.editor-topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.back-link {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.back-link:hover { color: var(--brand); text-decoration: none; }
.editor-title {
  flex: 1;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-status {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  font-style: normal;
}
.save-status.saving { color: var(--gold); }
.save-status.saved { color: var(--success); }
.save-status.error { color: var(--danger); }

.editor-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.status-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  background: white;
  cursor: pointer;
}
.status-select:focus {
  outline: none;
  border-color: var(--accent);
}

.editor-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 400px 1fr;
  overflow: hidden;
}

.sidebar {
  background: white;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.form-body { padding: 20px 24px 60px; }

.section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; }
.section-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 15px;
  color: var(--brand);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: '';
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
}

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: white;
  transition: all .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}
.field textarea { resize: vertical; min-height: 60px; font-family: inherit; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* plan pills */
.plan-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 4px;
}
.plan-pills label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  background: white;
  transition: all .15s;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  margin-bottom: 0;
}
.plan-pills input { display: none; }
.plan-pills input:checked + span {
  color: var(--brand);
  font-weight: 700;
}
.plan-pills label:has(input:checked) {
  border-color: var(--accent);
  background: #EAF3FB;
  box-shadow: 0 0 0 2px rgba(46,117,182,.2);
}

/* toggle */
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--row-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 8px;
}
.toggle:hover { background: #f3f4f6; }
.toggle-label { font-size: 13px; font-weight: 500; }
.toggle-label small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  margin-top: 2px;
}
.toggle input { display: none; }
.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: #d1d5db;
  border-radius: 10px;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked ~ .toggle-switch { background: var(--accent); }
.toggle input:checked ~ .toggle-switch::after { transform: translateX(16px); }

/* client link box */
.client-link-box {
  background: #EAF3FB;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 14px;
}
.client-link-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 13px;
  color: var(--brand);
  margin-bottom: 6px;
}
.client-link-url {
  background: white;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  word-break: break-all;
  color: var(--ink);
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.client-link-box small {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* preview area */
.preview-area {
  overflow-y: auto;
  background: var(--bg);
  position: relative;
}
.preview-controls {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(245,243,238,.95);
  backdrop-filter: blur(4px);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
}
.page-wrap {
  max-width: 850px;
  margin: 0 auto;
  padding: 24px;
}

/* ==========================================================
   PUBLIC CLIENT VIEW
   ========================================================== */
.view-page {
  background: var(--bg);
  min-height: 100vh;
}
.view-toolbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}
.view-brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--brand);
}
.view-page .page-wrap {
  max-width: 850px;
  margin: 0 auto;
  padding: 24px;
}
.view-footer {
  text-align: center;
  padding: 30px 20px 60px;
  color: var(--muted);
  font-size: 13px;
}
.view-footer a { color: var(--brand); font-weight: 500; }

/* ==========================================================
   PRINT STYLES
   ========================================================== */
@media print {
  @page { size: letter; margin: 0.5in; }
  html, body {
    background: white !important;
    height: auto !important;
    overflow: visible !important;
  }
  .editor-topbar,
  .editor-layout .sidebar,
  .preview-controls,
  .view-toolbar,
  .view-footer,
  .admin-header,
  .toast,
  .editor-actions {
    display: none !important;
  }
  .editor-page { height: auto; overflow: visible; display: block; }
  .editor-layout {
    display: block;
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .preview-area { overflow: visible; background: white; padding: 0; }
  .page-wrap { max-width: none !important; padding: 0 !important; margin: 0 !important; }
  .page {
    box-shadow: none !important;
    padding: 0 !important;
    min-height: 0 !important;
    border-radius: 0 !important;
    background: white !important;
  }
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 960px) {
  .editor-layout { grid-template-columns: 1fr; overflow: visible; height: auto; }
  .editor-page { height: auto; overflow: visible; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; overflow-y: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .admin-header { flex-direction: column; gap: 12px; align-items: flex-start; padding: 16px 20px; }
  .container { padding: 16px; }
  .actions-col { width: auto; }
  .editor-topbar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .editor-actions { flex-wrap: wrap; }
}

/* Client view on phones */
@media (max-width: 640px) {
  .view-toolbar {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
    align-items: stretch;
  }
  .view-toolbar .view-brand {
    text-align: center;
    font-size: 14px;
  }
  .view-toolbar .view-actions,
  .view-toolbar .btn {
    width: 100%;
    justify-content: center;
  }
  .view-page .page-wrap {
    padding: 12px 8px 24px;
  }
  .view-footer {
    padding: 20px 16px 40px;
    font-size: 12px;
  }
  /* Allow page to flex to screen width */
  .page {
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    border-radius: 4px;
  }
}

/* Dashboard table on phones */
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .stat { padding: 10px 4px; }
  .stat-num { font-size: 20px; }
  .stat-lbl { font-size: 9px; }

  /* Hide less-important columns on tiny screens */
  .data-table th:nth-child(2),
  .data-table td:nth-child(2),
  .data-table th:nth-child(5),
  .data-table td:nth-child(5) {
    display: none;
  }
  .action-btn {
    padding: 6px 8px;
    font-size: 11px;
    margin-left: 2px;
  }
  .data-table td { padding: 10px 10px; }
  .data-table th { padding: 10px; }
}
