:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #f0eef8;
  --border: #e3e0ef;
  --text: #1d1b2c;
  --muted: #6b6884;
  --accent: #6d4aff;
  --accent-soft: #ece6ff;
  --ok: #138a5b;
  --ok-soft: #dcf5ea;
  --warn: #b26a00;
  --warn-soft: #fff1d6;
  --bad: #c62f4b;
  --bad-soft: #fde3e8;
  --info: #1f6fd1;
  --info-soft: #e1edfc;
  --a-ielts: #1f6fd1;
  --a-apply: #8a3ffc;
  --a-paper: #d12771;
  --a-work: #0f8a7d;
  --a-personal: #d97706;
  --a-cv: #4f5bd5;
  --a-life: #5f8a1f;
  --shadow: 0 1px 2px rgba(30, 20, 70, .05), 0 4px 16px rgba(30, 20, 70, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12111a; --surface: #1b1a26; --surface-2: #242233; --border: #312e44;
    --text: #ecebf5; --muted: #a09cb8; --accent: #9d85ff; --accent-soft: #2c2650;
    --ok: #4fd39b; --ok-soft: #173a2c; --warn: #f2b14c; --warn-soft: #3b2d14;
    --bad: #ff7d93; --bad-soft: #42202a; --info: #71aaf5; --info-soft: #1a2c46;
    --a-ielts: #71aaf5; --a-apply: #b48cff; --a-paper: #ff7cb2; --a-work: #46c9b9;
    --a-personal: #f5a742; --a-cv: #8f98ff; --a-life: #9ccf57;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12111a; --surface: #1b1a26; --surface-2: #242233; --border: #312e44;
  --text: #ecebf5; --muted: #a09cb8; --accent: #9d85ff; --accent-soft: #2c2650;
  --ok: #4fd39b; --ok-soft: #173a2c; --warn: #f2b14c; --warn-soft: #3b2d14;
  --bad: #ff7d93; --bad-soft: #42202a; --info: #71aaf5; --info-soft: #1a2c46;
  --a-ielts: #71aaf5; --a-apply: #b48cff; --a-paper: #ff7cb2; --a-work: #46c9b9;
  --a-personal: #f5a742; --a-cv: #8f98ff; --a-life: #9ccf57;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Vazirmatn", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
small, .small { font-size: 12px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand b { display: block; font-size: 16px; }
.brand small { color: var(--muted); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--a-paper)); color: #fff; font-weight: 700;
}
nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  color: var(--text); font-weight: 500; margin-bottom: 2px;
}
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { background: var(--accent-soft); color: var(--accent); }
nav a .ico { width: 20px; text-align: center; }
nav a .count { margin-left: auto; font-size: 11px; color: var(--muted); }
nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }

.main { flex: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; }
.today { margin-left: auto; text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.today b { color: var(--text); font-size: 13px; }
.icon-btn { display: none; }
.view { padding: 24px; max-width: 1360px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.mt { margin-top: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }

/* stat tiles */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat-accent { border-top: 3px solid var(--c, var(--accent)); }

/* countdowns */
.countdowns { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.countdown {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.countdown .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.countdown small { display: block; color: var(--muted); }

/* forms & buttons */
button, .btn {
  font: inherit; border: 1px solid transparent; background: var(--accent); color: #fff; padding: 7px 14px;
  border-radius: 10px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
}
button:hover { filter: brightness(1.05); }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.ghost:hover { background: var(--surface-2); }
button.danger { background: var(--bad); }
button.small { padding: 4px 10px; font-size: 12px; }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.field.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input[type="text"] { flex: 1; min-width: 180px; }

/* chips, badges */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; font-weight: 500; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 9px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.area { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.area::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ac, var(--muted)); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; text-align: right; }

/* lists */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: none; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow-wrap: anywhere; }
.item .meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 2px; }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.item .x { opacity: 0; transition: opacity .15s; }
.item:hover .x { opacity: 1; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 13px; }

/* progress */
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 99px; transition: width .3s; }

