/* =========================================================
   TaskPilot Design System
   ========================================================= */

:root {
  --accent: #F2BF00;
  --accent-hover: #d9ab00;
  --accent-contrast: #1a1a1a;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);

  --transition: 150ms ease;
}

html[data-theme="light"] {
  --bg: #FAFAF8;
  --surface: #FFFFFF;
  --surface-alt: #F4F4F2;
  --border: #E7E5E0;
  --text: #1C1C1A;
  --text-muted: #6B6B65;
  --text-faint: #A3A39C;
  --danger: #E5484D;
  --success: #1E9E5A;
  --info: #3B82C4;
}

html[data-theme="dark"] {
  --bg: #121212;
  --surface: #191919;
  --surface-alt: #212121;
  --border: #2D2D2D;
  --text: #F2F1ED;
  --text-muted: #A8A79F;
  --text-faint: #6E6D66;
  --danger: #F16468;
  --success: #37C077;
  --info: #5FA6E0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

/* Global icon sizing safety net — prevents unsized inline SVGs from ever
   rendering at their raw viewBox dimensions (this was the cause of the
   oversized "Add Task" button). Specific contexts below override as needed. */
svg { width: 18px; height: 18px; display: block; flex-shrink: 0; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

::selection { background: var(--accent); color: var(--accent-contrast); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Layout ---------- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition);
}

.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-section-title { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--accent-contrast);
  flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 15px; }

.add-task-btn {
  margin: var(--space-3) var(--space-3) 0;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background var(--transition), transform var(--transition);
  width: calc(100% - 24px);
}
.add-task-btn svg { width: 16px; height: 16px; }
.add-task-btn:hover { background: var(--accent-hover); }
.add-task-btn:active { transform: scale(0.98); }

.sidebar-nav { padding: var(--space-3); overflow-y: auto; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active { background: var(--surface-alt); color: var(--text); font-weight: 650; }
.nav-item.active svg { color: var(--accent); }
.nav-item .count-badge {
  margin-left: auto; font-size: 11px; color: var(--text-faint);
  background: var(--surface-alt); padding: 1px 7px; border-radius: 20px;
}

.nav-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); margin: var(--space-4) var(--space-2) var(--space-1);
  display: flex; align-items: center; justify-content: space-between;
}

.project-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.sidebar-footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--space-2);
}

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0; background: var(--surface-alt);
  border: 1px solid var(--border);
}
.avatar-sm { width: 22px; height: 22px; }
.avatar-lg { width: 56px; height: 56px; }

/* ---------- Main content ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 60px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h1 { font-size: 18px; }

.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), border-color var(--transition);
  position: relative;
}
.icon-btn:hover { background: var(--surface-alt); border-color: var(--border); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.badge-dot {
  position: absolute; top: 5px; right: 5px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--surface);
}

.content-scroll { flex: 1; overflow-y: auto; padding: var(--space-5); }

/* ---------- Cards / KPIs ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-4);
  margin-bottom: var(--space-5);
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4); box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi-card.accent { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: var(--space-4) var(--space-4) var(--space-3);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.card-body { padding: var(--space-4); }

.section-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-4); }
@media (max-width: 1000px) { .section-grid { grid-template-columns: 1fr; } }

/* ---------- Task rows ---------- */
.task-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: var(--surface-alt); }

