/* ============================================================
   TaskGlass — Glassmorphism Task Management UI
   Design: liquid glass + spring animations + 16px base
   ============================================================ */

/* ============ Design Tokens ============ */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-size: 16px;
  --radius: 18px;
  --radius-sm: 12px;
  --gap: 22px;
  --sidebar-w: 256px;
  --topbar-h: 72px;

  --accent: #10b981;
  --accent-2: #059669;
  --accent-grad: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --good: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --speed: .28s;
}

[data-theme="dark"] {
  --bg-0: #070912;
  --bg-1: #0c1020;
  --text: #eef1fb;
  --text-dim: #9aa3c4;
  --glass: rgba(22, 27, 48, 0.55);
  --glass-2: rgba(30, 36, 62, 0.5);
  --stroke: rgba(255, 255, 255, 0.09);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
  --blob-a: #10b981;
  --blob-b: #059669;
  --blob-c: #2dd4bf;
  --hover: rgba(255, 255, 255, 0.06);
}

[data-theme="light"] {
  --bg-0: #e7ebfa;
  --bg-1: #f3f5ff;
  --text: #141a2e;
  --text-dim: #5a6486;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-2: rgba(255, 255, 255, 0.65);
  --stroke: rgba(20, 26, 46, 0.10);
  --stroke-strong: rgba(20, 26, 46, 0.16);
  --shadow: 0 18px 50px -22px rgba(60, 70, 130, 0.45);
  --blob-a: #34d399;
  --blob-b: #6ee7b7;
  --blob-c: #5eead4;
  --hover: rgba(20, 26, 46, 0.05);
}

/* ============ Reset & Base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: var(--font-size);
  background: var(--bg-0);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}

/* ============ Ambient Background ============ */
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(120% 120% at 100% 0%, var(--bg-1) 0%, var(--bg-0) 55%);
}
.bg::after {
  content: ''; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  pointer-events: none;
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: .55;
  animation: float 22s ease-in-out infinite;
}
.blob.b1 { width: 480px; height: 480px; background: var(--blob-a); top: -120px; left: -80px; }
.blob.b2 { width: 520px; height: 520px; background: var(--blob-b); bottom: -160px; right: -60px; animation-delay: -7s; }
.blob.b3 { width: 360px; height: 360px; background: var(--blob-c); top: 40%; left: 55%; opacity: .35; animation-delay: -14s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.08); }
  66% { transform: translate(-30px, 20px) scale(.95); }
}

/* ============ Glass Primitive ============ */
.glass {
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--shadow);
}

/* ============ App Shell ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  gap: var(--gap);
  padding: var(--gap);
}

/* ---- Sidebar ---- */
.sidebar {
  grid-row: 1;
  display: flex; flex-direction: column;
  padding: 22px 16px;
  position: sticky; top: var(--gap);
  height: calc(100vh - 2 * var(--gap));
  overflow-y: auto;
  transition: transform var(--speed) var(--ease);
  z-index: 60;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 10px 22px;
}
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent-grad);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 8px 24px -8px var(--accent); flex: none;
}
.brand .name { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.brand .name span { color: var(--text-dim); font-weight: 600; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  font-size: 11px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--text-dim);
  padding: 16px 12px 8px;
}
.nav a {
  display: flex; align-items: center; gap: 13px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); text-decoration: none;
  font-size: 15px; font-weight: 600;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
  position: relative;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(16, 185, 129, .22), rgba(5, 150, 105, .18));
  border: 1px solid var(--stroke-strong);
}
.nav a.active::before {
  content: ""; position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 22px; border-radius: 0 4px 4px 0; background: var(--accent-grad);
}

/* ---- AI Sidebar Panel ---- */
.side-foot { margin-top: auto; }
.ai-panel {
  padding: 14px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(16, 185, 129, .08), rgba(5, 150, 105, .06));
  border: 1px solid rgba(16, 185, 129, .2);
}
.ai-panel-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700; color: var(--text-dim);
  margin-bottom: 10px; text-transform: uppercase; letter-spacing: .06em;
}
.ai-panel-header svg { width: 14px; height: 14px; }

