/* ─── Design tokens ─── */
:root {
  --bg: #0f172a; --panel: #1e293b; --panel2: #283548; --panel3: #2f3f55;
  --accent: #3b82f6; --accent2: #6366f1; --text: #e2e8f0; --muted: #94a3b8;
  --green: #22c55e; --amber: #f59e0b; --red: #ef4444; --purple: #a855f7;
  --cyan: #06b6d4; --border: #334155; --shadow: rgba(0,0,0,.4);
  --radius: 8px; --radius-lg: 12px;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif; font-size: 14px; }
a { color: var(--accent); text-decoration: none; }

/* ─── Topbar ─── */
.topbar { display: flex; align-items: center; gap: 12px; padding: 0 18px;
  height: 54px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-icon { font-size: 20px; color: var(--accent); }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.3px; }
nav { display: flex; gap: 2px; }
nav button { background: transparent; border: none; color: var(--muted);
  padding: 6px 13px; border-radius: 6px; cursor: pointer; font-size: 13px;
  font-weight: 500; transition: all .15s; }
nav button:hover { background: var(--panel2); color: var(--text); }
nav button.active { background: var(--accent); color: #fff; }
.toolbar { margin-left: auto; display: flex; gap: 6px; }
.toolbar button { background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); padding: 6px 11px; border-radius: 6px;
  cursor: pointer; font-size: 12px; transition: border-color .15s; }
.toolbar button:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Main layout ─── */
main { padding: 20px; max-width: 1340px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h2 { margin: 0; font-size: 20px; }

/* ─── Cards & Grid ─── */
.card { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 14px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin: 0 0 12px; }
.grid { display: grid; gap: 12px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .cols-4, .cols-3, .cols-2 { grid-template-columns: 1fr; } }

/* ─── Stat cards ─── */
.stat-card { text-align: center; padding: 20px 16px; }
.stat-num { font-size: 32px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .05em; }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border);
  color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ─── Forms ─── */
