/* ─── VARIABLES ────────────────────────────────────────────────────────────── */
:root {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface2:  #f8fafc;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;
  --text:      #1e293b;
  --text2:     #475569;
  --text3:     #94a3b8;
  --primary:   #4f46e5;
  --primary-h: #4338ca;
  --primary-l: #eef2ff;
  --success:   #22c55e;
  --warning:   #f59e0b;
  --danger:    #ef4444;
  --topbar-h:  56px;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --transition: .15s ease;
}

[data-theme="dark"] {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --surface2: #162032;
  --border:   #334155;
  --border2:  #475569;
  --text:     #f1f5f9;
  --text2:    #cbd5e1;
  --text3:    #64748b;
  --primary-l:#1e1b4b;
  --shadow:    0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,.25);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.3);
}

/* ─── RESET & BASE ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea { font: inherit; color: var(--text); }
a { color: var(--primary); text-decoration: none; }

/* ─── TOPBAR ────────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--primary); min-width: 100px; }
.topbar-nav   { display: flex; gap: 4px; flex: 1; justify-content: center; }
.topbar-actions { display: flex; gap: 8px; min-width: 100px; justify-content: flex-end; }

.nav-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 6px;
  font-weight: 500; color: var(--text2);
  transition: background var(--transition), color var(--transition);
}
.nav-btn:hover  { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--primary-l); color: var(--primary); font-weight: 600; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius);
  color: var(--text2); transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: none; }

/* ─── MAIN ──────────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }
.main-content { margin-top: var(--topbar-h); flex: 1; overflow: auto; }
.page { min-height: calc(100vh - var(--topbar-h)); padding: 24px; }
.page.hidden { display: none; }

/* ─── CARDS & SURFACES ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
}

/* ─── BUTTONS ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius); font-weight: 500;
  transition: all var(--transition); white-space: nowrap;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-ghost    { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--surface2); color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-success  { background: var(--success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: var(--radius); }

/* ─── FORMS ─────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 500; font-size: 13px; color: var(--text2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="text"], input[type="number"], input[type="color"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border2);
  border-radius: var(--radius); background: var(--surface);
  transition: border-color var(--transition);
  outline: none;
}
input[type="color"] { padding: 4px 6px; height: 36px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* ─── MODAL ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 480px;
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title  { font-size: 16px; font-weight: 600; }
.modal-body   { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ─── TOAST ─────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow-md);
  font-size: 13px; font-weight: 500; color: #fff;
  animation: slideIn .2s ease; max-width: 300px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── LOADING ───────────────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── PROGRESS BAR ──────────────────────────────────────────────────────────── */
