:root {
  --bg: #f8fafc;
  --panel: rgba(255, 255, 255, 0.85);
  --panel-solid: #ffffff;
  --panel-soft: rgba(248, 250, 252, 0.9);
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #10b981;
  --accent-dark: #059669;
  --accent-soft: rgba(16, 185, 129, 0.12);
  --stroke: rgba(226, 232, 240, 0.7);
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
  --radius: 24px;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.78);
  --panel-solid: #0f172a;
  --panel-soft: rgba(15, 23, 42, 0.7);
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --accent: #34d399;
  --accent-dark: #10b981;
  --accent-soft: rgba(52, 211, 153, 0.12);
  --stroke: rgba(30, 41, 59, 0.7);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Sora", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(16, 185, 129, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 20%, rgba(59, 130, 246, 0.12), transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.no-scroll {
  overflow: hidden;
}

[data-theme="dark"] body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(20, 184, 166, 0.12), transparent 60%),
    radial-gradient(900px 500px at 100% 10%, rgba(37, 99, 235, 0.12), transparent 60%),
    var(--bg);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 12px 24px rgba(16, 185, 129, 0.35);
}

.brand-title {
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
}

.app-sidebar {
  display: none;
}

.app-main {
  min-height: 100vh;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--stroke);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 6vw;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
}

.topbar-link:hover {
  color: var(--ink);
}

.app-content {
  padding: 28px 6vw 120px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 12px;
}

.app-brand-badge {
  height: 44px;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(16, 185, 129, 0.35);
}

.app-brand-badge.small {
  height: 36px;
  width: 36px;
  border-radius: 14px;
  font-size: 14px;
}

.sidebar-nav {
  padding: 8px 14px;
  display: grid;
  gap: 6px;
}

.nav-icon {
  width: 24px;
  text-align: center;
}

.app-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
  color: var(--muted);
}

.app-nav-item-active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.18);
}

.app-nav-item-inactive:hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 999px;
  background: #f43f5e;
  color: white;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 22px;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--stroke);
}

