:root {
  --bg: #121214;
  --surface: #1a1a1e;
  --surface-hover: #222226;
  --surface-raised: #25252a;
  --white: #f2f2f0;
  --text: #e8e8e6;
  --text-secondary: #a0a0a0;
  --text-muted: #666668;
  --border: #2a2a2e;
  --border-light: #333338;
  --accent: #2d6a4f;
  --accent-bright: #40916c;
  --accent-surface: rgba(45,106,79,0.12);
  --red: #e63946;
  --red-surface: rgba(230,57,70,0.1);
  --orange: #d4840a;
  --orange-surface: rgba(212,132,10,0.1);
  --blue: #4472C4;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 4px;
  --radius-md: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --transition: 0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.5px;
}

.logo span { color: var(--accent-bright); }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 2px;
}

.tab-btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
}

.tab-btn:hover { color: var(--text); background: var(--surface-hover); }
.tab-btn.active { color: var(--white); background: var(--accent); }

/* Container */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* Form */
.form-section { display: none; }
.form-section.active { display: block; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 2px var(--accent-surface);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-group input.invalid,
.form-group select.invalid,
.form-group textarea.invalid {
  border-color: var(--red);
  box-shadow: 0 0 0 2px var(--red-surface);
}

/* Sections (SOW dynamic) */
.sow-sections { margin-top: 24px; }

.sow-section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  position: relative;
}

.sow-section-card .section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sow-section-card .section-number {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-bright);
  background: var(--accent-surface);
  padding: 2px 8px;
  border-radius: var(--radius);
  white-space: nowrap;
}

.sow-section-card .section-title-input {
  flex: 1;
}

.remove-section-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: var(--radius);
  transition: var(--transition);
}

.remove-section-btn:hover { color: var(--red); background: var(--red-surface); }

.bullet-list { margin-top: 8px; }

.bullet-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: flex-start;
}

.bullet-row textarea {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  min-height: 36px;
  resize: vertical;
}

.bullet-row textarea:focus {
  outline: none;
  border-color: var(--accent-bright);
}

.remove-bullet-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 6px;
  flex-shrink: 0;
  transition: var(--transition);
}

.remove-bullet-btn:hover { color: var(--red); }

.add-bullet-btn,
.add-section-btn {
  padding: 6px 12px;
  background: var(--accent-surface);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent-bright);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 6px;
}

.add-bullet-btn:hover,
.add-section-btn:hover {
  background: var(--accent);
  color: var(--white);
  border-style: solid;
}

.add-section-btn {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 13px;
  text-align: center;
}

.subtotal-row {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Actions */
.actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: var(--white);
}

.btn-primary:hover { background: var(--accent-bright); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-light); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Preview Modal — sized to 8.5×11" page */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  overflow-y: auto;
  padding: 20px;
}

.modal-overlay.active { display: flex; flex-direction: column; align-items: center; }

.modal {
  background: white;
  color: #111;
  border-radius: 4px;
  width: 8.5in;
  max-width: 100%;
  min-height: 11in;
  padding: 0.75in;
  font-family: 'Century Gothic', 'Segoe UI', sans-serif;
  font-size: 10pt;
  line-height: 1.5;
  position: relative;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  margin: 20px auto;
  flex-shrink: 0;
}

.modal-close {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface);
  color: var(--white);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal h1 { font-size: 14pt; text-align: center; margin-bottom: 16px; }
