:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e2230; --line: #2a2f3e;
  --text: #e8eaf0; --muted: #8a90a3; --accent: #4f8cff; --accent2: #7c5cff;
  --ok: #34c77b; --warn: #f5a623; --bad: #ef5b5b; --review: #38bdf8;
  --radius: 10px; font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.88em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header#topbar { display: flex; align-items: center; gap: 28px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40; }
.brand { font-weight: 800; letter-spacing: 2px; font-size: 1.05rem; }
.brand span { color: var(--accent); }
.brand em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 0.75rem; letter-spacing: 4px; margin-left: 6px; text-transform: uppercase; }
nav#nav { display: flex; gap: 4px; flex: 1; }
nav#nav a { color: var(--muted); padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 0.9rem; }
nav#nav a.active, nav#nav a:hover { color: var(--text); background: var(--panel2); text-decoration: none; }
.top-right { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.85rem; }
footer { padding: 10px 24px; color: var(--muted); font-size: 0.75rem; border-top: 1px solid var(--line); }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 26px 0 10px; }
.sub { color: var(--muted); margin: 0 0 22px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; font-size: 0.9rem; }
.btn:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ok { background: var(--ok); } .btn.bad { background: var(--bad); } .btn.warn { background: var(--warn); color: #201500; }
.btn.sm { padding: 5px 10px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.3px; }
.badge.ok { background: rgba(52,199,123,.15); color: var(--ok); }
.badge.warn { background: rgba(245,166,35,.15); color: var(--warn); }
.badge.bad { background: rgba(239,91,91,.15); color: var(--bad); }
.badge.info { background: rgba(79,140,255,.15); color: var(--accent); }
.badge.rev { background: rgba(56,189,248,.15); color: var(--review); }
.badge.dim { background: var(--panel2); color: var(--muted); }

.progress { height: 7px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 4px; transition: width .3s; }

/* forms */
form.stack label, .stack label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 0.86rem; }
input, select, textarea { width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 0.92rem; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.field-err { color: var(--bad); font-size: 0.83rem; margin-top: 8px; min-height: 1em; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: rgba(255,255,255,0.015); }

/* login */
.auth-wrap { max-width: 400px; margin: 8vh auto; }
.auth-wrap .brand { font-size: 1.4rem; text-align: center; margin-bottom: 24px; }

/* modal */
#modal-root .overlay { position: fixed; inset: 0; background: rgba(5,7,10,0.72); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 60; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: 100%; max-width: 560px; padding: 22px; }
.modal h3 { margin-top: 0; }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 11px 16px; border-radius: 8px; font-size: 0.88rem; max-width: 360px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }

/* error panel — UI never fails silently */
.err-panel { background: rgba(239,91,91,.08); border: 1px solid rgba(239,91,91,.4); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; font-size: 0.9rem; }
.err-panel b { color: var(--bad); }

.center-note { text-align: center; color: var(--muted); padding: 60px 0; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0; flex-wrap: wrap; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 9px 16px; font-weight: 600; cursor: pointer; font-size: 0.9rem; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* phase pipeline */
.pipeline { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0; }
.phase-chip { padding: 7px 12px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); font-size: 0.8rem; font-weight: 600; color: var(--muted); position: relative; }
.phase-chip.active { border-color: var(--accent); color: var(--text); }
.phase-chip.done { border-color: var(--ok); color: var(--ok); }
.phase-chip.awaiting_signoff { border-color: var(--warn); color: var(--warn); }
.phase-chip.blocked { border-color: var(--bad); color: var(--bad); }
.phase-chip .sub-note { display: block; font-weight: 400; font-size: 0.68rem; margin-top: 2px; }

/* kanban */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: start; }
.kanban .col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.kanban .col h4 { margin: 2px 4px 10px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.kanban .col.drag-over { border-color: var(--accent); }
.task-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; font-size: 0.88rem; }
.task-card .meta { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; align-items: center; }
.task-card.overdue { border-color: var(--bad); }
.task-card.dragging { opacity: 0.45; border-style: dashed; }
.eye { opacity: 0.75; font-size: 0.72rem; }

