:root {
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --bg-sidebar-hover: #334155;
  --bg-input: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-sidebar: #cbd5e1;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --radius: 12px;
  --radius-sm: 6px;
  --sidebar-w: 240px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary-light: #1e3a8a;
  --success-light: #064e3b;
  --warning-light: #78350f;
  --danger-light: #7f1d1d;
  --purple-light: #4c1d95;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; transition: background .2s, color .2s; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 20px 18px 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo .logo-icon {
  width: 32px; height: 32px; background: var(--primary);
  border-radius: 8px; display: grid; place-items: center;
  font-size: 16px; color: #fff; font-weight: 700; flex-shrink: 0;
}
.sidebar-logo span { color: #f1f5f9; font-weight: 700; font-size: 1.05rem; }
.sidebar-nav { padding: 12px 8px; flex: 1; }
.nav-label { color: #475569; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; padding: 8px 10px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text-sidebar); text-decoration: none;
  font-size: .9rem; font-weight: 500; transition: background .15s, color .15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: #f1f5f9; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.08); }
.biz-pills { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.biz-pill {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border-radius: 8px; cursor: pointer; transition: background .15s;
  font-size: .82rem; color: var(--text-sidebar); border: none; background: none; text-align: left; width: 100%;
}
.biz-pill:hover { background: rgba(255,255,255,.08); }
.biz-pill.active { background: rgba(255,255,255,.12); color: #fff; }
.biz-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.theme-toggle {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; color: var(--text-sidebar);
  font-size: .82rem; background: none; border: none; width: 100%; transition: background .15s;
}
.theme-toggle:hover { background: rgba(255,255,255,.08); color: #f1f5f9; }

/* ── Main ── */
.main { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 1.2rem; font-weight: 700; }
.content { padding: 24px; flex: 1; max-width: 1400px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: .875rem;
  font-weight: 500; cursor: pointer; border: none; transition: opacity .15s, transform .1s;
}
.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }

/* ── Cards ── */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card-grid { display: grid; gap: 16px; }
.card-grid-2 { grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); }
.card-grid-3 { grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); }
.card-grid-4 { grid-template-columns: repeat(4,1fr); }
@media (max-width: 900px) { .card-grid-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 500px) { .card-grid-4 { grid-template-columns: 1fr; } }

/* ── Summary stat cards ── */
.stat-card { display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; font-size: 1.2rem; }
.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-bottom: 2px; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 20px; font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.badge-todo     { background: #f1f5f9; color: #475569; }
.badge-in_progress { background: var(--primary-light); color: var(--primary); }
.badge-blocked  { background: var(--danger-light);  color: var(--danger); }
.badge-review   { background: var(--warning-light); color: var(--warning); }
.badge-done     { background: var(--success-light); color: var(--success); }
.badge-planning    { background: #f1f5f9; color: #475569; }
.badge-active      { background: var(--primary-light); color: var(--primary); }
.badge-on_hold     { background: var(--warning-light); color: var(--warning); }
.badge-completed   { background: var(--success-light); color: var(--success); }
.badge-cancelled   { background: #f1f5f9; color: #94a3b8; }
.badge-low      { background: #f1f5f9; color: #64748b; }
.badge-medium   { background: var(--primary-light); color: var(--primary); }
.badge-high     { background: var(--warning-light); color: var(--warning); }
.badge-critical { background: var(--danger-light); color: var(--danger); }
.badge-good     { background: var(--success-light); color: var(--success); }
.badge-at_risk  { background: var(--warning-light); color: var(--warning); }

/* ── Progress bar ── */
.progress-wrap { background: var(--border); border-radius: 99px; height: 6px; overflow: hidden; }
.progress-bar  { height: 100%; border-radius: 99px; transition: width .4s; }
.progress-bar.good     { background: var(--success); }
.progress-bar.at_risk  { background: var(--warning); }
.progress-bar.critical { background: var(--danger); }
.progress-bar.default  { background: var(--primary); }

/* ── Health dot ── */
.health-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.health-dot.good     { background: var(--success); }
.health-dot.at_risk  { background: var(--warning); }
.health-dot.critical { background: var(--danger); }

/* ── Priority left border ── */
.border-low      { border-left: 3px solid #94a3b8; }
.border-medium   { border-left: 3px solid var(--primary); }
.border-high     { border-left: 3px solid var(--warning); }
.border-critical { border-left: 3px solid var(--danger); }

/* ── Section headers ── */
.section-title {
  font-size: 1rem; font-weight: 700; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title .count {
  background: var(--border); color: var(--text-muted);
  border-radius: 20px; padding: 1px 8px; font-size: .75rem; font-weight: 600;
}
.section { margin-bottom: 28px; }

/* ── Task row ── */
.task-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--bg-card); border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-bottom: 6px;
  cursor: pointer; transition: box-shadow .15s;
}
.task-row:hover { box-shadow: var(--shadow-md); }
.task-row .task-title { flex: 1; font-weight: 500; font-size: .875rem; }
.task-row .task-meta  { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }

/* ── Project card ── */
.project-card {
  background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; cursor: pointer; transition: transform .15s, box-shadow .15s;
  border-top: 3px solid transparent;
}
.project-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.project-card .pc-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.project-card .pc-name   { font-weight: 700; font-size: .95rem; flex: 1; }
.project-card .pc-meta   { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.project-card .pc-progress { margin-bottom: 6px; }
.project-card .pc-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.project-card .pc-footer .pc-counts { font-size: .78rem; color: var(--text-muted); display: flex; gap: 10px; }

/* ── Filter bar ── */
.filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--bg-card); padding: 12px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.filter-bar select, .filter-bar input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text); font-size: .82rem; outline: none;
}
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--primary); }
.filter-bar input[type=search] { min-width: 160px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; background: var(--bg-card); padding: 4px; border-radius: var(--radius-sm); width: fit-content; margin-bottom: 16px; box-shadow: var(--shadow); }
.tab { padding: 7px 16px; border-radius: calc(var(--radius-sm) - 2px); cursor: pointer; font-size: .85rem; font-weight: 500; color: var(--text-muted); border: none; background: none; transition: background .15s, color .15s; }
.tab.active { background: var(--primary); color: #fff; }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th { background: var(--bg); text-align: left; padding: 10px 12px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); border-bottom: 2px solid var(--border); cursor: pointer; user-select: none; }
.data-table th:hover { color: var(--text); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.table-wrap { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

/* ── Calendar ── */
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-header { text-align: center; background: var(--bg-card); padding: 8px 4px; font-size: .72rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); }
.cal-day {
  background: var(--bg-card); min-height: 90px; padding: 6px;
  cursor: pointer; transition: background .1s;
}
.cal-day:hover { background: var(--bg); }
.cal-day .day-num { font-size: .78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.cal-day.today .day-num { background: var(--primary); color: #fff; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.cal-day.other-month .day-num { color: #cbd5e1; }
.cal-chip { font-size: .68rem; padding: 2px 5px; border-radius: 3px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.cal-chip.low      { background: #94a3b8; }
.cal-chip.medium   { background: var(--primary); }
.cal-chip.high     { background: var(--warning); }
.cal-chip.critical { background: var(--danger); }
.mini-cal { }
.mini-cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
.mini-cal-day { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 4px; cursor: pointer; position: relative; }
.mini-cal-day span { font-size: .72rem; }
.mini-cal-day.today span { background: var(--primary); color: #fff; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.mini-cal-day.has-tasks::after { content: ''; width: 4px; height: 4px; background: var(--primary); border-radius: 50%; position: absolute; bottom: 2px; }
.mini-cal-day.other-month span { color: var(--border); }
.mini-cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mini-cal-header .month-name { font-weight: 700; font-size: .9rem; }
.mini-cal-dow { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; margin-bottom: 4px; }
.mini-cal-dow span { font-size: .65rem; text-align: center; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }

/* ── Kanban Board ── */
.board { display: grid; grid-template-columns: repeat(5,1fr); gap: 12px; min-height: 500px; }
@media (max-width: 1100px) { .board { grid-template-columns: repeat(3,1fr); } }
@media (max-width: 700px)  { .board { grid-template-columns: 1fr; } }
.board-col { background: var(--bg); border-radius: var(--radius); padding: 10px; }
.board-col-header { font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; }
.board-col-header .col-count { background: var(--border); border-radius: 20px; padding: 1px 7px; font-size: .72rem; color: var(--text-muted); }
.board-card { background: var(--bg-card); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; transition: transform .15s; }
.board-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.board-card .bc-title { font-weight: 600; font-size: .82rem; margin-bottom: 6px; }
.board-card .bc-meta  { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

/* ── Gantt ── */
.gantt-wrap { overflow-x: auto; }
.gantt-table { min-width: 900px; width: 100%; border-collapse: collapse; }
.gantt-table th, .gantt-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.gantt-table th { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--bg); }
.gantt-row-label { font-weight: 600; font-size: .82rem; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-timeline { position: relative; height: 32px; }
.gantt-bar { position: absolute; height: 20px; top: 6px; border-radius: 4px; opacity: .85; display: flex; align-items: center; padding: 0 6px; font-size: .7rem; font-weight: 600; color: #fff; overflow: hidden; white-space: nowrap; }
.gantt-milestone { position: absolute; top: 5px; width: 14px; height: 14px; transform: rotate(45deg); background: var(--warning); border: 2px solid var(--warning-light); }
.gantt-header-dates { display: flex; gap: 0; }
.gantt-today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); opacity: .5; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg-card); border-radius: var(--radius); padding: 24px; max-width: 520px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.2); max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 18px; }
.modal .form-group { margin-bottom: 14px; }
.modal label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text); font-size: .875rem; outline: none; font-family: inherit;
}
.modal input:focus, .modal select:focus, .modal textarea:focus { border-color: var(--primary); }
.modal textarea { resize: vertical; min-height: 70px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Detail panel ── */
.detail-panel {
  background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 20px; margin-top: 8px; border: 1px solid var(--border);
}

/* ── Overdue flag ── */
.overdue-row { border-left: 3px solid var(--danger); }
.overdue-badge { background: var(--danger-light); color: var(--danger); padding: 2px 6px; border-radius: 20px; font-size: .7rem; font-weight: 600; }

/* ── Upcoming list ── */
.deadline-group { margin-bottom: 14px; }
.deadline-date { font-size: .78rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.deadline-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.deadline-item:last-child { border-bottom: none; }
.deadline-type { font-size: .68rem; padding: 1px 6px; border-radius: 20px; font-weight: 600; background: var(--border); color: var(--text-muted); }
.deadline-type.milestone { background: var(--warning-light); color: var(--warning); }
.deadline-name { flex: 1; font-size: .85rem; font-weight: 500; }

/* ── Misc ── */
.biz-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .es-icon { font-size: 2.5rem; margin-bottom: 10px; }
.collapse-btn { background: none; border: none; color: var(--primary); font-size: .8rem; cursor: pointer; font-weight: 500; padding: 4px 0; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-1 { gap: 4px; }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--text-muted); font-size: .8rem; }
.font-bold { font-weight: 700; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; }