.app-button-outline {
  border-radius: 18px;
  border: 1px solid var(--stroke);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.app-button-outline:hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.sidebar-link {
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
}

.sidebar-link:hover {
  color: var(--ink);
}

.app-mobile-nav {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  z-index: 50;
  background: color-mix(in srgb, #f8fafc 88%, transparent);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 16px;
  padding: 8px 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(60px, 1fr);
  gap: 6px;
  text-align: center;
  font-size: 11px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.25);
  backdrop-filter: blur(14px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.app-mobile-nav::-webkit-scrollbar {
  display: none;
}

.auth-layout .app-sidebar,
.auth-layout .app-topbar,
.auth-layout .app-mobile-nav {
  display: none;
}

.auth-layout .app-content {
  padding: 40px 6vw 40px;
}

.app-mobile-nav a {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-decoration: none;
  color: #64748b;
  font-weight: 600;
  min-width: 52px;
  line-height: 1.2;
  position: relative;
}

.app-mobile-nav a.is-active {
  color: var(--accent);
}

.app-mobile-nav a.is-active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.page {
  position: relative;
  z-index: 1;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-shell {
  min-height: calc(100vh - 140px);
  display: grid;
  place-items: center;
  padding: 40px 6vw;
}

.auth-card {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: 28px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.auth-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.auth-form .actions {
  margin-top: 8px;
}

.panel {
  border-radius: var(--radius);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.panel.narrow {
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.panel.soft {
  background: var(--panel-soft);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

.muted {
  margin: 0;
  color: var(--muted);
}

.button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 18px;
  padding: 10px 16px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.button:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

.button.subtle {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--stroke);
}

.alert {
  background: rgba(251, 191, 36, 0.15);
  color: #92400e;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 6px;
}

input,
select,
textarea {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  font-family: inherit;
  font-size: 14px;
  background: var(--panel-solid);
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.help {
  font-size: 12px;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.form {
  display: grid;
  gap: 14px;
  width: 100%;
}

.form-spaced {
  padding-bottom: 40px;
}

.mobile-spacer {
  height: 0;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 20px;
  gap: 12px;
}

.summary-card {
  background: var(--accent-soft);
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--stroke);
  min-width: 160px;
}

.chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 12px;
  align-items: end;
  height: 220px;
  padding-top: 12px;
}

.chart-bar {
  display: grid;
  align-items: end;
  gap: 8px;
  text-align: center;
  height: 100%;
}

.chart-bar span {
  display: block;
  height: 0;
  border-radius: 16px 16px 8px 8px;
  background: var(--accent);
  box-shadow: 0 12px 26px rgba(16, 185, 129, 0.25);
  transition: height 0.4s ease;
}

.chart-value {
  font-size: 12px;
  color: var(--muted);
}

.chart-label {
  font-size: 11px;
  color: var(--muted);
}

.summary-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.summary-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 6px;
}

.summary-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.table {
  display: grid;
  gap: 12px;
}

.table-header,
.table-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1.4fr auto;
  gap: 12px;
  align-items: center;
}

.table-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.table-row {
  background: var(--panel);
  border-radius: 16px;
  padding: 12px;
  border: 1px solid var(--stroke);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.table-row:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
}

.table.two-col .table-header,
.table.two-col .table-row {
  grid-template-columns: 2fr auto;
}

.events-table .table-header,
.events-table .table-row {
  grid-template-columns: 2fr 1fr 1fr auto;
}

.notifications-table .table-header,
.notifications-table .table-row {
  grid-template-columns: 2fr 1fr 1fr auto;
}

.receipt-list {
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.receipt-stack {
  display: grid;
  gap: 8px;
  border: 1px dashed var(--stroke);
  padding: 12px;
  border-radius: 12px;
  background: var(--panel-soft);
}

.receipt-item {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}

.receipt-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.calendar-nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}

.calendar-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  text-align: center;
}

.calendar-cell {
  min-height: 110px;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 10px;
  background: var(--panel);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
}

.calendar-cell.is-other {
  background: var(--panel-soft);
  color: var(--muted);
}

.calendar-cell.is-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.calendar-date {
  font-weight: 700;
  font-size: 13px;
}

.calendar-events {
  display: grid;
  gap: 6px;
}

.calendar-event {
  font-size: 12px;
  text-decoration: none;
  color: var(--accent-dark);
  background: rgba(16, 185, 129, 0.1);
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid rgba(16, 185, 129, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.calendar-event:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.hide-sm {
  display: block;
}

.row-title {
  font-weight: 600;
}

.row-notes {
  font-size: 12px;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.link {
  background: none;
  border: none;
  color: var(--accent-dark);
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

.preview-link {
  color: var(--accent);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}

.lightbox.is-open {
  display: flex;
}

.lightbox-content {
  position: relative;
  width: min(900px, 94vw);
  height: min(80vh, 700px);
  background: var(--panel-solid);
  border-radius: 24px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
}

.lightbox-close {
  justify-self: end;
  border: none;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
}

.lightbox img,
.lightbox iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 16px;
  object-fit: contain;
}

.link.danger {
  color: #b91c1c;
}

.amount {
  font-weight: 700;
}

.pill {
  background: rgba(15, 23, 42, 0.05);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  text-transform: capitalize;
}

.pill-unread {
  background: rgba(251, 191, 36, 0.2);
  color: #92400e;
}

.tag-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.upload-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: center;
}

.upload-form input[type="file"] {
  padding: 8px 10px;
}

.reader-frame {
  margin-top: 16px;
  height: 70vh;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  overflow: hidden;
}

.reader-frame iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #0f172a;
}

.epub-reader {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  overflow: hidden;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--stroke);
  border-radius: 12px;
}

.dashboard .panel-header {
  margin-bottom: 24px;
}

.quick-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  margin: 8px 0 2px;
}

.stat-sub {
  font-size: 13px;
  color: var(--muted);
}

.split-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.panel-title {
  font-weight: 600;
  margin-bottom: 12px;
}

.panel-footer {
  margin-top: 12px;
}

.stack {
  display: grid;
  gap: 12px;
}

.row-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px dashed var(--stroke);
  padding-bottom: 10px;
}

.row-line:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar {
  height: 8px;
  background: rgba(148, 163, 184, 0.25);
  border-radius: 999px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

@media (min-width: 900px) {
  .app-shell {
    display: flex;
  }

  .app-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    width: 18rem;
    background: color-mix(in srgb, var(--panel) 90%, transparent);
    border-right: 1px solid var(--stroke);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
  }

  .app-main {
    margin-left: 18rem;
  }

  .topbar-brand {
    display: none;
  }

  .app-mobile-nav {
    display: none;
  }
}

@media (max-width: 900px) {
  .hide-sm {
    display: none;
  }

  .table-header,
  .table-row {
    grid-template-columns: 1.4fr 0.8fr 0.8fr 0.8fr 0.9fr 1fr;
  }

  .table.two-col .table-header,
  .table.two-col .table-row {
    grid-template-columns: 1fr auto;
  }

  .table-header div:last-child,
  .table-row div:last-child {
    grid-column: 1 / -1;
  }

  .row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 600px) {
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .app-content {
    padding: 20px 16px calc(300px + env(safe-area-inset-bottom, 0px));
  }

  .panel {
    padding: 20px 18px;
    margin-bottom: 12px;
  }

  .panel-header {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }

  .app-mobile-nav {
    gap: 3px;
    font-size: 10px;
    padding: 6px 8px;
  }

  .form {
    gap: 16px;
    padding-bottom: 320px; /* breathing room above mobile nav */
  }

  .form-spaced {
    padding-bottom: 380px; /* extra room for long forms on mobile */
  }

  .mobile-spacer {
    height: 180px;
  }

  .panel.narrow {
    max-width: none;
    width: 100%;
  }

  .table-header {
    display: none;
  }

  .table-row {
    grid-template-columns: 1fr;
  }
}
