:root { --brand: #2563eb; --bg: #f6f7f9; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626; }
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, Segoe UI, sans-serif; color: var(--text); background: var(--bg); display: flex; min-height: 100vh; }
a { color: var(--brand); }

.sidebar { width: 220px; background: #111827; color: #e5e7eb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { padding: 20px 16px; border-bottom: 1px solid #1f2937; }
.brand img { max-width: 100%; max-height: 48px; display: block; }
.brand b { font-size: 18px; display: block; }
.brand small { color: #9ca3af; }
nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; flex: 1; }
nav a { color: #d1d5db; text-decoration: none; padding: 9px 12px; border-radius: 6px; }
nav a:hover { background: #1f2937; }
nav a.active { background: var(--brand); color: #fff; }
.powered { padding: 12px 16px; font-size: 12px; color: #6b7280; }

main { flex: 1; padding: 28px 32px; max-width: 1200px; min-width: 0; }
h1 { margin: 0 0 20px; font-size: 24px; display: flex; align-items: center; gap: 12px; }
h1 .spacer { flex: 1; }
h1 button { font-size: 14px; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); }

button, .btn { background: var(--brand); color: #fff; border: 0; border-radius: 6px; padding: 8px 14px; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--bad); }
button.sm, .btn.sm { padding: 4px 10px; font-size: 13px; }
button:hover, .btn:hover { filter: brightness(.95); }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; padding: 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * { margin-left: 4px; }
.table-wrap { border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #e5e7eb; color: #374151; text-transform: capitalize; }
.pill.sent, .pill.scheduled { background: #dbeafe; color: #1e40af; }
.pill.accepted, .pill.paid, .pill.done { background: #dcfce7; color: #166534; }
.pill.declined, .pill.cancelled, .pill.overdue { background: #fee2e2; color: #991b1b; }
.pill.unpaid, .pill.in-progress { background: #fef3c7; color: #92400e; }
.sync { font-size: 12px; color: var(--muted); }
.sync.err { color: var(--bad); }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(760px, 95vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(17,24,39,.5); }
#modal-form { padding: 22px; max-height: 88vh; overflow: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions .left { margin-right: auto; }

.items td { padding: 4px; border: 0; }
.items input { margin: 0; }
.items .qty { width: 80px; } .items .price { width: 120px; }
.totals { text-align: right; margin-top: 8px; color: var(--muted); }
.totals b { color: var(--text); font-size: 16px; }

/* Calendar */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h2 { margin: 0 12px 0 0; min-width: 170px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: #f9fafb; padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.cal .day { background: #fff; min-height: 110px; padding: 6px; cursor: pointer; overflow: hidden; }
.cal .day:hover { background: #f9fafb; }
.cal .day.other { background: #fafafa; color: #c0c4cc; }
.cal .day.today .num { background: var(--brand); color: #fff; border-radius: 99px; padding: 0 7px; }
.cal .num { font-size: 12px; font-weight: 600; display: inline-block; margin-bottom: 4px; }
.chip { display: block; font-size: 12px; padding: 2px 6px; border-radius: 4px; margin-bottom: 3px; background: var(--brand); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.done { background: var(--ok); } .chip.cancelled { background: #9ca3af; text-decoration: line-through; } .chip.in-progress { background: var(--warn); }

.integration { display: flex; gap: 16px; align-items: flex-start; }
.integration .logo { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; flex-shrink: 0; }
.integration .body { flex: 1; }
.connected { color: var(--ok); font-weight: 600; }
.nudge { border-left: 4px solid var(--brand); }
code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 12px; word-break: break-all; }
details summary { cursor: pointer; color: var(--brand); margin: 8px 0; }
ol { padding-left: 18px; margin: 6px 0; }

#toast { position: fixed; bottom: 20px; right: 20px; background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 400px; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }

@media (max-width: 760px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  nav { flex-direction: row; overflow-x: auto; }
  .powered { display: none; }
  main { padding: 16px; }
  .cal .day { min-height: 70px; }
}

/* ---- sign-in, account, CSP-safe helpers (no inline styles anywhere) ---- */
[hidden] { display: none !important; }
body.logged-out .sidebar, body.logged-out main { display: none; }
body:not(.logged-out) #auth { display: none; }
#auth { flex: 1; display: grid; place-items: center; padding: 24px; min-height: 100vh; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(420px, 100%); box-shadow: 0 10px 30px rgba(0,0,0,.06); }
.auth-card h1 { margin-bottom: 8px; }
.auth-card button { width: 100%; padding: 10px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 0 0 8px; }
.spacer { flex: 1; }
.mt { margin-top: 12px; }
h2.section { margin-top: 28px; }
.userbox { padding: 12px 16px; border-top: 1px solid #1f2937; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.userbox .who { font-size: 13px; line-height: 1.3; }
.userbox .who small { display: block; color: #9ca3af; text-transform: capitalize; }
.userbox button { color: #e5e7eb; border-color: #374151; }
.integration .logo.google { background: #4285f4; }
.integration .logo.zoho { background: #e42527; }
.integration .logo.ics { background: #6b7280; }
.nudge.warn { border-left-color: var(--warn); }
button.link { background: none; color: var(--brand); padding: 0 4px; font-size: 12px; font-weight: 600; }
code.key { font-size: 15px; letter-spacing: 1px; display: inline-block; margin-top: 6px; }
.pill.disabled { background: #e5e7eb; color: #6b7280; }
.audit { max-height: 420px; }
.audit td { font-size: 12px; }
@media (max-width: 760px) { .userbox { display: none; } }
