:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #5f6b7a;
  --line: #dde4ee;
  --dark: #17191d;
  --red: #ed1c24;
  --blue: #12345f;
  --green: #059669;
  --gold: #f59e0b;
  --shadow: 0 22px 60px rgba(15, 23, 42, .12);
  --radius: 26px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(circle at top left, #ffffff 0, var(--bg) 48%, #edf2f7 100%);
  color: var(--text);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
code { background: #eef2f7; border-radius: 8px; padding: 2px 6px; }

.auth-body { min-height: 100vh; overflow-x: hidden; }
.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(380px, 560px) minmax(320px, 1fr);
  gap: 32px;
  align-items: center;
  padding: 48px clamp(22px, 5vw, 80px);
}
.auth-panel {
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-radius: 34px;
  padding: 42px;
  box-shadow: var(--shadow);
}
.auth-logo { width: 178px; height: auto; display: block; margin-bottom: 28px; }
.eyebrow { margin: 0 0 12px; text-transform: uppercase; letter-spacing: .18em; color: #9f1239; font-size: 13px; font-weight: 900; }
.auth-panel h1 { margin: 0 0 18px; font-size: clamp(40px, 5vw, 64px); line-height: .96; letter-spacing: -0.05em; }
.auth-description { color: var(--muted); font-size: 18px; line-height: 1.55; margin-bottom: 30px; }
.auth-form, .stack-form { display: grid; gap: 14px; }
.auth-form label, .stack-form label, .modal-card label { font-weight: 800; color: #172033; }
input, select {
  width: 100%;
  border: 1px solid #d5deeb;
  background: #fff;
  border-radius: 18px;
  min-height: 58px;
  padding: 0 18px;
  outline: none;
  color: var(--text);
  margin-top: 8px;
}
input:focus, select:focus { border-color: #2563eb; box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.check-row { display: flex !important; align-items: center; gap: 12px; color: var(--text); }
.check-row input { width: 18px; min-height: 18px; margin: 0; }
.primary-button, .outline-button, .ghost-button, .icon-button {
  border: 0;
  border-radius: 18px;
  min-height: 52px;
  padding: 0 22px;
  font-weight: 900;
}
.primary-button { background: var(--dark); color: white; box-shadow: 0 12px 22px rgba(0,0,0,.16); }
.primary-button:hover { transform: translateY(-1px); }
.primary-button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.outline-button { background: #fff; color: var(--text); border: 1px solid var(--line); }
.ghost-button { background: #f7f9fc; color: var(--text); border: 1px solid var(--line); }
.icon-button { width: 42px; min-height: 42px; border-radius: 50%; background: #f4f6fa; font-size: 26px; line-height: 1; }
.full { width: 100%; }
.form-error { min-height: 24px; margin: 0; color: #e11d48; font-weight: 900; line-height: 1.45; }
.security-note { color: var(--muted); margin: 22px 0 0; font-size: 14px; line-height: 1.5; }
.helper-text { color: var(--muted); margin: 0; line-height: 1.5; }
.auth-info {
  position: relative;
  min-height: 580px;
  background: linear-gradient(145deg, #17191d, #263142);
  border-radius: 42px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.auth-info::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 78% 24%, rgba(237,28,36,.28), transparent 24%),
    linear-gradient(120deg, transparent 0 36%, rgba(255,255,255,.06) 37% 38%, transparent 39%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.04) 0 1px, transparent 1px 80px);
}
.floating-card, .math-card {
  position: absolute;
  width: min(360px, calc(100% - 48px));
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.20);
  backdrop-filter: blur(10px);
  color: white;
  border-radius: 28px;
  padding: 28px;
}
.floating-card { top: 70px; right: 46px; }
.math-card { bottom: 70px; left: 46px; }
.floating-card span, .math-card span { color: #cbd5e1; font-weight: 800; }
.floating-card strong, .math-card strong { display: block; margin: 10px 0; font-size: 34px; }
.floating-card p, .math-card p { margin: 0; color: #e5e7eb; line-height: 1.5; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 86px;
  display: grid;
  grid-template-columns: 1.3fr auto auto;
  gap: 18px;
  align-items: center;
  padding: 14px clamp(18px, 4vw, 54px);
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand-wrap { display: flex; align-items: center; gap: 22px; min-width: 0; }
.top-logo { width: 128px; height: auto; object-fit: contain; }
.brand-wrap h1 { margin: 0; font-size: 22px; letter-spacing: -0.03em; }
.brand-wrap p { margin: 4px 0 0; color: var(--muted); }
.nav-tabs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.nav-tab {
  border: 0;
  background: transparent;
  color: #5f6875;
  font-weight: 800;
  border-radius: 999px;
  min-height: 44px;
  padding: 0 18px;
}
.nav-tab.active { background: var(--dark); color: #fff; }
.nav-logout { display: none; }
.menu-toggle {
  display: none;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  box-shadow: 0 10px 24px rgba(15,23,42,.08);
}
.menu-toggle span {
  width: 22px;
  height: 3px;
  border-radius: 99px;
  background: #111827;
  transition: transform .2s ease, opacity .2s ease;
}
.topbar.menu-open .menu-toggle span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.topbar.menu-open .menu-toggle span:nth-child(2) { opacity: 0; }
.topbar.menu-open .menu-toggle span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }
.mobile-student-strip { display: none; }
.app-container { width: min(1440px, calc(100% - 40px)); margin: 28px auto 70px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.hero-card {
  min-height: 205px;
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 22px;
  align-items: center;
  background: linear-gradient(135deg, #311c21, #18191d 45%, #1f242c);
  color: #fff;
  border-radius: 30px;
  padding: clamp(24px, 3.5vw, 42px);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.hero-card h2 { margin: 0 0 12px; max-width: 760px; font-size: clamp(32px, 4vw, 50px); line-height: 1.03; letter-spacing: -0.055em; }
.hero-card p { margin: 0; color: #f2f4f7; font-size: 16px; line-height: 1.5; max-width: 780px; }
.budget-state-card {
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.10);
  border-radius: 24px;
  padding: 24px;
  backdrop-filter: blur(12px);
}
.budget-state-card span { color: #d1d5db; font-weight: 800; }
.budget-state-card strong { display: block; margin: 10px 0; font-size: 40px; letter-spacing: -0.05em; }
.budget-state-card p { color: #e5e7eb; font-size: 14px; }
.period-banner, .projection-banner {
  margin: 18px 0;
  border-radius: 18px;
  padding: 18px 22px;
  font-weight: 800;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
}
.projection-banner.warning { background: #fff7ed; border-color: #fdba74; color: #9a3412; }
.projection-banner.danger { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin: 22px 0; }
.kpi-card, .card {
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 12px 34px rgba(15,23,42,.07);
}
.kpi-card { padding: 24px; }
.kpi-card span, .settings-grid span { color: var(--muted); font-weight: 800; }
.kpi-card strong, .settings-grid strong { display: block; margin: 10px 0; font-size: 34px; letter-spacing: -0.04em; }
.kpi-card p, .settings-grid p { margin: 0; color: var(--muted); line-height: 1.45; }
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.card { padding: 24px; }
.card-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.card-heading h3 { margin: 0; font-size: 26px; letter-spacing: -0.03em; }
.card-heading p { margin: 4px 0 0; color: var(--muted); line-height: 1.45; }
.chart-box {
  height: 300px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
}
.chart-box canvas { width: 100%; height: 100%; display: block; }
.math-chart { margin-top: 22px; }
.two-column { display: grid; grid-template-columns: 440px 1fr; gap: 24px; align-items: start; }
.form-card { position: sticky; top: 116px; }
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.quick-actions button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
}
.movement-list {
  max-height: 620px;
  overflow: auto;
  padding-right: 8px;
  display: grid;
  gap: 12px;
}
.movement-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  background: #fbfcff;
}
.movement-item strong { display: block; margin-bottom: 4px; }
.movement-item small { color: var(--muted); }
.amount.positive { color: var(--green); font-weight: 900; }
.amount.negative { color: var(--red); font-weight: 900; }
.delete-button { border: 0; background: #fee2e2; color: #991b1b; border-radius: 14px; min-height: 38px; padding: 0 12px; font-weight: 900; }
.empty-state { color: var(--muted); text-align: center; padding: 60px 20px; border: 1px dashed var(--line); border-radius: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin: 10px 0 24px; }
.settings-grid > div { border: 1px solid var(--line); border-radius: 20px; padding: 20px; background: #fbfcff; }
.concept-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.concept { border-radius: 24px; padding: 22px; min-height: 140px; border-left: 8px solid; }
.concept strong { font-size: 20px; }
.concept p { color: #344054; line-height: 1.45; }
.concept.blue { background: #eaf2ff; border-color: #173b70; }
.concept.red { background: #fff1f2; border-color: var(--red); }
.concept.gold { background: #fff7e6; border-color: var(--gold); }
.concept.green { background: #eafaf3; border-color: var(--green); }
.formula-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 22px; }
.formula-box { border: 1px solid var(--line); border-radius: 24px; padding: 24px; background: #fff; }
.formula-box h4 { margin: 0 0 16px; color: var(--blue); font-size: 22px; }
.formula-box p { margin: 8px 0; font-size: 20px; font-weight: 800; }

.math-note { font-size: 15px !important; font-weight: 700 !important; color: #475467; line-height: 1.45; }
.derivative-panel { margin-top: 22px; display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 22px; border: 1px solid var(--line); border-radius: 24px; padding: 24px; background: #fbfcff; }
.derivative-panel h4 { margin: 0 0 10px; color: var(--blue); font-size: 22px; }
.derivative-panel p { margin: 0; color: #344054; line-height: 1.55; font-weight: 650; }
.derivative-list { display: grid; gap: 10px; max-height: 250px; overflow: auto; padding-right: 4px; }
.derivative-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; background: #fff; }
.derivative-row strong { color: #111827; }
.derivative-row small { display: block; margin-top: 3px; color: #667085; font-weight: 700; }
.derivative-row span { white-space: nowrap; font-weight: 900; color: var(--red); }
.empty-state.compact { padding: 16px; }
.abpro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.abpro-grid > div { background: #fbfcff; border: 1px solid var(--line); border-radius: 22px; padding: 22px; }
.abpro-grid strong { color: var(--blue); font-size: 18px; }
.abpro-grid p { color: #344054; line-height: 1.5; }
.modal {
  border: 0;
  background: transparent;
  padding: 20px;
  width: min(620px, calc(100% - 20px));
}
.modal::backdrop { background: rgba(15,23,42,.62); backdrop-filter: blur(5px); }
.modal-card { display: grid; gap: 16px; background: #fff; border-radius: 30px; padding: 28px; box-shadow: var(--shadow); }
.modal-heading { display: flex; justify-content: space-between; gap: 16px; }
.modal-heading h3 { margin: 0; font-size: 32px; letter-spacing: -0.04em; }
.modal-heading p { margin: 8px 0 0; color: var(--muted); line-height: 1.45; }
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: none;
  max-width: 380px;
  background: #111827;
  color: #fff;
  border-radius: 18px;
  padding: 16px 18px;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.toast.show { display: block; }
.toast.error { background: #991b1b; }
.toast.ok { background: #065f46; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: 1fr; }
  .hero-card, .dashboard-grid, .two-column { grid-template-columns: 1fr; }
  .form-card { position: static; }
  .kpi-grid, .settings-grid, .concept-grid, .abpro-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .auth-layout { grid-template-columns: 1fr; padding: 20px; }
  .auth-info { min-height: 360px; }
  .auth-panel { padding: 28px; }
  .floating-card, .math-card { position: relative; top: auto; right: auto; bottom: auto; left: auto; margin: 24px; }
  .kpi-grid, .settings-grid, .concept-grid, .formula-grid, .derivative-panel, .abpro-grid, .math-charts-grid, .abpro-section-grid, .abpro-wide-grid { grid-template-columns: 1fr; }

  .topbar {
    min-height: 76px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
  }
  .brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }
  .top-logo {
    width: 92px;
    max-width: 34vw;
    flex: 0 0 auto;
  }
  .desktop-brand-text {
    display: block;
    min-width: 0;
  }
  .brand-wrap h1 {
    font-size: 16px;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand-wrap p {
    font-size: 12px;
    line-height: 1.15;
    white-space: normal;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .menu-toggle { display: flex; flex: 0 0 auto; }
  .nav-tabs {
    position: fixed;
    top: 78px;
    left: 14px;
    right: 14px;
    z-index: 35;
    display: none;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: rgba(255,255,255,.98);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
  }
  .topbar.menu-open .nav-tabs { display: grid; }
  .nav-tab {
    min-height: 52px;
    width: 100%;
    justify-content: center;
    font-size: 17px;
    background: #f6f7fb;
  }
  .nav-tab.active { background: var(--dark); color: #fff; }
  .nav-logout { display: block; color: #111827; background: #fff; border: 1px solid var(--line); }
  .logout-top { display: none; }

  .app-container { width: min(100% - 24px, 760px); margin-top: 18px; }
  .mobile-student-strip { display: none; }

  .hero-card { padding: 24px; border-radius: 26px; min-height: auto; }
  .hero-card h2 { font-size: 34px; }
  .budget-state-card { padding: 20px; }
  .movement-item { grid-template-columns: 1fr; }
  .card-heading { display: block; }
}


.latest-card { min-height: 100%; }
.latest-movement-list {
  display: grid;
  gap: 12px;
  max-height: 300px;
  overflow: auto;
  padding-right: 6px;
}
.latest-movement-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  border-radius: 18px;
  padding: 14px 16px;
  background: #f7f8fb;
}
.latest-movement-item strong { display: block; margin-bottom: 4px; }
.latest-movement-item small { color: var(--muted); }

.math-charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-top: 22px;
}
.math-charts-grid h4 {
  margin: 0 0 12px;
  color: var(--blue);
  font-size: 22px;
}
.math-charts-grid .math-chart { margin-top: 0; }

.abpro-section-grid,
.abpro-wide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
}
.abpro-section-grid section,
.abpro-wide-grid section,
.sources-box {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fbfcff;
  padding: 22px;
}
.abpro-section-grid h4,
.abpro-wide-grid h4,
.sources-box h4 {
  margin: 0 0 12px;
  color: var(--blue);
  font-size: 20px;
}
.abpro-section-grid p,
.abpro-wide-grid p,
.sources-box li,
.abpro-section-grid li {
  color: #344054;
  line-height: 1.55;
}
.abpro-section-grid ol,
.sources-box ul { margin: 0; padding-left: 20px; }
.abpro-table-wrap { overflow: auto; }
.abpro-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  font-size: 14px;
}
.abpro-table th {
  background: var(--blue);
  color: #fff;
  text-align: left;
  padding: 10px;
}
.abpro-table td {
  border: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
  background: #fff;
}
.sources-box { margin-top: 18px; }

@media (max-width: 820px) {
  .math-charts-grid,
  .abpro-section-grid,
  .abpro-wide-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .top-logo { width: 82px; }
  .brand-wrap h1 { font-size: 15px; }
  .brand-wrap p { font-size: 11px; }
  .menu-toggle { width: 46px; height: 46px; border-radius: 15px; }
}
