:root {
  --bg: #f7f6fb;
  --surface: #ffffff;
  --surface-2: #f1eff8;
  --text: #23212b;
  --muted: #777383;
  --border: #e7e3ef;
  --primary: #7567ea;
  --primary-dark: #6154d8;
  --primary-soft: #eeeafd;
  --green: #2b9c72;
  --green-soft: #e4f6ee;
  --peach: #ef8c59;
  --peach-soft: #fff0e7;
  --blue: #4388da;
  --blue-soft: #eaf3ff;
  --rose: #d96389;
  --danger: #d94f65;
  --shadow: 0 18px 50px rgba(47, 42, 76, 0.08);
  --shadow-soft: 0 8px 28px rgba(47, 42, 76, 0.055);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

[data-theme="dark"] {
  --bg: #17161d;
  --surface: #211f29;
  --surface-2: #2a2734;
  --text: #f4f1fb;
  --muted: #aaa4b7;
  --border: #383442;
  --primary: #9388ff;
  --primary-dark: #a79eff;
  --primary-soft: #322e4b;
  --green-soft: #21392f;
  --peach-soft: #3a2d26;
  --blue-soft: #243346;
  --shadow: 0 18px 50px rgba(0, 0, 0, .25);
  --shadow-soft: 0 8px 28px rgba(0,0,0,.18);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(117, 103, 234, .22); outline-offset: 2px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 20; }
.brand-wrap { display: flex; justify-content: space-between; align-items: center; }
.brand { border: 0; background: transparent; display: flex; align-items: center; gap: 12px; color: inherit; text-align: left; padding: 0 10px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; background: linear-gradient(135deg, var(--primary), #a48df5); color: #fff; display: grid; place-items: center; font-weight: 850; letter-spacing: -.03em; box-shadow: 0 10px 24px rgba(117, 103, 234, .28); }
.brand-mark.large { width: 58px; height: 58px; border-radius: 18px; font-size: 1.1rem; margin: 0 auto 8px; }
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 1rem; }
.brand-copy small { color: var(--muted); font-size: .72rem; }
.nav-list { display: grid; gap: 7px; margin-top: 38px; }
.nav-item { width: 100%; border: 0; color: var(--muted); background: transparent; padding: 12px 14px; border-radius: 14px; display: flex; align-items: center; gap: 12px; font-weight: 700; text-align: left; transition: .2s ease; }
.nav-item:hover { background: var(--surface-2); color: var(--text); transform: translateX(2px); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }
.nav-icon { width: 28px; height: 28px; border-radius: 10px; background: rgba(117,103,234,.08); display: grid; place-items: center; font-weight: 900; }
.nav-item.active .nav-icon { background: rgba(117,103,234,.14); }
.sidebar-note { margin-top: auto; padding: 16px; border-radius: 16px; background: linear-gradient(140deg, var(--surface-2), var(--primary-soft)); display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.sidebar-note strong, .sidebar-note span { display: block; }
.sidebar-note strong { font-size: .78rem; }
.sidebar-note span { font-size: .7rem; color: var(--muted); margin-top: 3px; }
.note-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); margin-top: 4px; box-shadow: 0 0 0 5px rgba(43,156,114,.12); }
.sidebar-overlay { display: none; }

.main-area { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 15; min-height: 86px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 18px clamp(20px, 4vw, 52px); border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent); }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 { margin: 0; font-size: clamp(1.35rem, 2vw, 1.75rem); letter-spacing: -.035em; }
.eyebrow, .section-kicker { margin: 0; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--primary); font-weight: 850; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--peach-soft); color: var(--peach); font-weight: 850; display: grid; place-items: center; border: 1px solid color-mix(in srgb, var(--peach) 18%, transparent); }
.menu-btn, .mobile-only { display: none !important; }

.page { display: none; padding: 30px clamp(20px, 4vw, 52px) 56px; animation: fadeUp .25s ease; }
.page.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