.modal h2 { font-size: 10pt; margin-top: 12px; display: inline; }
.modal p { margin-bottom: 8px; font-weight: bold; }
.modal .sig-block { margin-top: 32px; display: flex; gap: 40px; }
.modal .sig-col { flex: 1; }
.modal .sig-line { border-top: 1px solid #000; margin-top: 40px; padding-top: 4px; font-size: 9pt; }

/* SOW Preview styles */
.modal .sow-title { font-family: 'Roboto', sans-serif; font-size: 56pt; color: #3B66B8; font-weight: 900; line-height: 1.0; margin: 8px 0 14px; text-transform: uppercase; text-align: right; }
.modal .sow-title-client { color: #111; }
.modal .sow-meta { font-family: 'Inter', sans-serif; font-size: 8pt; font-weight: 500; margin-bottom: 2px; color: #A6A6A6; }
.modal .sow-meta b { color: #3B66B8; }
.modal .sow-section-head { font-family: 'Roboto', sans-serif; font-weight: 700; text-transform: uppercase; margin-top: 14px; margin-bottom: 6px; font-size: 10pt; color: #3B66B8; }
.modal .sow-bullet-list { font-family: 'Inter', sans-serif; margin: 0 0 4px 40px; padding: 0; list-style-type: disc; font-weight: 500; }
.modal .sow-bullet-list li { margin-bottom: 2px; padding-left: 8px; font-size: 10pt; line-height: 1.3; }
.modal .sow-body-text { font-family: 'Inter', sans-serif; font-weight: 500; margin-bottom: 10px; font-size: 10pt; line-height: 1.3; }
.modal .sow-pricing { font-family: 'Inter', sans-serif; font-weight: 500; margin-top: 14px; padding-top: 8px; }
.modal .sow-subtotal { font-weight: 500; font-size: 10pt; margin-bottom: 2px; }
.modal .sow-total { font-weight: 700; font-size: 11pt; margin-top: 8px; }
.modal .sow-payment-note { font-style: italic; font-weight: 400; font-size: 10pt; margin-top: 4px; color: #555; }
.modal .sow-exclusions { font-family: 'Inter', sans-serif; font-size: 7.5pt; font-style: italic; font-weight: 400; margin-top: 20px; color: #444; line-height: 1.3; }
.modal .sow-exclusions b { font-style: italic; color: #3B66B8; }
.modal .sow-badge { position: absolute; left: 0; top: 140px; height: calc(100% - 140px); width: auto; max-width: 60px; opacity: 0.12; pointer-events: none; object-fit: contain; object-position: top left; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--accent);
  color: var(--white);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ─── View Management ─────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ─── Login Screen ─────────────────────────────────────── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-box .logo {
  font-size: 20px;
  margin-bottom: 8px;
}

.login-box .login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-box input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  text-align: center;
  letter-spacing: 8px;
  margin-bottom: 16px;
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 2px var(--accent-surface);
}

.login-box .login-error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 20px;
}

/* ─── App Header (post-login) ──────────────────────────── */
.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-user .user-name {
  font-size: 13px;
  color: var(--text-secondary);
}

.header-nav {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 2px;
}

.nav-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
}

.nav-btn:hover { color: var(--text); background: var(--surface-hover); }
.nav-btn.active { color: var(--white); background: var(--accent); }

.btn-logout {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
}

.btn-logout:hover { color: var(--red); border-color: var(--red); }

/* ─── Dashboard ────────────────────────────────────────── */
.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
}

.filter-btn:hover { border-color: var(--border-light); color: var(--text); }
.filter-btn.active { background: var(--accent-surface); border-color: var(--accent); color: var(--accent-bright); }

.new-doc-btns { display: flex; gap: 8px; }

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-card:hover { border-color: var(--border-light); background: var(--surface-hover); }

.doc-type-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.doc-type-badge.msa { background: rgba(68,114,196,0.15); color: var(--blue); }
.doc-type-badge.sow { background: var(--orange-surface); color: var(--orange); }

.doc-card-info { flex: 1; min-width: 0; }

.doc-card-client {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  flex-shrink: 0;
}

.status-badge.draft { background: rgba(102,102,104,0.15); color: #999; }
.status-badge.sent { background: var(--orange-surface); color: var(--orange); }
.status-badge.partial { background: rgba(68,114,196,0.15); color: var(--blue); }
.status-badge.executed { background: var(--accent-surface); color: var(--accent-bright); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state p { font-size: 14px; margin-bottom: 4px; }
.empty-state .empty-hint { font-size: 12px; }

/* ─── Detail View ──────────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-header .back-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  transition: var(--transition);
}

.detail-header .back-btn:hover { color: var(--text); border-color: var(--border-light); }

.detail-header h2 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.detail-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.detail-controls select {
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}

.detail-controls select:focus { outline: none; border-color: var(--accent-bright); }

.detail-data {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

.detail-row {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 140px;
  flex-shrink: 0;
  text-transform: uppercase;
  font-size: 11px;
  padding-top: 2px;
}

.detail-value { color: var(--text); }

.detail-notes {
  margin-bottom: 16px;
}

.detail-notes label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-notes textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  min-height: 60px;
  resize: vertical;
}

.detail-notes textarea:focus {
  outline: none;
  border-color: var(--accent-bright);
}

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

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(230,57,70,0.3);
}

.btn-danger:hover { background: var(--red-surface); }

/* ─── Archive View ─────────────────────────────────────── */
.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.archive-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* ─── Loading Spinner ──────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-bright);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  justify-content: center;
  padding: 40px;
}

/* ─── MSA Logo ─────────────────────────────────────────── */
.msa-logo {
  text-align: center;
  margin-bottom: 20px;
}

/* ─── SOS Company Verification ─────────────────────────── */
.sos-verify-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

.sos-verify-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.sos-verify-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sos-verify-row select {
  width: 80px;
  flex-shrink: 0;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

.sos-verify-row select:focus {
  outline: none;
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 2px var(--accent-surface);
}

.sos-manual-link {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid rgba(68,114,196,0.3);
  border-radius: var(--radius);
  transition: var(--transition);
  margin-top: 10px;
}

.sos-manual-link:hover {
  background: rgba(68,114,196,0.1);
  border-color: var(--blue);
}

/* Responsive */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full-width { grid-column: 1; }
  .header-inner { flex-direction: column; gap: 8px; }
  .actions { flex-direction: column; }
  .modal { padding: 20px; }
  .sos-verify-row { flex-direction: column; }
  .sos-verify-row select { width: 100%; }
}

/* Address autocomplete dropdown */
.address-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 10000;
  margin-top: 4px;
  display: none;
  max-height: 240px;
  overflow-y: auto;
}
.address-dropdown-item {
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.address-dropdown-item:last-child { border-bottom: none; }
.address-dropdown-item:hover {
  background: var(--surface-hover);
}
