:root {
  --bg: #f5f5fb;
  --surface: #ffffff;
  --surface-2: #fbfbfe;
  --border: #e9e9f2;
  --text: #191a23;
  --muted: #6b7280;
  --primary: #6d5ef8;
  --primary-dark: #5541e8;
  --primary-light: #9186fa;
  --primary-soft: #f1eefe;
  --success: #16a34a;
  --success-soft: #eafbf1;
  --danger: #e11d48;
  --danger-soft: #fdecef;
  --warning: #d97706;
  --warning-soft: #fef6e7;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 43, 0.05), 0 1px 1px rgba(20, 20, 43, 0.03);
  --shadow-md: 0 8px 24px rgba(24, 22, 65, 0.08);
  --shadow-lg: 0 16px 40px rgba(24, 22, 65, 0.14);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

h1 { font-size: 1.6rem; margin: 0 0 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 1.9rem 0 0.9rem; font-weight: 700; color: #2b2c3a; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 0; }
.muted { color: var(--muted); font-size: 0.87rem; }
.icon { flex-shrink: 0; }

/* ===================== App shell ===================== */
.shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 258px;
  flex-shrink: 0;
  background: linear-gradient(190deg, #1a1733 0%, #211c48 55%, #2a2160 100%);
  color: #e4e2f5;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0.5rem 1.6rem; }
.brand-mark {
  width: 15px; height: 15px; border-radius: 5px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary-light), #22d3c8);
  box-shadow: 0 0 0 5px rgba(109, 94, 248, 0.18);
}
.brand-mark.lg { width: 40px; height: 40px; border-radius: 12px; margin: 0 auto 0.9rem; box-shadow: 0 8px 22px rgba(109, 94, 248, 0.35); }
.brand-text { font-weight: 800; font-size: 0.95rem; line-height: 1.25; letter-spacing: -0.01em; color: #fff; }
.brand-text small { font-weight: 500; color: #a9a4d6; font-size: 0.78rem; }

.side-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; margin-top: 0.5rem; }
.side-nav a {
  display: flex; align-items: center; gap: 0.75rem;
  color: #c2bfe6; padding: 0.62rem 0.8rem; border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 500; transition: background 0.15s ease, color 0.15s ease;
}
.side-nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.side-nav a.active {
  background: linear-gradient(135deg, var(--primary), #7c6ff9);
  color: #fff; font-weight: 600; box-shadow: 0 6px 16px rgba(109, 94, 248, 0.4);
}

.side-user {
  display: flex; align-items: center; gap: 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 1rem; margin-top: 0.5rem;
}
.side-user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary-light), #22d3c8);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
}
.side-user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.side-user-info strong { font-size: 0.85rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-info span { font-size: 0.74rem; color: #a9a4d6; }
.side-icon-btn {
  background: rgba(255, 255, 255, 0.07); border: none; color: #c2bfe6; cursor: pointer; text-decoration: none;
  width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.side-icon-btn:hover { background: var(--primary); color: #fff; }
.side-logout:hover { background: var(--danger); color: #fff; }
form.inline { margin: 0; }

.side-accounts {
  display: flex; flex-direction: column; gap: 0.3rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 0.9rem; margin-top: 0.5rem;
}
.side-accounts-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: #8b86bd; padding: 0 0.5rem 0.15rem; }
.side-account-btn {
  display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left;
  background: none; border: none; color: #c2bfe6; padding: 0.4rem 0.5rem; border-radius: var(--radius-sm);
  font-size: 0.8rem; font-family: inherit; cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.side-account-btn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.side-user-avatar.sm { width: 24px; height: 24px; font-size: 0.72rem; flex-shrink: 0; }
.side-accounts-logout-all {
  background: none; border: none; color: #8b86bd; font-size: 0.72rem; font-family: inherit; cursor: pointer;
  text-align: left; padding: 0.35rem 0.5rem 0.1rem; text-decoration: underline; text-underline-offset: 2px;
}
.side-accounts-logout-all:hover { color: #fff; }

.account-tiles { display: flex; flex-direction: column; gap: 0.5rem; }
.account-tile-form { margin: 0; }
.account-tile {
  display: flex; align-items: center; gap: 0.7rem; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 0.65rem 0.8rem; font-family: inherit; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease;
}
.account-tile:hover { background: var(--primary-soft); border-color: var(--primary-light); }
.account-tile-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary-light), #22d3c8); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem;
}
.account-tile-info { display: flex; flex-direction: column; min-width: 0; }
.account-tile-info strong { font-size: 0.86rem; color: var(--text); }
.account-tile-info span { font-size: 0.76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.shell-main { flex: 1; min-width: 0; }
.content-area { max-width: 1180px; margin: 0 auto; padding: 2.4rem 2.6rem 3.5rem; }
.bare-area { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }

/* ===================== Cards / tables / general ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.6rem;
  margin-bottom: 1.4rem;
  box-shadow: var(--shadow-sm);
}
.card.center-card { max-width: 480px; margin-left: auto; margin-right: auto; text-align: center; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
th, td { text-align: left; padding: 0.75rem 1rem; font-size: 0.87rem; }
th {
  background: var(--surface-2); font-weight: 700; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid #f1f1f7; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--primary-soft); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-weight: 600; }
td.muted-cell { color: var(--muted); font-size: 0.82rem; line-height: 1.35; }

.filters {
  display: flex; gap: 1rem; flex-wrap: wrap; align-items: end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem; margin-bottom: 1.4rem; box-shadow: var(--shadow-sm);
}
.filters label { display: flex; flex-direction: column; font-size: 0.75rem; color: var(--muted); gap: 0.3rem; font-weight: 600; }
.filters select, .filters input {
  padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.86rem;
  font-family: inherit; background: var(--surface-2); color: var(--text);
}
.filters select:focus, .filters input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: #fff; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem; justify-content: center;
  padding: 0.62rem 1.15rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
  font-family: inherit; box-shadow: 0 4px 12px rgba(109, 94, 248, 0.28);
}
.btn:hover { filter: brightness(1.06); color: white; box-shadow: 0 6px 16px rgba(109, 94, 248, 0.36); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: none; }
.btn.secondary:hover { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary-light); }
.btn.danger { background: linear-gradient(135deg, var(--danger), #c81e46); box-shadow: 0 4px 12px rgba(225, 29, 72, 0.28); }
.btn.small { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn:disabled { cursor: not-allowed; filter: grayscale(0.3) brightness(0.95); box-shadow: none; transform: none; opacity: 0.75; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1.15rem; }
.form-grid label, form > label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.84rem; font-weight: 600; color: #374151; margin-bottom: 1rem; }
.form-grid input, .form-grid select, .form-grid textarea { padding: 0.58rem 0.7rem; font-size: 0.88rem; }
input, select, textarea {
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; color: var(--text); background: var(--surface-2);
  padding: 0.55rem 0.7rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: #fff; }
textarea { width: 100%; font-family: inherit; }

.checkbox-row { flex-direction: row !important; align-items: center; gap: 0.5rem !important; font-weight: 500 !important; color: var(--muted) !important; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--primary); }

.noten-rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 0.65rem; margin: 0.9rem 0; }
.noten-row {
  display: flex; flex-direction: column; gap: 0.35rem; background: var(--surface-2);
  border: 1px solid var(--border); padding: 0.55rem 0.6rem; border-radius: var(--radius-sm);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.noten-row.has-value { background: var(--primary-soft); border-color: var(--primary-light); }
.noten-row label { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.stepper { display: flex; align-items: stretch; gap: 0.3rem; }
.stepper input {
  padding: 0.35rem 0.2rem; text-align: center; font-weight: 700; width: 100%; min-width: 0;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-btn {
  flex-shrink: 0; width: 30px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--primary-dark); font-size: 1rem; font-weight: 700;
  cursor: pointer; line-height: 1; transition: background 0.12s ease, transform 0.08s ease;
}
.stepper-btn:hover { background: var(--primary-soft); }
.stepper-btn:active { transform: scale(0.92); }

.summary-line {
  display: flex; gap: 2.2rem; font-size: 0.88rem; margin: 0.7rem 0 1.1rem; color: var(--muted);
  background: var(--primary-soft); border-radius: var(--radius-md); padding: 0.9rem 1.15rem; width: fit-content;
}
.summary-line strong { font-size: 1.2rem; color: var(--text); display: block; }

.warning-box {
  background: var(--warning-soft); border: 1px solid #f3d391; color: #8a5a09;
  padding: 0.85rem 1.1rem; border-radius: var(--radius-md); margin-bottom: 0.9rem; font-size: 0.87rem;
}
.flash { padding: 0.75rem 1.1rem; border-radius: var(--radius-md); margin-bottom: 1.2rem; font-size: 0.88rem; font-weight: 600; }
.flash.success { background: var(--success-soft); border: 1px solid #86e0ae; color: #0e7a3d; }
.flash.error { background: var(--danger-soft); border: 1px solid #fda4af; color: #9f1239; }
.error-box { background: var(--danger-soft); border: 1px solid #fda4af; color: #9f1239; padding: 0.75rem 1.1rem; border-radius: var(--radius-md); margin-bottom: 1.2rem; font-size: 0.88rem; }

.badge {
  display: inline-block; padding: 0.22rem 0.65rem; border-radius: 999px; font-size: 0.74rem; font-weight: 700;
  background: var(--success-soft); color: #0e7a3d;
}
.badge.good { background: var(--success-soft); color: #0e7a3d; }
.badge.warn { background: var(--warning-soft); color: #92400e; }
.badge.bad { background: var(--danger-soft); color: #9f1239; }

/* ===================== Login ===================== */
.bare-area {
  background:
    radial-gradient(circle at 15% 10%, rgba(109, 94, 248, 0.14), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(34, 211, 200, 0.14), transparent 40%),
    var(--bg);
}
.login-wrap { width: 100%; max-width: 400px; }
.login-brand { text-align: center; margin-bottom: 1.6rem; }
.login-brand h1 { font-size: 1.3rem; margin: 0 0 0.35rem; }
.login-box { padding: 1.8rem 1.8rem 1.6rem; }
.login-box form label { margin-bottom: 1.05rem; }
.login-box input { width: 100%; }
.login-box .btn { width: 100%; padding: 0.72rem; margin-top: 0.3rem; }
.login-hint { text-align: center; margin-top: 1.2rem; font-size: 0.8rem; }

/* ===================== Metric cards / empty state ===================== */
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.metric-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.05rem 1.2rem; box-shadow: var(--shadow-sm);
}
.metric-value { display: block; font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.metric-label { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }
.metric-card.metric-warn { background: var(--warning-soft); border-color: #f3d391; }
.metric-card.metric-warn .metric-value { color: #8a5a09; }

.empty-state {
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: 2.4rem 1.5rem; text-align: center; color: var(--muted);
}
.empty-state p { margin: 0 0 1.1rem; font-size: 0.95rem; }

/* ===================== Stat hub ===================== */
.stat-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 1.1rem; }
.stat-card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem; color: var(--text); box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--primary-light); color: var(--text); }
.stat-card .stat-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-soft), #e3f7f5); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem; margin-bottom: 0.8rem;
}
.stat-card strong { display: block; font-size: 0.97rem; margin-bottom: 0.3rem; }
.stat-card span { font-size: 0.81rem; color: var(--muted); }

/* ===================== Charts ===================== */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px,1fr)); gap: 1.3rem; margin: 0.5rem 0 1.6rem; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.2rem 1.3rem 1.35rem; box-shadow: var(--shadow-sm); }
.chart-card h3 { margin: 0 0 0.9rem; color: #2b2c3a; }
.chart-card .chart-wrap { position: relative; height: 260px; }
.chart-card.tall .chart-wrap { height: 340px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 0.9rem 1.1rem; }
  .brand { padding: 0; margin-right: auto; }
  .side-nav { flex-direction: row; flex: none; margin: 0; overflow-x: auto; }
  .side-nav a span { display: none; }
  .side-user { border: none; padding: 0; margin: 0 0 0 0.5rem; }
  .side-user-info { display: none; }
  .side-accounts { display: none; }
  .content-area { padding: 1.5rem 1.1rem 2.5rem; }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}
