:root,
[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273549;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #10b981;
  --border: #334155;
  --shadow: 0 1px 2px rgba(0,0,0,0.3);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --muted: #64748b;
  --text: #0f172a;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15,23,42,0.08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}
h1, h2, h3 { margin: 0; font-weight: 600; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { color: var(--accent); font-size: 22px; }
.brand h1 { font-size: 18px; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted); border: none;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--accent); color: white; }

.theme-toggle {
  margin-left: 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  width: 38px; height: 38px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--accent); color: white; border-color: var(--accent); }

main { padding: 22px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.filters { display: flex; gap: 8px; align-items: center; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.projects { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.stat .stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .stat-value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat .stat-value.warn { color: var(--warn); }

/* Buttons / inputs */
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: #31425b; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: white; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 24px; cursor: pointer; }
.icon-btn:hover { color: var(--text); }

input, select, textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 6px; font-size: 14px; font-family: inherit; width: 100%;
}
input[type="color"] { padding: 2px; height: 38px; }
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.list .item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--panel-2); border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.list .item:hover { border-color: var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.muted { color: var(--muted); font-size: 12px; }

/* Project cards */
.proj-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; cursor: pointer; transition: border-color .15s;
  border-top: 4px solid var(--accent);
}
.proj-card:hover { border-color: var(--accent); }
.proj-card h3 { margin-bottom: 6px; }
.proj-card .desc { color: var(--muted); font-size: 13px; min-height: 36px; }
.proj-card .kv { display: grid; gap: 4px; margin: 10px 0 4px; font-size: 12px; }
.proj-card .kv > div { display: flex; gap: 8px; }
.proj-card .klabel { color: var(--muted); min-width: 64px; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; padding-top: 1px; }
.proj-card .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 10px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.active { background: rgba(16,185,129,.15); color: var(--ok); border-color: rgba(16,185,129,.3); }
.badge.paused { background: rgba(245,158,11,.15); color: var(--warn); border-color: rgba(245,158,11,.3); }
.badge.done { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.p-high { background: rgba(239,68,68,.15); color: var(--danger); border-color: rgba(239,68,68,.3); }
.badge.p-medium { background: rgba(59,130,246,.15); color: var(--accent); border-color: rgba(59,130,246,.3); }
.badge.p-low { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.s-todo { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.s-in_progress { background: rgba(59,130,246,.15); color: var(--accent); }
.badge.s-blocked { background: rgba(239,68,68,.15); color: var(--danger); }
.badge.s-done { background: rgba(16,185,129,.15); color: var(--ok); }

/* Table */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.tbl tr:hover td { background: var(--panel-2); cursor: pointer; }
.tbl .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.btn.small { padding: 4px 10px; font-size: 12px; margin-left: 4px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(600px, 94vw); max-height: 90vh; overflow: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; display: grid; gap: 12px; }
.modal-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-body label.row { flex-direction: row; align-items: center; gap: 8px; }
.modal-body .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.hidden { display: none !important; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; margin: 0; padding: 24px; }
.login-wrap { width: 100%; max-width: 420px; }
.login-card { padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login-brand .logo { color: var(--accent); font-size: 24px; }
.login-brand h1 { font-size: 20px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* Header user pill */
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 12px; margin-left: 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  font-size: 13px;
}
.user-pill-name { color: var(--text); font-weight: 500; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pill-admin {
  color: var(--accent); text-decoration: none; font-weight: 600;
  padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(59,130,246,.3);
  background: rgba(59,130,246,.1); font-size: 12px;
}
.user-pill-admin:hover { background: var(--accent); color: white; border-color: var(--accent); }
.user-pill-logout {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer;
}
.user-pill-logout:hover { background: var(--danger); color: white; border-color: var(--danger); }

/* Toggle switch (admin flag) */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--border); transition: .15s;
}
.switch span::before {
  content: ""; position: absolute; top: 1px; left: 1px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: .15s;
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); background: white; }

/* Journey page */
.journey { max-width: 1000px; margin: 0 auto; padding: 32px 24px 60px; }
.journey-intro { text-align: center; margin-bottom: 28px; }
.journey-intro h2 { font-size: 28px; margin-bottom: 8px; }
.journey-intro p { color: var(--muted); max-width: 680px; margin: 0 auto; line-height: 1.55; }
.journey-stats { display: flex; gap: 18px; justify-content: center; margin-top: 14px; color: var(--muted); font-size: 13px; }
.journey-stats strong { color: var(--text); font-size: 15px; }

.journey-controls {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  margin-bottom: 22px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
}
#j-search { flex: 1; min-width: 200px; max-width: 360px; }
.j-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.j-chip {
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.j-chip:hover { background: var(--accent); color: white; border-color: var(--accent); }
.j-chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.j-chip-n {
  background: rgba(255,255,255,0.2); color: inherit; border-radius: 10px;
  padding: 0 7px; font-size: 11px; line-height: 18px;
}
.j-chip:not(.active) .j-chip-n { background: var(--border); color: var(--muted); }

.timeline { position: relative; display: flex; flex-direction: column; gap: 18px; }
.timeline::before {
  content: ""; position: absolute; top: 10px; bottom: 10px; left: 24px;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; padding-left: 64px; }
.tl-dot {
  position: absolute; left: 0; top: 4px; width: 48px; height: 48px;
  background: var(--panel); border: 2px solid var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; z-index: 1;
}
.tl-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 20px; transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.tl-card.open { border-color: var(--accent); }
.tl-head-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.tl-num { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; font-weight: 600; }
.tl-date { color: var(--muted); font-size: 12px; }
.j-chip-tiny {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--muted);
}
.j-chip-tiny.cat-scaffold    { color: #a78bfa; border-color: rgba(167,139,250,.35); background: rgba(167,139,250,.12); }
.j-chip-tiny.cat-architecture{ color: #38bdf8; border-color: rgba(56,189,248,.35); background: rgba(56,189,248,.12); }
.j-chip-tiny.cat-data        { color: #f472b6; border-color: rgba(244,114,182,.35); background: rgba(244,114,182,.12); }
.j-chip-tiny.cat-feature     { color: var(--ok);   border-color: rgba(16,185,129,.35); background: rgba(16,185,129,.12); }
.j-chip-tiny.cat-ux          { color: var(--accent); border-color: rgba(59,130,246,.35); background: rgba(59,130,246,.12); }
.j-chip-tiny.cat-infra       { color: var(--warn); border-color: rgba(245,158,11,.35); background: rgba(245,158,11,.12); }

.tl-title { font-size: 16px; margin-bottom: 4px; }
.tl-summary { color: var(--muted); margin: 0; line-height: 1.5; font-size: 14px; }
.tl-toggle {
  background: transparent; color: var(--accent); border: none;
  padding: 8px 0 4px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.tl-details {
  max-height: 0; overflow: hidden; margin: 0; padding: 0;
  transition: max-height .25s ease, padding .25s ease;
  list-style: none;
}
.tl-card.open .tl-details {
  max-height: 800px; padding: 8px 0 4px 18px;
}
.tl-details li {
  position: relative; padding: 4px 0 4px 14px; color: var(--text);
  font-size: 13px; line-height: 1.55;
}
.tl-details li::before {
  content: "›"; position: absolute; left: 0; top: 3px; color: var(--accent); font-weight: 700;
}
.tl-details code {
  background: var(--panel-2); padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  border: 1px solid var(--border);
}
.center { text-align: center; }

/* Project detail */
.pd-header { display: flex; flex-direction: column; gap: 10px; }
.pd-title { display: flex; align-items: center; gap: 12px; }
.pd-swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); display: inline-block; }
.pd-desc { color: var(--muted); margin: 0; line-height: 1.5; }
.pd-meta {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px 20px; margin-top: 6px;
}
.pd-meta > div { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.pd-meta .klabel {
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  font-size: 10px;
}

/* Landing page */
.brand-link { text-decoration: none; }
.landing { max-width: 1100px; margin: 0 auto; padding: 40px 24px; }
.landing-head { text-align: center; margin-bottom: 32px; }
.landing-head h2 { font-size: 28px; margin-bottom: 6px; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.tile {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile-icon {
  width: 48px; height: 48px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
  color: white; margin-bottom: 6px;
}
.tile h3 { font-size: 18px; }
.tile p { color: var(--muted); font-size: 13px; line-height: 1.5; flex: 1; margin: 0; }
.tile-cta { color: var(--accent); font-weight: 600; font-size: 14px; margin-top: 4px; }
.landing-foot { text-align: center; margin-top: 30px; }
.landing-foot a { color: var(--muted); font-size: 13px; text-decoration: none; }
.landing-foot a:hover { color: var(--accent); }

/* Inventory-specific statuses */
.badge.s-in_use  { background: rgba(16,185,129,.15); color: var(--ok); border-color: rgba(16,185,129,.3); }
.badge.s-spare   { background: rgba(59,130,246,.15); color: var(--accent); border-color: rgba(59,130,246,.3); }
.badge.s-repair  { background: rgba(245,158,11,.15); color: var(--warn); border-color: rgba(245,158,11,.3); }
.badge.s-retired { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.s-lost    { background: rgba(239,68,68,.15); color: var(--danger); border-color: rgba(239,68,68,.3); }
.badge.s-active  { background: rgba(16,185,129,.15); color: var(--ok); border-color: rgba(16,185,129,.3); }
.badge.s-expired { background: rgba(239,68,68,.15); color: var(--danger); border-color: rgba(239,68,68,.3); }
.badge.s-cancelled { background: rgba(148,163,184,.15); color: var(--muted); }
.badge.s-pending { background: rgba(245,158,11,.15); color: var(--warn); border-color: rgba(245,158,11,.3); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

/* Task notes */
.notes-block {
  margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.notes-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.notes-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.note-row {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
}
.note-meta {
  display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted);
}
.note-author-name { font-weight: 600; color: var(--text); }
.note-when { flex: 1; }
.note-body-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.notes-add { display: flex; flex-direction: column; gap: 8px; }
.notes-add-row { display: flex; gap: 8px; align-items: center; }
.notes-add-row select { flex: 1; }

/* Attachments */
.attach-block {
  margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.attach-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.attach-list { display: flex; flex-direction: column; gap: 6px; }
.attach-row {
  display: grid; grid-template-columns: minmax(140px, 1fr) auto auto;
  gap: 10px; align-items: center; padding: 8px 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
}
.attach-name { color: var(--accent); text-decoration: none; word-break: break-all; font-weight: 500; }
.attach-name:hover { text-decoration: underline; }
.attach-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.attach-upload {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
}
.attach-file { padding: 6px; background: var(--panel-2); }

/* FullCalendar overrides */
#calendar { min-height: 680px; }
.fc { color: var(--text); }
.fc .fc-toolbar-title { font-size: 18px; }
.fc .fc-button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  text-transform: capitalize;
}
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):hover { background: var(--accent); border-color: var(--accent); }
.fc-theme-standard td, .fc-theme-standard th, .fc-theme-standard .fc-scrollgrid { border-color: var(--border); }
.fc .fc-day-today { background: rgba(59,130,246,.08) !important; }
.fc-event { cursor: pointer; border-radius: 4px; padding: 2px 4px; font-size: 12px; color: white !important; }
.fc-event .fc-event-title { color: white; }
[data-theme="light"] .fc .fc-col-header-cell-cushion,
[data-theme="light"] .fc .fc-daygrid-day-number { color: var(--text); }