/* AI panel states */
.ai-input-area {
  transition: transform .4s var(--spring), margin-bottom .4s var(--spring);
  margin-bottom: 10px;
}
.ai-input-area.shift-up { transform: translateY(-8px); margin-bottom: 14px; }

.ai-panel textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  color: var(--text); font-family: var(--font); font-size: 14px; outline: none;
  resize: none; min-height: 48px;
  transition: border-color var(--speed) var(--ease);
}
.ai-panel textarea:focus { border-color: var(--accent); }
.ai-hint {
  font-size: 12px; color: var(--warn);
  padding: 6px 10px; margin-bottom: 8px;
  background: rgba(180, 83, 9, .1); border: 1px solid rgba(180, 83, 9, .2);
  border-radius: 8px; line-height: 1.4;
}

.ai-result-list {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px;
  max-height: 200px; overflow-y: auto;
}
.ai-result-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; font-size: 13px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  cursor: pointer; transition: all var(--speed) var(--ease);
  animation: slideInUp .3s var(--spring) backwards;
}
.ai-result-item:hover { border-color: var(--stroke-strong); }
.ai-result-item.editing { border-color: var(--accent); background: rgba(16, 185, 129, .1); }
.ai-result-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-result-item .remove-btn {
  width: 20px; height: 20px; border-radius: 5px; border: none;
  background: transparent; color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; font-size: 14px; flex: none;
}
.ai-result-item .remove-btn:hover { color: var(--bad); }

.ai-actions { display: flex; gap: 6px; }
.ai-actions button {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  font-size: 12px; font-weight: 700; cursor: pointer;
  border: none; transition: all var(--speed) var(--ease);
}
.ai-actions button:active { transform: scale(.96); }
.btn-ai-parse { background: var(--accent-grad); color: #fff; }
.btn-ai-parse:hover { transform: translateY(-1px); box-shadow: 0 4px 12px -4px var(--accent); }
.btn-ai-apply { background: var(--good); color: #fff; }
.btn-ai-apply:hover { transform: translateY(-1px); }
.btn-ai-apply.done { animation: pop .4s var(--spring); }

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ---- Main ---- */
.main {
  grid-row: 1;
  display: flex; flex-direction: column; gap: var(--gap);
  min-width: 0; overflow-y: auto; padding-right: 2px;
}
#pageContent {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
}

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px; height: var(--topbar-h);
  position: sticky; top: 0; z-index: 40;
}
.hamburger {
  display: none; width: 40px; height: 40px; border-radius: 11px;
  border: 1px solid var(--stroke); background: var(--glass-2);
  color: var(--text); cursor: pointer; place-items: center;
}
.page-title { display: flex; flex-direction: column; }
.page-title h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.page-title p { font-size: 13px; color: var(--text-dim); }

.search {
  margin-left: auto; display: flex; align-items: center; gap: 9px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  border-radius: 11px; padding: 9px 13px; width: 280px; max-width: 36vw; color: var(--text-dim);
}
.search svg { width: 16px; height: 16px; flex: none; }
.search input {
  border: 0; background: transparent; outline: none;
  color: var(--text); font-family: var(--font); font-size: 14px; width: 100%;
}
.search input::placeholder { color: var(--text-dim); }
.search kbd {
  font-size: 10.5px; font-weight: 700; color: var(--text-dim);
  border: 1px solid var(--stroke-strong); border-radius: 6px; padding: 2px 6px;
}

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px;
  border: 1px solid var(--stroke); background: var(--glass-2);
  color: var(--text); cursor: pointer;
  display: grid; place-items: center; position: relative;
  transition: background var(--speed) var(--ease), transform var(--speed) var(--ease); flex: none;
}
.icon-btn:hover { background: var(--hover); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .dot {
  position: absolute; top: 9px; right: 10px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--bad); border: 2px solid var(--bg-0);
}
.theme-icon .sun { display: none; }
[data-theme="light"] .theme-icon .sun { display: block; }
[data-theme="light"] .theme-icon .moon { display: none; }