.progress-wrap { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar  { height: 100%; border-radius: 99px; transition: width .3s ease; }
.progress-success { background: var(--success); }
.progress-warning { background: var(--warning); }
.progress-danger  { background: var(--danger); }
.progress-neutral { background: var(--text3); }

/* ─── BADGES ────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-high   { background: #fee2e2; color: #dc2626; }
.badge-medium { background: #fef3c7; color: #d97706; }
.badge-low    { background: #dcfce7; color: #16a34a; }
[data-theme="dark"] .badge-high   { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-medium { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .badge-low    { background: #052e16; color: #86efac; }

/* ═══════════════════════════════════════════════════════════════════════════════
   WEEKLY PAGE
═══════════════════════════════════════════════════════════════════════════════ */
.weekly-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.weekly-title { font-size: 20px; font-weight: 700; }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-label { font-weight: 600; font-size: 14px; min-width: 200px; text-align: center; }
.week-nav .icon-btn { border: 1px solid var(--border); }

.weekly-table-wrap { overflow-x: auto; border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.weekly-table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border-radius: var(--radius-lg); overflow: hidden;
}
.weekly-table th, .weekly-table td {
  padding: 0; text-align: center; border-bottom: 1px solid var(--border);
}
.weekly-table th {
  background: var(--surface2); padding: 10px 8px; font-weight: 600;
  font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 2px solid var(--border);
}
.weekly-table th.today-col { background: var(--primary-l); color: var(--primary); }
.weekly-table tr:last-child td { border-bottom: none; }
.weekly-table tr:hover td { background: var(--surface2); }

.th-activity { text-align: left !important; padding-left: 16px !important; min-width: 180px; width: 22%; }
.th-day { min-width: 80px; }
.th-progress { min-width: 100px; }

/* Category group row */
.cat-group-row td {
  background: var(--surface2) !important;
  padding: 6px 16px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; color: var(--text3);
  border-bottom: 1px solid var(--border) !important;
}
.cat-group-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Activity cell */
.activity-cell { text-align: left !important; padding: 8px 16px !important; }
.activity-name { font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.activity-obj  { font-size: 11px; color: var(--text3); }

/* Day cell */
.day-cell { position: relative; height: 52px; vertical-align: middle; }
.day-cell.today-col { background: rgba(79,70,229,.03); }
.day-checkbox-wrap {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; flex-direction: column; gap: 4px;
}
.day-checkbox {
  width: 24px; height: 24px; border: 2px solid var(--border2);
  border-radius: 6px; background: var(--surface); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); flex-shrink: 0;
}
.day-checkbox:hover { border-color: var(--primary); }
.day-checkbox.checked { background: var(--primary); border-color: var(--primary); }
.day-checkbox.checked::after {
  content: ''; width: 6px; height: 10px;
  border: 2px solid #fff; border-top: none; border-left: none;
  transform: rotate(45deg) translateY(-1px);
}
.day-comment-btn {
  font-size: 10px; color: var(--text3); cursor: pointer;
  padding: 1px 4px; border-radius: 3px; transition: color var(--transition);
  line-height: 1; border: none; background: none;
}
.day-comment-btn:hover { color: var(--primary); }
.day-comment-btn.has-comment { color: var(--warning); }

/* Progress cell */
.progress-cell { padding: 8px 12px !important; }
.progress-pct  { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.progress-sub  { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* Weekly stats bar */
.weekly-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-pill-val { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-pill-lbl { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; }

/* Comment textarea popover */
.comment-popover {
  position: absolute; z-index: 50; background: var(--surface);
  border: 1px solid var(--border2); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 8px; min-width: 200px;
  top: 50%; transform: translateY(-50%); left: 90%;
}
.comment-popover textarea { width: 100%; height: 60px; font-size: 12px; padding: 6px; border-radius: 4px; }
.comment-popover-btns { display: flex; gap: 4px; margin-top: 6px; justify-content: flex-end; }

/* ═══════════════════════════════════════════════════════════════════════════════
   KANBAN PAGE
═══════════════════════════════════════════════════════════════════════════════ */
.kanban-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.kanban-header h2 { font-size: 20px; font-weight: 700; }
.kanban-search {
  flex: 1; max-width: 280px; position: relative;
}
.kanban-search input { padding-left: 32px; }
.kanban-search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text3); pointer-events: none; }
.kanban-filters { display: flex; gap: 6px; }
.filter-btn {
  padding: 5px 10px; border-radius: var(--radius); font-size: 12px; font-weight: 500;
  border: 1px solid var(--border2); color: var(--text2);
  transition: all var(--transition);
}
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.kanban-board { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 16px; align-items: flex-start; }
.kanban-col {
  flex: 0 0 280px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; max-height: calc(100vh - 160px);
}
.kanban-col.drag-over { border-color: var(--primary); background: var(--primary-l); }
.kanban-col.dragging  { opacity: .5; }

.col-header {
  padding: 12px 14px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.col-color  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.col-name   { font-weight: 600; font-size: 13px; flex: 1; }
.col-name[contenteditable="true"] { outline: none; border-bottom: 1px dashed var(--primary); }
.col-count  { background: var(--border); color: var(--text3); border-radius: 99px; font-size: 11px; font-weight: 600; padding: 1px 7px; }
.col-actions { display: flex; gap: 2px; }

.col-cards { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.kanban-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  cursor: grab; transition: box-shadow var(--transition), transform var(--transition);
  position: relative;
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card.dragging { opacity: .4; cursor: grabbing; }
.kanban-card.drag-over { border-color: var(--primary); }

.card-top     { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.card-name    { font-weight: 600; font-size: 13px; line-height: 1.3; }
.card-actions { display: none; gap: 2px; flex-shrink: 0; }
.kanban-card:hover .card-actions { display: flex; }
.card-desc    { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.card-meta    { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card-obj     { font-size: 11px; color: var(--text3); }

.col-add-btn {
  margin: 8px; padding: 8px; border-radius: var(--radius);
  border: 1px dashed var(--border2); color: var(--text3); font-size: 13px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all var(--transition); flex-shrink: 0;
}
.col-add-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-l); }

.add-col-btn {
  flex: 0 0 60px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; border: 2px dashed var(--border2);
  border-radius: var(--radius-lg); color: var(--text3); font-size: 12px; font-weight: 500;
  padding: 20px 10px; transition: all var(--transition); cursor: pointer;
  background: var(--surface2); min-height: 120px;
}
.add-col-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-l); }

/* ═══════════════════════════════════════════════════════════════════════════════
   STATISTICS PAGE
═══════════════════════════════════════════════════════════════════════════════ */
.stats-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.stats-header h2 { font-size: 20px; font-weight: 700; }
.stats-actions { display: flex; gap: 8px; }

.stats-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; text-align: center;
}
.kpi-value { font-size: 28px; font-weight: 800; }
.kpi-label { font-size: 12px; color: var(--text3); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.chart-card-full { grid-column: 1 / -1; }
.chart-card-full .chart-wrap { height: 300px; }
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text2); }
.chart-wrap { position: relative; height: 300px; }

.details-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.details-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text2); }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.detail-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.detail-item-name { font-weight: 600; font-size: 13px; }
.detail-item-pct  { font-size: 13px; font-weight: 700; }
.detail-mini-chart { height: 80px; }

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .page { padding: 12px; }
  .charts-grid  { grid-template-columns: 1fr; }
  .details-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .weekly-table { font-size: 12px; }
  .th-activity { min-width: 130px; }
}

/* ─── UTILITIES ─────────────────────────────────────────────────────────────── */
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-muted   { color: var(--text3); }
.fw-600 { font-weight: 600; }
.mt-4   { margin-top: 4px; }
.flex   { display: flex; }
.items-center { align-items: center; }
.gap-8  { gap: 8px; }
.hidden { display: none !important; }