.checkbox {
  width: 19px; height: 19px; border-radius: 50%;
  border: 2px solid var(--text-faint);
  flex-shrink: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  background: transparent;
}
.checkbox.p-urgent { border-color: var(--danger); }
.checkbox.p-high { border-color: #E08A00; }
.checkbox.p-medium { border-color: var(--info); }
.checkbox.checked { background: var(--success); border-color: var(--success); }
.checkbox.checked svg { width: 11px; height: 11px; color: #fff; }

.task-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.task-row.done .task-title { text-decoration: line-through; color: var(--text-faint); }

.task-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pill {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px;
  background: var(--surface-alt); color: var(--text-muted); white-space: nowrap;
}
.pill.due-overdue { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.pill.due-today { background: color-mix(in srgb, var(--accent) 25%, transparent); color: #8a6800; }
html[data-theme="dark"] .pill.due-today { color: #f2d060; }

.label-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; color: #fff;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-md); font-weight: 600; font-size: 13px;
  cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.btn:hover { background: var(--surface-alt); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
label { font-size: 12px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="search"], input[type="file"], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 13px;
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.field { margin-bottom: var(--space-4); }
.field-row { display: flex; gap: var(--space-3); }
.field-row .field { flex: 1; }

/* ---------- Styled file upload ---------- */
.file-upload { position: relative; }
.file-upload input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.file-upload-trigger {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px dashed var(--border); border-radius: var(--radius-md);
  padding: 14px 16px; background: var(--surface-alt); cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.file-upload:hover .file-upload-trigger { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-alt)); }
.file-upload-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--text-muted);
}
.file-upload-icon svg { width: 16px; height: 16px; }
.file-upload-text { flex: 1; min-width: 0; }
.file-upload-text .fu-title { font-weight: 600; font-size: 13px; }
.file-upload-text .fu-sub { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-upload-btn {
  flex-shrink: 0; padding: 6px 12px; border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text);
}

/* ---------- Modals / panels ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
}
.overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 480px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  transform: translateY(8px) scale(0.98); transition: transform var(--transition);
}
.overlay.open .modal { transform: translateY(0) scale(1); }

.slide-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 100vw;
  background: var(--surface); box-shadow: var(--shadow-lg); z-index: 101;
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 200ms ease;
}
.slide-panel.open { transform: translateX(0); }

.modal-header, .panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4); border-bottom: 1px solid var(--border);
}
.modal-body, .panel-body { padding: var(--space-4); overflow-y: auto; flex: 1; }
.modal-footer { padding: var(--space-4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: var(--space-4); overflow-x: auto; padding-bottom: var(--space-3); height: 100%; }
.kanban-column {
  width: 280px; flex-shrink: 0; background: var(--surface-alt);
  border-radius: var(--radius-lg); padding: var(--space-3); display: flex; flex-direction: column;
  max-height: 100%;
}
.kanban-column-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; font-weight: 650; }
.kanban-cards { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.kanban-cards:empty::after {
  content: "No tasks";
  display: block; text-align: center; padding: 18px 8px; color: var(--text-faint); font-size: 12px;
  border: 1px dashed var(--border); border-radius: var(--radius-md);
}
.kanban-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px; cursor: grab; box-shadow: var(--shadow-sm);
}
.kanban-card.dragging { opacity: 0.4; }
.kanban-cards.drag-over { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: var(--radius-md); }
.kanban-card-title { font-weight: 600; margin-bottom: 8px; font-size: 13px; }
.kanban-card-footer { display: flex; align-items: center; justify-content: space-between; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: var(--space-6) var(--space-4); color: var(--text-muted); }
.empty-state .emoji { font-size: 34px; margin-bottom: var(--space-2); }
.empty-state h3 { margin-bottom: 4px; color: var(--text); }

/* ---------- Toasts ---------- */
#toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
  border-radius: var(--radius-md); padding: 10px 16px; font-size: 13px; font-weight: 500;
  animation: toast-in 200ms ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Command palette ---------- */
.cmdk { width: 560px; max-width: 90vw; }
.cmdk-input { border: none; border-bottom: 1px solid var(--border); border-radius: 0; padding: var(--space-4); font-size: 15px; }
.cmdk-input:focus { box-shadow: none; }
.cmdk-results { max-height: 360px; overflow-y: auto; }
.cmdk-item { padding: 10px var(--space-4); display: flex; align-items: center; gap: 10px; cursor: pointer; }
.cmdk-item:hover, .cmdk-item.active { background: var(--surface-alt); }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: var(--space-4); }
.auth-card { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-md); }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: var(--space-5); justify-content: center; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.mt-4 { margin-top: var(--space-4); }
.mb-3 { margin-bottom: var(--space-3); }
.hidden { display: none !important; }

/* ---------- Jalali date picker ---------- */
.jalali-field { position: relative; }
.jalali-popup {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); padding: 10px; width: 260px; display: none;
}
.jalali-popup.open { display: block; }
.jalali-popup-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 650; font-size: 13px; }
.jalali-popup-header button { background: transparent; border: none; cursor: pointer; color: var(--text-muted); width: 26px; height: 26px; border-radius: var(--radius-sm); }
.jalali-popup-header button:hover { background: var(--surface-alt); }
.jalali-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jalali-grid .jdow { font-size: 10px; text-align: center; color: var(--text-faint); padding: 4px 0; }
.jalali-grid .jday {
  font-size: 12px; text-align: center; padding: 6px 0; border-radius: 6px; cursor: pointer; background: transparent;
}
.jalali-grid .jday:hover { background: var(--surface-alt); }
.jalali-grid .jday.today { border: 1px solid var(--accent); }
.jalali-grid .jday.selected { background: var(--accent); color: var(--accent-contrast); font-weight: 700; }
.jalali-grid .jday.empty { visibility: hidden; }
.jalali-clear { margin-top: 8px; text-align: center; }
.jalali-clear button { background: transparent; border: none; color: var(--text-muted); font-size: 11px; cursor: pointer; }
.jalali-clear button:hover { color: var(--danger); }

/* ---------- Brand logo ---------- */
.brand-logo-img { width: 28px; height: 28px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }


.mobile-topbar { display: none; }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 90;
    transform: translateX(-100%); transition: transform 200ms ease; width: 260px;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px var(--space-4); border-bottom: 1px solid var(--border); background: var(--surface);
  }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .slide-panel { width: 100%; }
  .modal { width: 94vw; }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 89; }
}