/* ============ KPI Grid ============ */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); margin-bottom: 28px; }
.kpi {
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
  transition: transform var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.kpi:hover { transform: translateY(-3px); border-color: var(--stroke-strong); }
.kpi .row { display: flex; align-items: center; justify-content: space-between; }
.kpi .ico {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff;
}
.ico.i1 { background: linear-gradient(135deg, #34d399, #10b981); }
.ico.i2 { background: linear-gradient(135deg, #2dd4bf, #14b8a6); }
.ico.i3 { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.ico.i4 { background: linear-gradient(135deg, #059669, #047857); }
.kpi .ico svg { width: 20px; height: 20px; }
.kpi .val { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.kpi .lbl { font-size: 13px; color: var(--text-dim); font-weight: 600; }

/* ============ Task List ============ */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; margin-bottom: 16px; }
.filter-pill {
  padding: 7px 15px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all var(--speed) var(--ease);
  background: transparent; color: var(--text-dim); border: 1px solid transparent;
}
.filter-pill.active { background: var(--glass-2); color: var(--text); border-color: var(--stroke-strong); }
.filter-pill:hover:not(.active) { background: var(--hover); }
.filter-select {
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all var(--speed) var(--ease);
  background: var(--glass-2); color: var(--text); border: 1px solid var(--stroke);
  outline: none; font-family: var(--font); appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 30px;
}
.filter-select:hover { border-color: var(--stroke-strong); }

.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-item {
  display: flex; align-items: flex-start; gap: 14px; padding: 16px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--speed) var(--ease);
  animation: rise .5s var(--ease) backwards;
  position: relative;
}
.task-item.pinned {
  border-color: var(--warn);
  background: rgba(217, 119, 6, .08);
}
.task-item:hover { background: var(--hover); border-color: var(--stroke-strong); }
.task-item.completed { opacity: .55; }
.task-item.completed .task-title { text-decoration: line-through; color: var(--text-dim); }

.checkbox {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--stroke-strong);
  flex-shrink: 0; cursor: pointer; transition: all var(--speed) var(--ease);
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.checkbox:hover { border-color: var(--accent); }
.checkbox.checked { background: var(--good); border-color: var(--good); }
.checkbox.checked::after {
  content: ''; width: 6px; height: 11px;
  border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.task-content { flex: 1; min-width: 0; position: relative; padding-left: 12px; }
.task-color-bar {
  position: absolute; left: 0; top: 4px; bottom: 4px;
  width: 4px; border-radius: 2px;
}
.task-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.task-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 999px; font-size: 11px; font-weight: 600;
}
.tag-homework { background: rgba(99, 102, 241, .2); color: #a5b4fc; }
[data-theme="light"] .tag-homework { color: #4338ca; }
.tag-report { background: rgba(251, 191, 36, .2); color: #fcd34d; }
[data-theme="light"] .tag-report { color: #a16207; }
.tag-competition { background: rgba(236, 72, 153, .2); color: #f9a8d4; }
[data-theme="light"] .tag-competition { color: #be185d; }
.tag-other { background: rgba(156, 163, 175, .2); color: #d1d5db; }
[data-theme="light"] .tag-other { color: #4b5563; }
.task-date { font-size: 12px; color: var(--text-dim); }
.task-date.overdue { color: var(--bad); }
.task-actions { display: flex; gap: 6px; align-items: center; }
.task-actions button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--stroke);
  background: transparent; color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; transition: all var(--speed) var(--ease);
}
.task-actions button:hover { background: var(--hover); color: var(--text); border-color: var(--stroke-strong); }

/* Flag color dot (like mobile flag 0-7) */
.flag-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 8px;
  border: 1px solid rgba(0,0,0,.15);
}
.flag-1 { background: #ef4444; }
.flag-2 { background: #f97316; }
.flag-3 { background: #eab308; }
.flag-4 { background: #22c55e; }
.flag-5 { background: #3b82f6; }
.flag-6 { background: #a855f7; }
.flag-7 { background: #6b7280; }

/* ============ Charts ============ */
.charts { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--gap); }
.panel { padding: 22px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h3 { font-size: 16px; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.panel-head p { font-size: 13px; color: var(--text-dim); }
.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--glass-2); border: 1px solid var(--stroke); border-radius: 10px;
}
.seg button {
  border: 0; background: transparent; color: var(--text-dim);
  font-family: var(--font); font-weight: 700; font-size: 12px;
  padding: 5px 11px; border-radius: 7px; cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.seg button.on { background: var(--accent-grad); color: #fff; }

.chart-svg { width: 100%; height: 200px; display: block; }
.bar { transition: opacity var(--speed) var(--ease); cursor: pointer; transform-box: fill-box; transform-origin: bottom; }
.bar:hover { opacity: .8; }
body.loaded .bar { animation: grow .7s var(--ease) backwards; }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

.legend { display: flex; gap: 18px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-dim); font-weight: 600; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { position: relative; width: 150px; height: 150px; flex: none; }
.donut .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .center b { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; display: block; }
.donut .center small { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.donut circle { transition: stroke-dashoffset 1s var(--ease); }
.stat-list { display: flex; flex-direction: column; gap: 13px; flex: 1; min-width: 120px; }
.stat-list .item { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.stat-list .item i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.stat-list .item b { margin-left: auto; font-weight: 800; }
.stat-list .item span { color: var(--text-dim); }

/* ============ FAB ============ */
.fab {
  position: fixed; bottom: 28px; right: 28px; width: 56px; height: 56px;
  border-radius: 16px; background: var(--accent-grad); border: none;
  color: #fff; cursor: pointer; z-index: 70;
  display: grid; place-items: center;
  box-shadow: 0 12px 32px -8px var(--accent);
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 16px 40px -8px var(--accent); }
.fab:active { transform: scale(.95); }
.fab svg { width: 24px; height: 24px; }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 5, 12, .6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 80; animation: fadeIn .2s var(--ease);
}
.modal {
  width: 92%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  padding: 28px; animation: bounceIn .35s var(--spring);
}
.modal h2 { font-size: 20px; font-weight: 800; margin-bottom: 20px; letter-spacing: -0.02em; }
.modal .field { margin-bottom: 16px; }
.modal label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }
.modal input, .modal textarea, .modal select {
  width: 100%; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--glass-2); border: 1px solid var(--stroke);
  color: var(--text); font-family: var(--font); font-size: 14px; outline: none;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
  appearance: none; -webkit-appearance: none;
}
.modal input:focus, .modal textarea:focus, .modal select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(16, 185, 129, .15);
}
.modal textarea { resize: none; min-height: 80px; }
.modal select {
  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='%239aa3c4' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.modal .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 24px; }

.btn {
  flex: 1; padding: 12px 20px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 14px; cursor: pointer;
  border: none; transition: all var(--speed) var(--ease);
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--accent-grad); color: #fff; box-shadow: 0 8px 24px -8px var(--accent); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 28px -8px var(--accent); }
.btn-ghost { background: var(--glass-2); color: var(--text); border: 1px solid var(--stroke); }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { background: rgba(251, 113, 133, .15); color: var(--bad); }
.btn-danger:hover { background: rgba(251, 113, 133, .25); }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: .4; }
.empty-state h3 { font-size: 16px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 13px; }

/* ============ Notes Grid ============ */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.note-card {
  padding: 18px; border-radius: var(--radius-sm);
  background: var(--glass-2); border: 1px solid var(--stroke);
  cursor: pointer; transition: all var(--speed) var(--ease);
  animation: rise .4s var(--ease) backwards;
}
.note-card:hover { transform: translateY(-2px); border-color: var(--stroke-strong); }
.note-card h4 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.note-card p {
  font-size: 13px; color: var(--text-dim); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.note-card .date { font-size: 11px; color: var(--text-dim); margin-top: 12px; }

/* ============ Settings ============ */
.settings-section { margin-bottom: 24px; }
.settings-section h4 {
  font-size: 12px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 12px;
}
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--stroke);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .label { font-size: 15px; font-weight: 600; }
.setting-row .desc { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.toggle {
  width: 48px; height: 26px; border-radius: 13px; background: var(--glass-2);
  border: 1px solid var(--stroke); cursor: pointer; position: relative;
  transition: background var(--speed) var(--ease); flex: none;
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform var(--speed) var(--ease);
}
.toggle.on::after { transform: translateX(22px); }

/* ============ File Preview Lightbox ============ */
.file-preview-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(3, 5, 12, .85); backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s var(--ease); cursor: pointer; padding: 40px;
}
.file-preview-content {
  max-width: 90vw; max-height: 85vh; overflow: auto;
  border-radius: var(--radius-sm); animation: bounceIn .3s var(--spring); cursor: default;
}
.file-preview-content img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: var(--radius-sm); display: block; }
.file-preview-content iframe { width: 80vw; height: 80vh; border: none; border-radius: var(--radius-sm); background: #fff; }
.file-preview-content .md-preview {
  padding: 32px; background: var(--bg-1); color: var(--text);
  border-radius: var(--radius-sm); max-width: 750px; line-height: 1.75; font-size: 15px;
  text-wrap: pretty; border: 1px solid var(--stroke);
}
.file-preview-content .md-preview h1 { font-size: 1.8em; margin: 0 0 0.6em; font-weight: 800; letter-spacing: -0.02em; }
.file-preview-content .md-preview h2 { font-size: 1.4em; margin: 1.2em 0 0.5em; font-weight: 700; }
.file-preview-content .md-preview h3 { font-size: 1.15em; margin: 1em 0 0.4em; font-weight: 700; }
.file-preview-content .md-preview p { margin-bottom: 0.9em; }
.file-preview-content .md-preview ul, .file-preview-content .md-preview ol { margin: 0.8em 0; padding-left: 1.5em; }
.file-preview-content .md-preview li { margin-bottom: 0.35em; }
.file-preview-content .md-preview code {
  background: rgba(127,127,127,0.15); padding: 2px 6px;
  border-radius: 4px; font-size: 0.88em; font-family: 'SF Mono', 'Fira Code', monospace;
}
.file-preview-content .md-preview pre {
  background: rgba(0,0,0,0.06); padding: 16px; border-radius: 8px;
  overflow-x: auto; margin: 1em 0; border: 1px solid var(--stroke);
}
[data-theme="dark"] .file-preview-content .md-preview pre { background: rgba(0,0,0,0.3); }
.file-preview-content .md-preview pre code { background: none; padding: 0; }
.file-preview-content .md-preview strong { font-weight: 700; }
.file-preview-content .md-preview em { font-style: italic; }
/* Table styles with borders */
.file-preview-content .md-preview table {
  width: 100%; border-collapse: collapse; margin: 1em 0;
  font-size: 0.92em;
}
.file-preview-content .md-preview th,
.file-preview-content .md-preview td {
  padding: 10px 14px; text-align: left;
  border: 1px solid var(--stroke-strong);
}
.file-preview-content .md-preview th {
  background: rgba(127,127,127,0.1); font-weight: 700;
  font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.04em;
}
.file-preview-content .md-preview tr:nth-child(even) td {
  background: rgba(127,127,127,0.04);
}
.file-preview-content .md-preview tr:hover td {
  background: rgba(127,127,127,0.08);
}
.file-preview-close {
  position: fixed; top: 20px; right: 24px; z-index: 91;
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .15);
  color: #fff; cursor: pointer; font-size: 18px;
  display: grid; place-items: center; transition: background var(--speed) var(--ease);
}
.file-preview-close:hover { background: rgba(255, 255, 255, .2); }

/* File upload label in modal */
.file-upload-label {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: var(--glass-2); border: 1px solid var(--stroke); border-radius: 12px;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-dim);
  transition: all var(--speed) var(--ease);
}
.file-upload-label:hover { background: var(--hover); border-color: var(--stroke-strong); color: var(--text); }

/* File grid in modal */
.file-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px; margin-top: 12px;
}
.file-cell {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm);
  background: var(--glass-2); border: 1px solid var(--stroke);
  overflow: hidden; cursor: pointer;
  transition: all var(--speed) var(--ease);
  display: flex; align-items: center; justify-content: center;
}
.file-cell:hover { border-color: var(--stroke-strong); transform: scale(1.03); }
.file-cell img { width: 100%; height: 100%; object-fit: cover; }
.file-cell .file-icon {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-dim); text-align: center; padding: 4px;
}
.file-cell .file-icon svg { width: 28px; height: 28px; }
.file-cell .file-name {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 3px 4px; font-size: 10px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-cell .file-remove {
  position: absolute; top: 3px; right: 3px; z-index: 2;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.6); border: none; color: #fff;
  cursor: pointer; font-size: 12px; display: grid; place-items: center;
  opacity: 0; transition: opacity var(--speed) var(--ease);
}
.file-cell:hover .file-remove { opacity: 1; }
.file-cell .file-remove:hover { background: var(--bad); }

/* ============ Animations ============ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: scale(1); } }
@keyframes bounceIn {
  0% { opacity: 0; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.03); }
  100% { transform: scale(1); }
}
@keyframes slideInUp {
  from { opacity: 0; transform: translateY(8px) scale(.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.reveal { opacity: 0; }
body.loaded .reveal { animation: rise .6s var(--ease) forwards; animation-delay: var(--d, 0s); }

/* Scrim */
.scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(3, 5, 12, .55); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity var(--speed) var(--ease);
}
body.nav-open .scrim { opacity: 1; pointer-events: auto; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .15); border-radius: 3px; }

/* Focus */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  :root { --gap: 16px; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto; padding: 14px; }
  .hamburger { display: grid; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100vh;
    width: 280px; border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-105%); background: var(--glass);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .main { overflow: visible; }
  .topbar { top: 14px; }
  .fab { bottom: 20px; right: 20px; }
}
/* ============ Login Page ============ */
.login-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-box {
  width: 100%; max-width: 380px; padding: 40px 32px;
  text-align: center;
}
.login-logo {
  width: 72px; height: 72px; border-radius: 20px;
  background: var(--accent-grad); display: grid; place-items: center;
  color: #fff; margin: 0 auto 20px;
}
.login-logo svg { width: 36px; height: 36px; }
.login-box h2 { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.login-subtitle { font-size: 14px; color: var(--text-dim); margin-bottom: 24px; }
.login-box input {
  width: 100%; padding: 14px 18px; border-radius: var(--radius-sm);
  background: var(--glass-2); border: 1px solid var(--stroke);
  color: var(--text); font-family: var(--font); font-size: 16px; outline: none;
  transition: border-color var(--speed) var(--ease);
}
.login-box input:focus { border-color: var(--accent); }

@media (max-width: 560px) {
  .kpis { grid-template-columns: 1fr; }
  .search { display: none; }
  .page-title p { display: none; }
  .donut-wrap { justify-content: center; }
  .modal .row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============ Subtasks ============ */
.subtasks-list {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px;
}
.subtasks-empty {
  font-size: 12px; color: var(--text-dim); padding: 8px 0;
}
.subtask-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  border-radius: 8px; transition: all var(--speed) var(--ease);
}
.subtask-item:hover { border-color: var(--stroke-strong); }
.subtask-item.completed .subtask-title { text-decoration: line-through; color: var(--text-dim); }
.subtask-checkbox {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--stroke-strong);
  flex-shrink: 0; cursor: pointer; transition: all var(--speed) var(--ease);
  display: flex; align-items: center; justify-content: center;
}
.subtask-checkbox:hover { border-color: var(--accent); }
.subtask-checkbox.checked { background: var(--good); border-color: var(--good); }
.subtask-checkbox.checked::after {
  content: ''; width: 5px; height: 9px;
  border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
.subtask-title { flex: 1; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subtask-remove {
  width: 20px; height: 20px; border-radius: 5px; border: none;
  background: transparent; color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; font-size: 14px; flex: none;
}
.subtask-remove:hover { color: var(--bad); }
.subtask-add {
  display: flex; gap: 6px;
}
.subtask-add input {
  flex: 1; padding: 6px 10px; border-radius: 8px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  color: var(--text); font-family: var(--font); font-size: 13px; outline: none;
}
.subtask-add input:focus { border-color: var(--accent); }

.tag-subtask { background: rgba(15, 118, 110, .15); color: #0f766e; }
[data-theme="light"] .tag-subtask { background: rgba(15, 118, 110, .1); color: #0f766e; }
.tag-reminder { background: rgba(217, 119, 6, .15); color: #b45309; }
[data-theme="light"] .tag-reminder { background: rgba(217, 119, 6, .1); color: #b45309; }
.tag-repeat { background: rgba(3, 105, 161, .15); color: #0369a1; }
[data-theme="light"] .tag-repeat { background: rgba(3, 105, 161, .1); color: #0369a1; }

/* ============ Calendar ============ */
.calendar-section {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
}
.calendar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0 16px; flex-shrink: 0;
}
.calendar-title { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.calendar-today-btn { margin-left: auto; }
.calendar-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: 1fr;
  gap: var(--gap);
  flex: 1; min-height: 0;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(6, 1fr);
  gap: 4px;
  min-height: 0;
}
.calendar-day-header {
  text-align: center; font-size: 13px; font-weight: 700; color: var(--text-dim);
  padding: 8px 0 4px; display: flex; align-items: center; justify-content: center;
}
.calendar-day {
  display: flex; flex-direction: column;
  align-items: flex-start; justify-content: flex-start;
  gap: 4px;
  border-radius: 12px; cursor: pointer; position: relative;
  transition: all var(--speed) var(--ease);
  padding: 8px 8px; min-height: 0; overflow: hidden;
  background: var(--glass-2); border: 1px solid var(--stroke);
  font-size: 14px;
}
.calendar-day:hover { background: var(--hover); border-color: var(--stroke-strong); }
.calendar-day.today { background: var(--accent); color: #fff; border-color: var(--accent); }
.calendar-day.selected { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
.calendar-day.empty { background: transparent; border-color: transparent; cursor: default; }
.calendar-day.empty:hover { background: transparent; }
.day-num { font-weight: 700; font-size: 14px; line-height: 1; opacity: .85; }
.calendar-day.today .day-num { opacity: 1; }
.day-tasks { display: flex; flex-direction: column; gap: 2px; width: 100%; overflow: hidden; }
.day-task-name {
  display: block; font-size: 11px; line-height: 1.35; padding: 3px 6px;
  background: var(--accent); color: #fff; border-radius: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600;
}
.day-task-name.completed { text-decoration: line-through; opacity: .55; background: var(--text-dim); }
.day-more { font-size: 10px; color: var(--text-dim); font-weight: 700; padding-left: 2px; }
.calendar-day.today .day-task-name { background: #fff; color: var(--accent); }
.calendar-day.selected .day-task-name { background: var(--accent-2); color: #fff; }
.calendar-day-tasks {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--glass-2); border: 1px solid var(--stroke);
  border-radius: var(--radius-sm); padding: 16px; overflow: hidden;
}
.calendar-day-tasks-head {
  font-size: 14px; font-weight: 800; margin-bottom: 12px;
  display: flex; align-items: baseline; gap: 8px; flex-shrink: 0;
}
.calendar-day-tasks-head .date { color: var(--text-dim); font-weight: 600; font-size: 13px; }
.calendar-day-tasks-list {
  flex: 1; overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.calendar-task-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--glass); border: 1px solid var(--stroke);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--speed) var(--ease);
}
.calendar-task-item:hover { border-color: var(--stroke-strong); }
.calendar-task-item.completed { opacity: .55; }
.calendar-task-item.completed .calendar-task-title { text-decoration: line-through; }
.calendar-task-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent); }
.calendar-task-item.completed .calendar-task-dot { background: var(--text-dim); }
.calendar-task-title {
  font-weight: 600; font-size: 14px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.calendar-task-time { font-size: 12px; color: var(--text-dim); flex: none; }

@media (max-width: 860px) {
  .calendar-body { grid-template-columns: minmax(0, 1fr); }
  .calendar-day-tasks { max-height: 44vh; }
}
@media (max-width: 560px) {
  .calendar-day-header { font-size: 11px; }
  .day-num { font-size: 13px; }
  .day-task-name { font-size: 10px; }
}
