:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #06b6d4;
  --primary-dark: #0891b2;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #334155;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  flex-shrink: 0;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title span { display: block; font-size: .75rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.menu-toggle {
  display: none; background: none; border: 1px solid var(--border);
  color: var(--text); padding: .4rem .6rem; border-radius: 8px; cursor: pointer;
  flex-shrink: 0;
}
.flash-bar { margin: 0; border-radius: 0; flex-shrink: 0; }

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}
.app-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  overflow-y: auto;
}
.main-content {
  flex: 1;
  padding: 1.5rem;
  width: 100%;
  max-width: 1400px;
}
.footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .8rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  flex-shrink: 0;
  margin-top: auto;
}

.nav-section {
  padding: .5rem 1.25rem; font-size: .7rem;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1.25rem; color: var(--muted);
  text-decoration: none; transition: background .15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--bg-hover); color: var(--text); text-decoration: none;
}
.nav-link.active { border-left: 3px solid var(--primary); }
.nav-icon { font-size: 1.1rem; }

.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; }
.page-header p { color: var(--muted); font-size: .9rem; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-bottom: .75rem; font-size: 1rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: linear-gradient(135deg, var(--bg-card), #0e7490);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-card .value { font-size: 2rem; font-weight: 700; }
.stat-card .label { color: var(--muted); font-size: .85rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; }
tr:hover td { background: rgba(255,255,255,.03); }

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem 1rem; border-radius: 8px; border: none;
  font-size: .875rem; cursor: pointer; text-decoration: none;
  transition: opacity .15s;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn-primary { background: var(--primary); color: #0f172a; font-weight: 600; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

.form { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: .5rem .65rem; border-radius: 8px; font-size: .9rem;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary); border-color: transparent;
}

.search-bar {
  display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.search-bar input { flex: 1; min-width: 200px; }

.badge {
  display: inline-block; padding: .2rem .5rem; border-radius: 6px;
  font-size: .75rem; font-weight: 600;
}
.badge-low { background: #164e63; color: #a5f3fc; }
.badge-medium { background: #713f12; color: #fde68a; }
.badge-high { background: #7f1d1d; color: #fecaca; }

.progress-bar {
  height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden;
}
.progress-bar span {
  display: block; height: 100%; background: var(--primary); border-radius: 4px;
}
.progress-bar.warn span { background: var(--warning); }
.progress-bar.danger span { background: var(--danger); }

.alert {
  padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem;
}
.alert-success { background: rgba(34,197,94,.15); border: 1px solid var(--success); }
.alert-error { background: rgba(239,68,68,.15); border: 1px solid var(--danger); }
.alert-warning { background: rgba(245,158,11,.15); border: 1px solid var(--warning); }

.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow);
}
.auth-card h1 { margin-bottom: .5rem; }
.brand { text-align: center; margin-bottom: 1.5rem; }
.brand-icon { font-size: 3rem; }
.muted { color: var(--muted); font-size: .8rem; margin-top: 1rem; text-align: center; }
.lang-switch a { color: var(--muted); margin: 0 .25rem; }
.lang-switch a.active { color: var(--primary); font-weight: 700; }
.user-pill {
  background: var(--bg); padding: .25rem .6rem; border-radius: 999px;
  font-size: .8rem; color: var(--muted);
}

.text-income { color: #4ade80; font-weight: 600; }
.text-expense { color: #f87171; font-weight: 600; }
.stat-card .value.text-income { color: #4ade80; }
.stat-card .value.text-expense { color: #f87171; }

.backup-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.backup-row:last-child { border-bottom: none; }
.card h3 { font-size: .95rem; margin-bottom: .75rem; color: var(--muted); }

.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 200;
  align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.super-shell .sidebar { border-top: 3px solid var(--primary); }
.super-topbar {
  background: linear-gradient(90deg, #1e3a5f 0%, #0f172a 100%);
  border-bottom-color: #334155;
}
.super-shell .nav-link.active { border-left-color: #38bdf8; }

.manual-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.manual-toc {
  position: sticky;
  top: 72px;
  padding: 1rem 1.25rem;
  max-height: calc(100vh - 88px);
  overflow-y: auto;
}
.manual-toc h2 {
  font-size: 1rem;
  margin-bottom: .75rem;
}
.manual-toc ul {
  list-style: none;
}
.manual-toc li { margin-bottom: .25rem; }
.manual-toc a {
  display: block;
  padding: .45rem .6rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: .9rem;
  text-decoration: none;
}
.manual-toc a:hover,
.manual-toc a.active {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.manual-badge {
  display: inline-block;
  font-size: .65rem;
  padding: .1rem .35rem;
  margin-left: .25rem;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--primary);
  vertical-align: middle;
}
.manual-section h2 { margin-bottom: .75rem; }
.manual-section h3 {
  font-size: 1rem;
  margin: 1.25rem 0 .5rem;
  color: var(--muted);
}
.manual-intro {
  margin-bottom: 1rem;
  line-height: 1.65;
}
.manual-steps {
  margin: 0 0 1rem 1.25rem;
  line-height: 1.65;
}
.manual-steps li { margin-bottom: .5rem; }
.manual-tips {
  margin-top: 1rem;
  padding: .85rem 1rem;
  border-left: 3px solid var(--primary);
  background: rgba(6, 182, 212, .08);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.manual-tips ul {
  margin: .5rem 0 0 1.1rem;
  line-height: 1.6;
}
.manual-nav-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .manual-layout { grid-template-columns: 1fr; }
  .manual-toc {
    position: static;
    max-height: none;
  }
  .menu-toggle { display: block; }
  .app-body { position: relative; }
  .sidebar {
    position: fixed;
    left: -280px;
    top: 56px;
    height: calc(100vh - 56px);
    z-index: 150;
    transition: left .2s;
    box-shadow: var(--shadow);
  }
  .sidebar.open { left: 0; }
  .main-content { padding: 1rem; }
  .two-col { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .topbar-actions { gap: .5rem; }
  .user-pill { display: none; }
}