/* project & bucket cards */
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.pcard { display: flex; flex-direction: column; gap: 8px; cursor: pointer; border-left: 4px solid var(--ac, var(--accent)); }
.pcard:hover { border-color: var(--accent); }
.pcard p { margin: 0; color: var(--muted); font-size: 13px; }
.pcard .foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: auto; font-size: 12px; color: var(--muted); }
.stack { display: flex; gap: 4px; flex-wrap: wrap; }
.stack span { font-size: 11px; background: var(--surface-2); border-radius: 6px; padding: 1px 6px; color: var(--muted); }
.stars { color: #f5a623; letter-spacing: 1px; }
.bcard { cursor: pointer; display: flex; gap: 12px; align-items: flex-start; }
.bcard .emoji { font-size: 26px; line-height: 1; }

/* timeline */
.timeline { display: flex; flex-direction: column; gap: 0; position: relative; }
.tl { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; padding: 10px 0; cursor: pointer; position: relative; }
.tl::before { content: ""; position: absolute; left: 13px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.tl:first-child::before { top: 18px; }
.tl:last-child::before { bottom: calc(100% - 18px); }
.tl .dot {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 2px solid var(--border); z-index: 1; position: relative;
}
.tl.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.tl.doing .dot { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.tl p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* habits */
.habit { display: grid; grid-template-columns: minmax(140px, 1fr) repeat(7, 30px) 70px; gap: 6px; align-items: center; padding: 6px 0; }
.habit .day {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; display: grid; place-items: center; font-size: 13px; padding: 0; color: transparent;
}
.habit .day.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.habit .day.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.habit-head { font-size: 11px; color: var(--muted); text-align: center; }

/* week planner */
.week { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; }
.wday { background: var(--surface-2); border-radius: 12px; padding: 10px; min-height: 140px; }
.wday.is-today { outline: 2px solid var(--accent); }
.wday h3 { font-size: 12px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.wtask { background: var(--surface); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; margin-bottom: 6px; border-left: 3px solid var(--ac, var(--accent)); cursor: pointer; }
.wtask.done { opacity: .5; text-decoration: line-through; }

/* flashcard */
.flash {
  min-height: 170px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 8px; background: linear-gradient(135deg, var(--accent-soft), var(--surface-2)); padding: 20px;
}
.flash .word { font-size: 26px; font-weight: 700; }

/* charts */
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
svg.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.ring { position: relative; width: 92px; height: 92px; flex: none; }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; }

/* timer */
.timer { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* modal & toast */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 8, 25, .45); z-index: 50; display: grid; place-items: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 16px; width: min(640px, 100%); max-height: 90vh; overflow: auto;
  padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); border: 1px solid var(--border);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; z-index: 60; font-weight: 500; box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }
[dir="auto"] { unicode-bidi: plaintext; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 12px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.note { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 13px; }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span3 { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .2s; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .icon-btn { display: inline-flex; background: none; color: var(--text); border: 1px solid var(--border); padding: 6px 10px; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .today { display: none; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .habit { grid-template-columns: minmax(100px, 1fr) repeat(7, 26px); }
  .habit .day { width: 26px; height: 26px; }
  .habit .wk { display: none; }
}
.cd-row { display: grid; grid-template-columns: 48px minmax(0, 1fr) 150px auto; gap: 8px; margin-bottom: 8px; align-items: center; }
@media (max-width: 760px) { .cd-row { grid-template-columns: 44px minmax(0, 1fr) auto; } .cd-row input[type="date"] { grid-column: 2; } }
.who { padding: 0 6px 10px; display: flex; flex-direction: column; }
.who small { color: var(--muted); }
.wevent { background: color-mix(in srgb, var(--ac) 14%, var(--surface)); }
.code-box { display: flex; gap: 8px; align-items: center; }
.code-box input { flex: 1; font-family: ui-monospace, monospace; font-size: 12px; }
.bookmarklet { display: inline-flex; padding: 8px 14px; border-radius: 10px; border: 2px dashed var(--accent); font-weight: 600; cursor: grab; }
.steps { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: var(--muted); }
.steps li { margin-bottom: 4px; }
.cal-row { display: grid; grid-template-columns: 40px 130px minmax(0, 1fr) auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.cal-row input[type="color"] { padding: 2px; height: 34px; width: 40px; }
details summary { cursor: pointer; }
@media (max-width: 760px) { .cal-row { grid-template-columns: 40px minmax(0, 1fr) auto; } .cal-row input[type="url"] { grid-column: 1 / -1; } }