.form-grid { display: grid; gap: 12px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row > .f { flex: 1; min-width: 120px; }
.f { display: flex; flex-direction: column; gap: 4px; }
label { font-size: 11px; color: var(--muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 9px; border-radius: 6px; font-size: 13px; width: 100%;
  outline: none; transition: border-color .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
select option { background: var(--panel2); }

/* ─── Buttons ─── */
.btn { background: var(--accent); color: #fff; border: none; padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: opacity .15s; white-space: nowrap; }
.btn:hover { opacity: .88; }
.btn:active { opacity: .75; }
.btn-sm { padding: 4px 8px; font-size: 12px; border-radius: 5px; }
.btn-xs { padding: 2px 6px; font-size: 11px; border-radius: 4px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
.btn-danger { background: var(--red); }
.btn-success { background: var(--green); }
.btn-secondary { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-icon { background: transparent; border: none; cursor: pointer; color: var(--muted);
  padding: 3px 5px; border-radius: 4px; font-size: 14px; line-height: 1; }
.btn-icon:hover { background: var(--panel2); color: var(--text); }

/* ─── Badges & Status ─── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; white-space: nowrap; }
.b-green { background: rgba(34,197,94,.15); color: var(--green); border: 1px solid rgba(34,197,94,.25); }
.b-amber { background: rgba(245,158,11,.15); color: var(--amber); border: 1px solid rgba(245,158,11,.25); }
.b-red { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.25); }
.b-blue { background: rgba(59,130,246,.15); color: var(--accent); border: 1px solid rgba(59,130,246,.25); }
.b-purple { background: rgba(168,85,247,.15); color: var(--purple); border: 1px solid rgba(168,85,247,.25); }
.b-muted { background: var(--panel2); color: var(--muted); border: 1px solid var(--border); }
.priority-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.p-low { background: var(--green); } .p-medium { background: var(--amber); }
.p-high { background: var(--red); } .p-critical { background: var(--purple); }

/* ─── Progress bars ─── */
.progress { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.progress > .fill { height: 100%; background: var(--accent); border-radius: 3px;
  transition: width .3s; }
.progress.thick { height: 10px; border-radius: 5px; }

/* ─── Project cards ─── */
.project-card { border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--panel); margin-bottom: 10px; overflow: hidden;
  transition: border-color .15s, opacity .15s; }
.project-card:hover { border-color: var(--panel3); }
.project-card.dragging { opacity: .35; }
.project-card.drag-over-top { border-top: 2px solid var(--accent); }
.project-card.drag-over-bot { border-bottom: 2px solid var(--accent); }
.drag-handle { color: var(--muted); font-size: 16px; cursor: grab; flex-shrink: 0;
  line-height: 1; padding: 0 2px; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.project-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  cursor: pointer; user-select: none; }
.project-header:hover { background: rgba(255,255,255,.02); }
.project-expand { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.project-name { font-weight: 600; font-size: 14px; flex: 1; }
.project-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.project-actions { display: flex; gap: 4px; margin-left: auto; }
.project-body { padding: 0 14px 14px; border-top: 1px solid var(--border);
  display: none; }
.project-body.open { display: block; }

/* ─── Task rows ─── */
.task-item { border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel2); margin: 8px 0; padding: 10px 12px; }
.task-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.task-name { font-weight: 500; font-size: 13px; flex: 1; }
.task-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.subtask-list { margin: 8px 0 8px 16px; }
.subtask-item { display: flex; align-items: center; gap: 8px; padding: 4px 0;
  font-size: 12px; border-bottom: 1px solid rgba(255,255,255,.04); }
.subtask-item:last-child { border-bottom: none; }
.subtask-item input[type="checkbox"] { width: auto; flex-shrink: 0; accent-color: var(--accent); }
.subtask-name { flex: 1; }
.subtask-name.done { text-decoration: line-through; color: var(--muted); }

/* ─── Gantt ─── */
.gantt-wrap { overflow-x: auto; }
.gantt-header { display: flex; border-bottom: 2px solid var(--border);
  position: sticky; top: 0; background: var(--panel); z-index: 2; }
.gantt-label-col { width: 220px; flex-shrink: 0; padding: 6px 10px;
  font-size: 11px; color: var(--muted); font-weight: 600; }
.gantt-timeline { flex: 1; position: relative; height: 28px; min-width: 600px; }
.gantt-month { position: absolute; font-size: 11px; color: var(--muted);
  padding-top: 6px; padding-left: 4px; }
.gantt-row { display: flex; align-items: center; border-bottom: 1px solid var(--border);
  min-height: 36px; }
.gantt-row.group { background: var(--panel2); }
.gantt-label { width: 220px; flex-shrink: 0; font-size: 12px; padding: 0 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-track { flex: 1; position: relative; height: 36px; min-width: 600px; }
.gantt-bar { position: absolute; top: 8px; height: 20px; border-radius: 4px;
  font-size: 11px; color: #fff; line-height: 20px; padding: 0 6px;
  overflow: hidden; white-space: nowrap; cursor: pointer; transition: opacity .15s; }
.gantt-bar:hover { opacity: .85; }
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--red); opacity: .6; z-index: 1; }
.gantt-today::after { content: 'Today'; position: absolute; top: 4px;
  left: 4px; font-size: 10px; color: var(--red); white-space: nowrap; }
.gantt-conflict { border-left: 3px solid var(--red); }
.gantt-milestone { width: 12px; height: 12px; background: var(--amber);
  transform: rotate(45deg); position: absolute; top: 12px; }

/* ─── Resource allocation ─── */
.alloc-bar-wrap { width: 140px; }
.resource-card { border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel2); padding: 12px; margin-bottom: 8px; }
.conflict-banner { border: 1px solid var(--red); border-radius: var(--radius);
  background: rgba(239,68,68,.08); padding: 12px 14px; margin-bottom: 12px; }

/* ─── Lock wait overlay ─── */
.lock-wait { position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 900; }
.lock-wait.hidden { display: none; }
.lock-wait-box { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px 40px; text-align: center;
  box-shadow: 0 20px 60px var(--shadow); }
.lock-spinner { width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 16px;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lock-wait-msg { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0; }

/* ─── File gate ─── */
.file-gate { position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px; }
.file-gate.hidden { display: none; }
.file-gate-box { text-align: center; max-width: 420px; width: 100%; }
.file-gate-icon { font-size: 52px; color: var(--accent); line-height: 1; margin-bottom: 12px; }
.file-gate-title { margin: 0 0 8px; font-size: 28px; font-weight: 700; }
.file-gate-sub { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.file-gate-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 24px; }
.file-gate-actions .btn { padding: 10px 20px; font-size: 14px; }
.file-gate-hint { color: var(--muted); font-size: 12px; line-height: 1.6; }
.file-gate-hint code { background: var(--panel2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* ─── Reports ─── */
.chart-bar-h { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.chart-bar-h .bar-label { width: 120px; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.chart-bar-h .bar-track { flex: 1; height: 18px; background: var(--panel2);
  border-radius: 3px; overflow: hidden; position: relative; }
.chart-bar-h .bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.chart-bar-h .bar-val { position: absolute; right: 6px; top: 1px;
  font-size: 11px; color: var(--text); line-height: 16px; }

/* ─── Modal ─── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  padding: 20px; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px;
  cursor: pointer; padding: 0 4px; line-height: 1; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--panel2); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ─── Toast ─── */
#toastContainer { position: fixed; bottom: 20px; right: 20px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; font-size: 13px;
  box-shadow: 0 4px 16px var(--shadow); display: flex; align-items: center; gap: 8px;
  animation: slideIn .2s ease; max-width: 320px; }
.toast.toast-success { border-color: var(--green); }
.toast.toast-error { border-color: var(--red); }
.toast.toast-warn { border-color: var(--amber); }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ─── Search & filters ─── */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar input, .filter-bar select { background: var(--panel2); padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
  font-size: 13px; width: auto; }
.filter-bar input { min-width: 200px; }

/* ─── Utilities ─── */
.flex { display: flex; align-items: center; gap: 8px; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }
.spread { justify-content: space-between; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-16 { gap: 16px; }
.muted { color: var(--muted); }
.text-green { color: var(--green); } .text-red { color: var(--red); }
.text-amber { color: var(--amber); } .text-accent { color: var(--accent); }
.text-sm { font-size: 12px; } .text-xs { font-size: 11px; }
.fw-600 { font-weight: 600; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; }
.ml-auto { margin-left: auto; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; font-size: 13px; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px;
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted); }
.color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.scrollable { overflow-y: auto; max-height: 400px; }
