:root {
  --bg: #0b0c0f; --panel: #15171c; --border: #262a33; --text: #e8eaed;
  --muted: #9aa1ac; --accent: #6ea8fe; --good: #3ecf8e; --warn: #f2b84b; --bad: #ef6461;
}
:root[data-theme="light"] {
  --bg: #f5f6f8; --panel: #ffffff; --border: #dde1e6; --text: #14161a;
  --muted: #5b6270; --accent: #2f6fe4; --good: #1f9d63; --warn: #b3780a; --bad: #d1453b;
}
:root[data-theme="light"] .sidebar nav a.active { background: rgba(47,111,228,0.08); }
:root[data-theme="light"] tbody tr.clickable:hover { background: rgba(0,0,0,0.03); }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; border-right: 1px solid var(--border); padding: 20px 0;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar .brand { padding: 0 20px 20px; font-weight: 700; font-size: 16px; }
.sidebar .brand span { color: var(--muted); font-weight: 400; font-size: 12px; display: block; margin-top: 2px; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  padding: 10px 20px; color: var(--muted); text-decoration: none; font-size: 14px; cursor: pointer;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { color: var(--text); }
.sidebar nav a.active { color: var(--text); border-left-color: var(--accent); background: rgba(110,168,254,0.08); }
.nav-badge {
  display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 999px;
  background: var(--bad); color: #1a0f0f; font-size: 11px; font-weight: 700; text-align: center;
}
.sidebar .sidebar-footer { margin-top: auto; padding: 12px 20px 0; }
.sidebar .sidebar-footer .user-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.content { flex: 1; padding: 28px 32px; max-width: 1200px; }
.view { display: none; }
.view.active { display: block; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.view-header h1 { margin: 0; font-size: 20px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--accent); }
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 6px; }

h2 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 28px 0 12px; }
h2:first-child { margin-top: 0; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: rgba(255,255,255,0.03); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.lead, .pill.draft { background: rgba(154,161,172,0.15); color: var(--muted); }
.pill.prospect, .pill.sent { background: rgba(242,184,75,0.15); color: var(--warn); }
.pill.customer, .pill.accepted { background: rgba(62,207,142,0.15); color: var(--good); }
.pill.partner { background: rgba(110,168,254,0.15); color: var(--accent); }
.pill.inactive, .pill.rejected, .pill.expired { background: rgba(239,100,97,0.15); color: var(--bad); }
.pill.priority-low { background: rgba(154,161,172,0.15); color: var(--muted); }
.pill.priority-medium { background: rgba(110,168,254,0.15); color: var(--accent); }
.pill.priority-high { background: rgba(242,184,75,0.15); color: var(--warn); }
.pill.priority-critical { background: rgba(239,100,97,0.15); color: var(--bad); }
.pill.attn-overdue { background: rgba(239,100,97,0.15); color: var(--bad); }
.pill.attn-due_soon { background: rgba(242,184,75,0.15); color: var(--warn); }
.pill.attn-high { background: rgba(110,168,254,0.15); color: var(--accent); }
.pill.attn-normal { background: rgba(154,161,172,0.15); color: var(--muted); }

.empty { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }

.btn {
  background: var(--accent); color: #0b0c0f; border: none; border-radius: 8px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--bad); color: #1a0f0f; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; box-sizing: border-box; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 60px; }
.form-error { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 1em; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }
.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 32px; }
.auth-card h1 { font-size: 18px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.auth-card button[type="submit"] {
  width: 100%; margin-top: 6px; background: var(--accent); color: #0b0c0f; border: none;
  border-radius: 8px; padding: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center;
  justify-content: center; z-index: 100; padding: 20px;
}
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal.wide { max-width: 720px; }
.modal h3 { margin: 0 0 16px; font-size: 16px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.quote-items-table input { padding: 6px 8px; font-size: 13px; }
.quote-items-table td { padding: 6px 8px; }
.quote-total-row td { font-weight: 700; border-top: 1px solid var(--border); }
.back-link { color: var(--muted); font-size: 13px; text-decoration: none; cursor: pointer; }
.back-link:hover { color: var(--text); }
.detail-section { margin-bottom: 24px; }
.notes-block { white-space: pre-wrap; font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
tr.todo-done td { color: var(--muted); text-decoration: line-through; }
.todo-check { width: 16px; height: 16px; cursor: pointer; }

/* hidden is semantic: layout rules must never reopen a dismissed modal. */
[hidden] { display: none !important; }
.automation-inbox .detail-section { overflow-x: auto; }

/* Theme toggle (injected by theme.js): floating on standalone pages, inline in the app sidebar. */
.theme-toggle-btn {
  position: fixed; top: 16px; right: 16px; z-index: 1000;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.theme-toggle-btn:hover { border-color: var(--accent); }
.theme-toggle-inline { width: 100%; margin-bottom: 8px; }