button { border: 0; }
.primary-btn, .soft-btn, .ghost-btn, .danger-btn { min-height: 42px; padding: 0 16px; border-radius: 13px; font-weight: 800; transition: transform .18s ease, box-shadow .18s ease, background .18s ease; }
.primary-btn { background: var(--primary); color: #fff; box-shadow: 0 10px 22px rgba(117,103,234,.2); }
.primary-btn:hover { transform: translateY(-1px); background: var(--primary-dark); box-shadow: 0 12px 26px rgba(117,103,234,.27); }
.soft-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.soft-btn:hover, .ghost-btn:hover { transform: translateY(-1px); background: var(--primary-soft); }
.ghost-btn { background: transparent; color: var(--muted); display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); }
.danger-btn { background: #fff0f3; color: var(--danger); border: 1px solid rgba(217,79,101,.18); }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); display: grid; place-items: center; }
.text-btn, .danger-link { background: transparent; padding: 7px 0; font-weight: 800; color: var(--primary); }
.danger-link { color: var(--danger); }
.compact { min-height: 36px; padding: 0 13px; }
.big { min-height: 52px; display: grid; place-items: center; }
.hidden { display: none !important; }

.hero-card { min-height: 250px; border-radius: var(--radius-xl); background: linear-gradient(125deg, #eeeafd 0%, #f9f4ff 45%, #ffece2 100%); border: 1px solid rgba(117,103,234,.1); padding: clamp(26px, 4vw, 44px); display: grid; grid-template-columns: 1.25fr .75fr; overflow: hidden; position: relative; box-shadow: var(--shadow-soft); }
[data-theme="dark"] .hero-card { background: linear-gradient(125deg, #302b4e 0%, #252230 48%, #392a2f 100%); }
.hero-copy { position: relative; z-index: 2; max-width: 680px; }
.hero-badge { display: inline-flex; padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.7); color: #776bd6; font-size: .65rem; font-weight: 900; letter-spacing: .11em; }
[data-theme="dark"] .hero-badge { background: rgba(255,255,255,.07); color: #bfb8ff; }
.hero-copy h2 { margin: 18px 0 12px; max-width: 620px; font-size: clamp(1.8rem, 3.5vw, 3rem); line-height: 1.04; letter-spacing: -.055em; }
.hero-copy p { color: var(--muted); max-width: 600px; margin: 0; font-size: 1rem; }
.hero-actions { margin-top: 24px; display: flex; gap: 10px; flex-wrap: wrap; }
.hero-visual { position: relative; min-height: 170px; }
.book-card { position: absolute; width: 180px; height: 128px; right: 22px; bottom: 6px; transform: rotate(6deg); border-radius: 20px 20px 28px 20px; background: #fff; box-shadow: 0 20px 50px rgba(82,67,152,.16); display: flex; align-items: center; justify-content: center; gap: 12px; color: #685be0; font-size: 1.8rem; font-weight: 900; }
.book-card::after { content: ''; position: absolute; inset: 0 50% 0 auto; border-left: 1px solid #ece8f7; }
.book-card span { width: 38px; height: 38px; border-radius: 50%; background: #f4f1ff; display: grid; place-items: center; }
.hero-bubble { position: absolute; border-radius: 999px; background: #fff; color: #6c61c9; padding: 9px 13px; font-size: .76rem; font-weight: 850; box-shadow: 0 10px 28px rgba(60,50,100,.11); }
.bubble-one { right: 170px; top: 18px; transform: rotate(-7deg); }
.bubble-two { right: 5px; top: 55px; transform: rotate(4deg); color: var(--green); }
.pencil-shape { position: absolute; width: 130px; height: 18px; background: #f7a16e; border-radius: 999px; right: 108px; bottom: 148px; transform: rotate(-28deg); box-shadow: inset -16px 0 rgba(255,255,255,.35); }
.pencil-shape::before { content: ''; position: absolute; left: -18px; border-top: 9px solid transparent; border-bottom: 9px solid transparent; border-right: 20px solid #f5d5ae; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 20px 0; }
.stat-card, .mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); padding: 20px; min-width: 0; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-icon { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; font-weight: 900; }
.accent-purple .stat-icon { background: var(--primary-soft); color: var(--primary); }
.accent-green .stat-icon { background: var(--green-soft); color: var(--green); }
.accent-peach .stat-icon { background: var(--peach-soft); color: var(--peach); }
.accent-blue .stat-icon { background: var(--blue-soft); color: var(--blue); }
.trend-pill, .mini-label { font-size: .68rem; color: var(--muted); font-weight: 800; background: var(--surface-2); padding: 5px 8px; border-radius: 999px; }
.stat-label { display: block; color: var(--muted); font-size: .78rem; margin-top: 16px; }
.stat-value { display: block; margin-top: 4px; font-size: clamp(1.6rem, 2.5vw, 2.2rem); letter-spacing: -.045em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-foot { display: block; color: var(--muted); margin-top: 8px; font-size: .72rem; }

.dashboard-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-soft); padding: 22px; min-width: 0; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.panel-head h3 { margin: 4px 0 0; font-size: 1.1rem; letter-spacing: -.025em; }
.panel-total { font-size: .92rem; font-weight: 850; color: var(--primary); }
.chart-panel { min-height: 340px; }
.canvas-wrap { position: relative; width: 100%; min-height: 250px; }
.canvas-wrap canvas { width: 100% !important; }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 118px;
  padding: 9px 11px;
  border-radius: 12px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow-soft);
  font-size: .72rem;
  font-weight: 750;
  line-height: 1.35;
  transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
}
.chart-tooltip strong, .chart-tooltip span { display: block; }
.chart-tooltip span { margin-top: 2px; opacity: .78; font-size: .66rem; font-weight: 650; }
[data-theme="dark"] .chart-tooltip { background: #f4f1fb; color: #211f29; }
.lesson-list, .transactions-list, .agenda-list { display: grid; gap: 10px; }
.lesson-item, .transaction-item, .agenda-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px; border-radius: 15px; background: var(--surface-2); border: 1px solid transparent; }
.lesson-item, .agenda-item { color: var(--text); text-align: left; width: 100%; }
.lesson-item .lesson-time, .agenda-item .lesson-main strong, .lesson-item .lesson-main strong { color: var(--text); }
.lesson-item:hover, .agenda-item:hover { border-color: var(--border); }
.lesson-color { width: 10px; height: 38px; border-radius: 999px; }
.lesson-main strong, .transaction-main strong { display: block; font-size: .87rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson-main span, .transaction-main span { display: block; color: var(--muted); font-size: .72rem; margin-top: 3px; }
.lesson-time { font-size: .78rem; font-weight: 850; }
.empty-state { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 6px; }
.empty-state .emoji { font-size: 2rem; display: block; margin-bottom: 8px; }
.goal-ring-wrap { display: grid; grid-template-columns: 126px minmax(0,1fr); align-items: center; gap: 18px; min-height: 150px; }
.goal-ring { --progress: 0; width: 116px; height: 116px; border-radius: 50%; background: conic-gradient(var(--primary) calc(var(--progress) * 1%), var(--surface-2) 0); display: grid; place-items: center; position: relative; }
.goal-ring::after { content: ''; width: 84px; height: 84px; border-radius: 50%; background: var(--surface); position: absolute; }
.goal-ring span { z-index: 1; font-size: 1.1rem; font-weight: 900; }
.goal-info strong { display: block; font-size: 1.35rem; }
.goal-info > span { color: var(--muted); font-size: .8rem; }
.goal-info p { color: var(--muted); font-size: .75rem; margin: 8px 0 0; }
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick-action { text-align: left; padding: 15px; border-radius: 16px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); transition: .18s ease; }
.quick-action:hover { transform: translateY(-2px); border-color: rgba(117,103,234,.26); }
.quick-action > span { display: inline-grid; width: 34px; height: 34px; place-items: center; border-radius: 11px; background: var(--surface); margin-bottom: 14px; }
.quick-action strong, .quick-action small { display: block; }
.quick-action strong { font-size: .83rem; }
.quick-action small { color: var(--muted); margin-top: 3px; font-size: .68rem; }

.page-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.segmented { padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; display: inline-flex; }
.segmented button { background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 9px; font-weight: 800; }
.segmented button.active { background: var(--primary-soft); color: var(--primary); }
.calendar-panel { overflow: hidden; }
.calendar-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.month-nav { display: flex; align-items: center; gap: 12px; }
.month-nav h2 { min-width: 190px; text-align: center; margin: 0; font-size: 1.25rem; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); color: var(--muted); font-size: .72rem; font-weight: 800; text-align: center; padding-bottom: 8px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.calendar-day { min-height: 118px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 8px; background: var(--surface); overflow: hidden; }
.calendar-day.other-month { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); color: var(--muted); }
.calendar-day.today { box-shadow: inset 0 0 0 2px rgba(117,103,234,.35); }
.calendar-day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.day-number { width: 27px; height: 27px; border-radius: 9px; display: grid; place-items: center; font-size: .76rem; font-weight: 850; }
.today .day-number { background: var(--primary); color: #fff; }
.day-add { opacity: 0; background: transparent; color: var(--primary); font-weight: 900; }
.calendar-day:hover .day-add { opacity: 1; }
.event-chip { display: block; width: 100%; padding: 5px 6px; border-radius: 8px; margin: 4px 0; text-align: left; font-size: .64rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #302d3b; border-left: 3px solid var(--event-color); background: color-mix(in srgb, var(--event-color) 18%, white); }
[data-theme="dark"] .event-chip { color: #f6f3ff; background: color-mix(in srgb, var(--event-color) 24%, #282530); }
.event-chip.cancelled { opacity: .48; text-decoration: line-through; }
.agenda-item { cursor: pointer; }
.agenda-date { width: 48px; text-align: center; }
.agenda-date strong { font-size: 1.1rem; display: block; }
.agenda-date span { font-size: .68rem; color: var(--muted); text-transform: uppercase; }
.status-badge { padding: 5px 8px; border-radius: 999px; font-size: .66rem; font-weight: 850; }
.status-paid { background: var(--green-soft); color: var(--green); }
.status-unpaid { background: var(--peach-soft); color: var(--peach); }
.status-cancelled { background: #f5e8eb; color: var(--danger); }

.search-box { min-width: min(360px, 100%); height: 44px; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; display: flex; align-items: center; gap: 8px; padding: 0 13px; }
.search-box input { border: 0; outline: none; background: transparent; color: var(--text); width: 100%; }
.group-summary-strip { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.summary-chip { padding: 8px 11px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .73rem; color: var(--muted); }
.summary-chip strong { color: var(--text); }
.groups-grid, .goals-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.group-card, .goal-card { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-soft); border-radius: var(--radius-lg); padding: 20px; min-width: 0; }
.group-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.group-avatar { width: 46px; height: 46px; border-radius: 15px; color: white; display: grid; place-items: center; font-weight: 900; }
.group-title { margin: 12px 0 4px; font-size: 1.04rem; letter-spacing: -.02em; }
.group-meta { color: var(--muted); font-size: .74rem; }
.group-members { display: flex; margin: 16px 0 10px; }
.member-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); display: grid; place-items: center; background: var(--surface-2); font-size: .65rem; font-weight: 850; margin-left: -6px; }
.member-dot:first-child { margin-left: 0; }
.group-details { display: grid; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.detail-row { display: flex; justify-content: space-between; gap: 12px; font-size: .75rem; }
.detail-row span { color: var(--muted); }
.card-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.card-mini-btn { min-height: 34px; border-radius: 10px; background: var(--surface-2); color: var(--text); padding: 0 11px; font-size: .72rem; font-weight: 800; border: 1px solid var(--border); }

.filter-row, .toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.select-control { height: 42px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 13px; padding: 0 12px; }
.finance-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.mini-stat span, .mini-stat small { display: block; color: var(--muted); }
.mini-stat span { font-size: .75rem; }
.mini-stat strong { display: block; font-size: 1.45rem; margin: 5px 0; }
.mini-stat small { font-size: .68rem; }
.finance-layout { display: grid; grid-template-columns: 1.45fr .75fr; gap: 18px; }
.transaction-icon { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-weight: 900; }
.transaction-icon.income { background: var(--green-soft); color: var(--green); }
.transaction-icon.expense { background: var(--peach-soft); color: var(--peach); }
.transaction-amount { text-align: right; font-weight: 900; font-size: .86rem; }
.transaction-amount.income { color: var(--green); }
.transaction-amount.expense { color: var(--danger); }
.expense-breakdown { display: grid; gap: 14px; }
.category-row { display: grid; gap: 6px; }
.category-row-head { display: flex; justify-content: space-between; gap: 12px; font-size: .75rem; }
.progress-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: inherit; }

.goals-hero { margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.goals-hero h2 { margin: 5px 0 7px; letter-spacing: -.04em; }
.goals-hero p { margin: 0; max-width: 700px; color: var(--muted); }
.goal-card-top { display: flex; justify-content: space-between; gap: 14px; }
.goal-type { font-size: .67rem; padding: 5px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 850; }
.goal-card h3 { margin: 15px 0 4px; }
.goal-card p { margin: 0; color: var(--muted); font-size: .76rem; }
.goal-progress { margin: 18px 0 8px; }
.goal-progress .progress-track { height: 10px; }
.goal-progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .7rem; margin-top: 6px; }
.goal-controls { margin-top: 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.goal-controls input { min-width: 0; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-card:nth-child(1) { grid-row: span 2; }
.form-stack { display: grid; gap: 15px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.actions { grid-template-columns: auto auto; justify-content: start; }
label { display: grid; gap: 7px; font-size: .76rem; font-weight: 800; color: var(--muted); }
input, select, textarea { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; background: var(--surface); color: var(--text); transition: border .18s ease, box-shadow .18s ease; }
input:focus, select:focus, textarea:focus { border-color: rgba(117,103,234,.55); box-shadow: 0 0 0 4px rgba(117,103,234,.08); outline: none; }
textarea { resize: vertical; }
.settings-copy { color: var(--muted); font-size: .82rem; margin-top: 0; }
.backup-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.file-btn { cursor: pointer; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 7px; color: var(--primary); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(27,24,39,.38); backdrop-filter: blur(6px); z-index: 50; opacity: 0; visibility: hidden; transition: .2s ease; }
.modal-backdrop.show { opacity: 1; visibility: visible; }
dialog.modal { width: min(620px, calc(100% - 28px)); max-height: 90vh; overflow: auto; border: 1px solid var(--border); border-radius: 24px; padding: 0; background: var(--surface); color: var(--text); box-shadow: 0 30px 90px rgba(22,18,42,.25); z-index: 60; }
dialog.modal::backdrop { background: transparent; }
dialog.modal form { padding: 22px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-head h3 { margin: 4px 0 0; font-size: 1.25rem; }
.modal-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }

.pin-lock { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 20%, #eeeafd, #f7f6fb 45%, #ffece2); }
[data-theme="dark"] .pin-lock { background: radial-gradient(circle at 20% 20%, #302b4e, #17161d 45%, #392a2f); }
.pin-card { width: min(390px, 100%); padding: 32px; border-radius: 26px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); text-align: center; }
.pin-card h2 { margin: 8px 0 4px; }
.pin-card p { margin: 0 0 18px; color: var(--muted); }
.pin-card input { text-align: center; font-size: 1.5rem; letter-spacing: .45em; margin-bottom: 12px; }
.pin-card .primary-btn { width: 100%; }
.form-error { color: var(--danger); font-size: .74rem; display: block; margin-top: 8px; }

.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: grid; gap: 10px; }
.toast { min-width: 260px; max-width: 380px; padding: 13px 15px; border-radius: 14px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); font-size: .78rem; font-weight: 750; animation: toastIn .2s ease; }
.toast.success { background: #246f56; color: #fff; }
.toast.error { background: #a9384a; color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 1180px) {
  .stats-grid, .finance-cards { grid-template-columns: repeat(2, 1fr); }
  .groups-grid, .goals-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .finance-layout { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-card:nth-child(1) { grid-row: auto; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 280px; transform: translateX(-104%); transition: .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 19; background: rgba(22,18,35,.35); opacity: 0; visibility: hidden; transition: .2s; }
  .sidebar-overlay.show { opacity: 1; visibility: visible; }
  .menu-btn, .mobile-only { display: grid !important; }
  .hero-card { grid-template-columns: 1fr; }
  .hero-visual { display: none; }
  .topbar { padding-inline: 20px; }
  .page { padding-inline: 20px; }
}

@media (max-width: 680px) {
  .desktop-label { display: none; }
  .topbar-actions .ghost-btn { width: 42px; padding: 0; justify-content: center; }
  .topbar-actions .primary-btn { font-size: 0; width: 42px; padding: 0; }
  .topbar-actions .primary-btn::after { content: '+'; font-size: 1.2rem; }
  .avatar { display: none; }
  .stats-grid, .finance-cards, .groups-grid, .goals-grid { grid-template-columns: 1fr; }
  .page-toolbar, .goals-hero, .calendar-head { align-items: stretch; flex-direction: column; }
  .page-toolbar > * { width: 100%; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(2, 1fr); }
  .filter-row { display: grid; grid-template-columns: 1fr; }
  .select-control { width: 100%; }
  .calendar-panel { padding: 12px; overflow-x: auto; }
  .weekdays, .calendar-grid { min-width: 720px; }
  .quick-grid, .backup-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .goal-ring-wrap { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .modal-actions { grid-template-columns: 1fr 1fr; }
  .modal-actions .danger-link { grid-column: 1 / -1; text-align: left; }
  .hero-copy h2 { font-size: 2rem; }
}

/* ===== TutorFlow Cloud / Supabase ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(circle at 10% 10%, rgba(117,103,234,.20), transparent 36%),
    radial-gradient(circle at 92% 86%, rgba(239,140,89,.18), transparent 32%),
    var(--bg);
}
.auth-layout {
  width: min(1060px, 100%);
  min-height: min(700px, calc(100vh - 48px));
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(360px, 1.05fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 32px;
  overflow: hidden;
  box-shadow: 0 34px 110px rgba(41,35,76,.18);
}
.auth-card { padding: clamp(30px, 5vw, 58px); display: flex; flex-direction: column; justify-content: center; }
.auth-brand { display: flex; align-items: center; gap: 16px; }
.auth-brand .brand-mark.large { margin: 0; flex: 0 0 auto; }
.auth-brand h1 { margin: 4px 0 0; font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.08; letter-spacing: -.045em; }
.auth-lead { color: var(--muted); margin: 20px 0 24px; max-width: 540px; }
.auth-tabs { width: 100%; margin-bottom: 18px; }
.auth-tabs button { flex: 1; }
.auth-form { gap: 14px; }
.auth-form h3 { margin: 0; }
.auth-link { justify-self: center; }
.auth-hint { color: var(--muted); font-size: .77rem; margin: 0; }
.auth-back-row { margin-bottom: -4px; }
.auth-loading { min-height: 150px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-message, .auth-notice { margin-top: 14px; padding: 12px 14px; border-radius: 13px; font-size: .78rem; line-height: 1.45; }
.auth-message.success, .auth-notice.success { background: var(--green-soft); color: var(--green); }
.auth-message.error, .auth-notice.error { background: #fff0f3; color: var(--danger); border: 1px solid rgba(217,79,101,.18); }
[data-theme="dark"] .auth-message.error, [data-theme="dark"] .auth-notice.error { background: #3a252d; }
.auth-notice strong, .auth-notice span { display: block; }
.auth-notice span { margin-top: 5px; }
.auth-setup { display: grid; gap: 14px; }
.auth-showcase {
  position: relative;
  overflow: hidden;
  padding: clamp(34px, 5vw, 62px);
  color: #fff;
  background: linear-gradient(145deg, #7668eb 0%, #8c78f0 48%, #ef9a78 130%);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-showcase::before, .auth-showcase::after { content: ''; position: absolute; border-radius: 50%; background: rgba(255,255,255,.10); }
.auth-showcase::before { width: 300px; height: 300px; right: -90px; top: -80px; }
.auth-showcase::after { width: 220px; height: 220px; left: -80px; bottom: -70px; }
.auth-cloud-pill { position: relative; z-index: 1; display: inline-flex; align-self: flex-start; padding: 7px 11px; border-radius: 999px; background: rgba(255,255,255,.16); backdrop-filter: blur(12px); font-size: .7rem; font-weight: 850; }
.auth-showcase h2 { position: relative; z-index: 1; margin: 18px 0 26px; font-size: clamp(2.1rem, 4vw, 3.8rem); line-height: .98; letter-spacing: -.06em; }
.auth-demo-grid { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.auth-demo-card { min-height: 130px; border-radius: 20px; padding: 17px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.16); backdrop-filter: blur(14px); }
.auth-demo-card.wide { grid-column: 1 / -1; min-height: 100px; }
.auth-demo-card > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: rgba(255,255,255,.16); margin-bottom: 16px; }
.auth-demo-card strong, .auth-demo-card small { display: block; }
.auth-demo-card strong { font-size: 1.05rem; }
.auth-demo-card small { margin-top: 3px; opacity: .75; font-size: .72rem; }

.sync-pill { min-height: 34px; display: inline-flex; align-items: center; gap: 7px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .68rem; font-weight: 800; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(43,156,114,.10); }
.sync-pill.syncing .sync-dot, .sidebar-note.syncing .note-dot { background: var(--primary); animation: pulse 1s ease infinite; }
.sync-pill.offline .sync-dot, .sidebar-note.offline .note-dot { background: var(--peach); }
.sync-pill.error .sync-dot, .sidebar-note.error .note-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .45; transform: scale(.8); } }
.account-avatar-btn { padding: 0; background: transparent; border-radius: 50%; }
.account-avatar-btn:hover .avatar { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(239,140,89,.18); }
.avatar { transition: .18s ease; }

.cloud-badge { padding: 6px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .62rem; font-weight: 900; letter-spacing: .08em; }
.account-summary { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 12px; align-items: center; padding: 14px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.account-summary-avatar { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--primary), #a48df5); font-weight: 900; }
.account-summary strong, .account-summary span { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-summary strong { font-size: .84rem; }
.account-summary span { margin-top: 3px; color: var(--muted); font-size: .7rem; }
.account-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.account-actions > button { flex: 1 1 150px; }

@media (max-width: 860px) {
  .auth-screen { padding: 0; }
  .auth-layout { min-height: 100vh; width: 100%; border-radius: 0; grid-template-columns: 1fr; }
  .auth-showcase { display: none; }
  .auth-card { padding: 30px 22px; }
  .sync-pill { display: none; }
}

/* ===== TutorFlow v2.1 — recurring lessons & calendar markers ===== */
.marker-chip { font-weight: 850; }
.marker-birthday { --event-color: #e16f96; }
.marker-reminder { --event-color: #f39c6b; }
.marker-personal { --event-color: #4e8de6; }
.marker-status { border: 1px solid color-mix(in srgb, var(--event-color, var(--primary)) 26%, transparent); }
.marker-status.marker-birthday { background: color-mix(in srgb, #e16f96 15%, var(--surface)); color: #b54d73; }
.marker-status.marker-reminder { background: color-mix(in srgb, #f39c6b 16%, var(--surface)); color: #b96539; }
.marker-status.marker-personal { background: color-mix(in srgb, #4e8de6 15%, var(--surface)); color: #356db7; }
[data-theme="dark"] .marker-status.marker-birthday,
[data-theme="dark"] .marker-status.marker-reminder,
[data-theme="dark"] .marker-status.marker-personal { color: var(--text); }
.marker-agenda .agenda-date { background: var(--surface); }

.repeat-card { border: 1px solid var(--border); border-radius: 16px; padding: 14px; background: var(--surface-2); }
.repeat-options { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.check-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; color: var(--text); }
.check-row input[type="checkbox"] { width: 18px; height: 18px; margin: 2px 0 0; padding: 0; flex: 0 0 auto; accent-color: var(--primary); }
.check-row span { display: grid; gap: 2px; }
.check-row strong { font-size: .78rem; }
.check-row small, .field-hint { color: var(--muted); font-size: .7rem; font-weight: 600; line-height: 1.45; }
.field-hint { margin: 10px 0 0; }

.compact-modal { width: min(480px, calc(100% - 28px)) !important; }
.quick-modal-body { padding: 22px; }
.calendar-quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.calendar-quick-actions .quick-action { min-height: 128px; }

@media (max-width: 520px) {
  .calendar-quick-actions { grid-template-columns: 1fr; }
}


/* ===== TutorFlow v2.3 — calendar UX, reports, reminders, achievements ===== */
.chart-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 650;
  text-align: center;
}
.chart-tooltip {
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.more-events-btn {
  width: 100%;
  margin-top: 4px;
  padding: 5px 7px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  color: var(--primary);
  text-align: left;
  font-size: .64rem;
  font-weight: 900;
}
.more-events-btn:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); background: var(--primary-soft); }
.day-details-list { display: grid; gap: 9px; }
.day-detail-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
}
.day-detail-item:hover { border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }
.day-detail-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--surface); }
.day-detail-copy { min-width: 0; }
.day-detail-copy strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .8rem; }
.day-detail-copy span { display: block; color: var(--muted); font-size: .69rem; margin-top: 3px; }
.day-detail-time { font-size: .72rem; font-weight: 900; color: var(--text); }

.event-chip { cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; }
.event-chip.calendar-drag-active { cursor: grabbing; opacity: .5; transform: scale(.98); }
.calendar-day.drag-over { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--primary-soft); }
body.calendar-dragging, body.calendar-dragging * { cursor: grabbing !important; }
.calendar-drag-ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  font-size: .7rem;
  font-weight: 850;
  transform: translate(12px, 12px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
[data-theme="dark"] .calendar-drag-ghost { background: #f4f1fb; color: #211f29; }

.payment-reminders-panel, .achievements-panel { min-height: 220px; }
.payment-reminder-list { display: grid; gap: 9px; }
.payment-reminder-item {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.payment-reminder-item .lesson-color { height: 36px; }
.payment-reminder-copy { min-width: 0; }
.payment-reminder-copy strong { display: block; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.payment-reminder-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: .68rem; }
.payment-reminder-actions { display: flex; align-items: center; gap: 8px; }
.payment-reminder-amount { font-size: .76rem; font-weight: 900; white-space: nowrap; }
.pay-now-btn { min-height: 32px; padding: 0 10px; border-radius: 9px; background: var(--green-soft); color: var(--green); font-size: .68rem; font-weight: 900; border: 1px solid color-mix(in srgb, var(--green) 20%, transparent); }
.finance-reminders-panel { margin-bottom: 18px; }

.achievement-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.achievement-card {
  padding: 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  min-width: 0;
}
.achievement-card.locked { opacity: .52; filter: grayscale(.55); }
.achievement-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; background: var(--surface); font-size: 1.05rem; }
.achievement-card strong { display: block; margin-top: 11px; font-size: .77rem; }
.achievement-card span { display: block; margin-top: 3px; color: var(--muted); font-size: .65rem; line-height: 1.35; }

.group-stat-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.group-stats-kpis { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin-bottom: 18px; }
.group-stats-kpi { padding: 13px; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--border); }
.group-stats-kpi span { display: block; color: var(--muted); font-size: .67rem; }
.group-stats-kpi strong { display: block; margin-top: 5px; font-size: 1.02rem; }
.group-stats-section { margin-top: 18px; }
.group-stats-section h4 { margin: 0 0 10px; }
.group-stats-history { display: grid; gap: 8px; }
.group-history-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .73rem; }
.group-history-row:last-child { border-bottom: 0; }
.group-history-row span { color: var(--muted); }

.report-toolbar { align-items: end; }
.report-title { margin: 4px 0 5px; }
.report-subtitle { margin: 0; color: var(--muted); font-size: .8rem; }
.report-month-select { min-width: 210px; }
.report-kpis { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.report-summary-list, .ranking-list { display: grid; gap: 10px; }
.report-summary-row, .ranking-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.report-summary-row span, .ranking-row span { color: var(--muted); font-size: .72rem; }
.report-summary-row strong, .ranking-row strong { font-size: .78rem; }
.ranking-left { min-width: 0; display: flex; align-items: center; gap: 9px; }
.ranking-dot { width: 9px; height: 30px; border-radius: 999px; flex: 0 0 auto; }
.ranking-copy { min-width: 0; }
.ranking-copy strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking-copy span { display: block; margin-top: 2px; }

@media (max-width: 1180px) {
  .report-kpis { grid-template-columns: repeat(2,1fr); }
  .report-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .achievement-grid { grid-template-columns: 1fr; }
  .payment-reminder-item { grid-template-columns: auto minmax(0,1fr); }
  .payment-reminder-actions { grid-column: 2; justify-content: space-between; }
  .group-stats-kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  .chart-tooltip {
    position: static;
    transform: none;
    margin: 8px auto 0;
    width: min(100%, 280px);
    text-align: center;
    white-space: normal;
  }
  .canvas-wrap { min-height: 280px; }
  .canvas-wrap canvas { touch-action: manipulation; }
  .chart-hint { padding-inline: 8px; }
  .day-add { opacity: 1; }
  .report-kpis { grid-template-columns: 1fr; }
  .report-toolbar .report-month-select { width: 100%; }
}
@media (max-width: 480px) {
  .group-stats-kpis { grid-template-columns: 1fr; }
}
.calendar-drag-hint { margin: -7px 0 14px; color: var(--muted); font-size: .69rem; font-weight: 650; }