/* gantt */
.gantt-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.gantt { position: relative; min-width: 640px; }
.gantt-months { display: flex; border-bottom: 1px solid var(--line); margin-left: 180px; }
.gantt-month { font-size: 0.72rem; color: var(--muted); padding: 4px 0 6px; border-left: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-transform: uppercase; letter-spacing: 0.5px; padding-left: 5px; }
.gantt-row { display: flex; align-items: center; height: 34px; border-bottom: 1px solid rgba(42,47,62,0.5); }
.gantt-label { width: 180px; min-width: 180px; font-size: 0.82rem; padding-right: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-label .muted { font-size: 0.7rem; }
.gantt-track { position: relative; flex: 1; height: 100%; }
.gantt-bar { position: absolute; top: 7px; height: 20px; border-radius: 5px; font-size: 0.68rem; line-height: 20px; padding: 0 7px; white-space: nowrap; overflow: hidden; color: #fff; opacity: 0.95; cursor: default; }
.gantt-bar.pending { background: #3b4157; }
.gantt-bar.active { background: var(--accent); }
.gantt-bar.done { background: var(--ok); }
.gantt-bar.awaiting_signoff { background: var(--warn); color: #201500; }
.gantt-bar.blocked { background: var(--bad); }
.gantt-bar.task { height: 12px; top: 11px; background: var(--accent2); border-radius: 3px; font-size: 0; }
.gantt-bar.task.done { background: var(--ok); }
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); opacity: 0.8; z-index: 5; }
.gantt-today::after { content: 'today'; position: absolute; top: -2px; left: 4px; font-size: 0.62rem; color: var(--bad); }
.gantt-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 0.72rem; color: var(--muted); flex-wrap: wrap; }
.gantt-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; }

/* content items */
.item-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; background: var(--panel); }
.item-row.status-approved { border-left: 4px solid var(--ok); }
.item-row.status-submitted { border-left: 4px solid var(--review); }
.item-row.status-rejected { border-left: 4px solid var(--bad); }
.item-row.status-pending { border-left: 4px solid var(--line); }
.item-row h4 { margin: 0 0 4px; font-size: 0.95rem; }
.save-note { font-size: 0.75rem; color: var(--muted); margin-left: 8px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; font-size: 0.78rem; margin: 3px 4px 0 0; }

/* signoff */
.signoff-box { border: 1px dashed var(--warn); border-radius: var(--radius); padding: 14px; margin: 10px 0; background: rgba(245,166,35,0.05); }
.audit { font-size: 0.78rem; color: var(--muted); }

.comments { margin-top: 10px; }
.comment { padding: 8px 10px; border-radius: 8px; background: var(--panel2); margin-bottom: 6px; font-size: 0.85rem; }
.comment.internal { border: 1px dashed var(--warn); }
.comment .who { font-weight: 700; font-size: 0.78rem; }

.stat-strip { display: flex; gap: 18px; flex-wrap: wrap; margin: 10px 0 4px; }
.stat { font-size: 0.82rem; color: var(--muted); }
.stat b { color: var(--text); font-size: 1.05rem; display: block; }

@media (max-width: 900px) {
  .kanban { grid-template-columns: 1fr 1fr; }
  .inline-fields { grid-template-columns: 1fr; }
  nav#nav { overflow-x: auto; }
}

/* email inbox */
.email-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; background: var(--panel); font-size: 0.9rem; }
.email-row:hover { border-color: var(--accent); }

/* client portal dashboard */
.portal-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }
.portal-side .card h3 { margin-bottom: 10px; }
.feature-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin: 18px 0 8px; }
.feature-card { border-radius: 14px; padding: 20px; color: #fff; cursor: pointer; transition: transform .15s; }
.feature-card:hover { transform: translateY(-2px); }
.feature-card.g0 { background: linear-gradient(135deg, #2563eb, #7c5cff); }
.feature-card.g1 { background: linear-gradient(135deg, #7c5cff, #0ea5a4); }
.feature-card h3 { margin: 6px 0 12px; font-size: 1.15rem; }
.fc-phase { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1px; opacity: 0.85; }
.fc-progress { background: rgba(255,255,255,0.25); }
.fc-progress > div { background: #fff; }
.fc-foot { display: flex; justify-content: space-between; font-size: 0.8rem; margin-top: 10px; opacity: 0.9; }
.wait-row { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; background: var(--panel); color: var(--text); }
.wait-row:hover { border-color: var(--accent); text-decoration: none; }
.wait-ico { font-size: 1.2rem; }
.wait-main { flex: 1; display: flex; flex-direction: column; gap: 2px; }
@media (max-width: 900px) { .portal-wrap { grid-template-columns: 1fr; } }

.mini-table { border-collapse: collapse; font-size: 0.85rem; }
.mini-table th, .mini-table td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.mini-table th { color: var(--muted); font-weight: 600; }
