:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #0f1d2e;
  --ink-2: #4a5568;
  --muted: #6b7280;
  --line: #e5e1d8;
  --line-strong: #d6d1c4;
  --primary: #0f1d2e;
  --primary-hover: #1a2a40;
  --accent: #b08438;
  --accent-soft: #f3ead6;
  --danger: #b03a3a;
  --danger-soft: #f8e8e8;
  --success: #2d6e3e;
  --success-soft: #e7f2ea;
  --shadow-sm: 0 1px 2px rgba(15, 29, 46, 0.06);
  --shadow: 0 4px 14px rgba(15, 29, 46, 0.08);
  --shadow-lg: 0 18px 48px rgba(15, 29, 46, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font-sans); color: var(--ink); background: var(--bg); }
body { min-height: 100vh; line-height: 1.55; -webkit-font-smoothing: antialiased; }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; color: var(--ink); }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.15rem; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

/* ---------------- Login ---------------- */
.login-body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(176,132,56,0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, rgba(15,29,46,0.08), transparent 60%),
    var(--bg);
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.brand h1 { font-size: 1.25rem; margin: 0; }
.brand p { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #243a5a);
  color: #f1e3c4; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.4rem;
  letter-spacing: -0.02em;
}
.brand-mark::after { content: ''; }

form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; color: var(--ink-2); font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"], input[type="tel"], select, textarea {
  font: inherit; color: var(--ink);
  padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface);
  outline: none; transition: border 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,29,46,0.08); }
textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 500;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #f9f4e8; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #8e2f2f; }
.btn-block { width: 100%; padding: 12px 16px; }
.btn-link { background: none; border: none; color: var(--ink-2); cursor: pointer; padding: 4px 0; text-decoration: underline; font: inherit; }
.btn-link:hover { color: var(--primary); }
.icon-btn { background: none; border: none; cursor: pointer; padding: 6px; font-size: 1.1rem; color: var(--muted); border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.form-error, .form-msg { font-size: 0.85rem; padding: 8px 12px; border-radius: 8px; }
.form-error { background: var(--danger-soft); color: var(--danger); }
.form-msg.success { background: var(--success-soft); color: var(--success); }
.form-msg.error { background: var(--danger-soft); color: var(--danger); }

.login-hint { color: var(--muted); font-size: 0.8rem; text-align: center; margin-top: 20px; }

/* ---------------- App Shell ---------------- */
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--primary);
  color: #e8dfca;
  padding: 24px 18px;
  display: flex; flex-direction: column;
  border-right: 1px solid #1a2740;
}
.sidebar .brand-small { display: flex; align-items: center; gap: 12px; padding: 4px 6px 22px; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 18px; }
.sidebar .brand-small strong { font-family: var(--font-display); display: block; color: #f5ecd6; font-size: 1rem; }
.role-tag { display: inline-block; font-size: 0.7rem; color: var(--accent); margin-top: 2px; letter-spacing: 0.08em; text-transform: uppercase; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: rgba(245,236,214,0.78); font-size: 0.93rem;
  transition: background 0.12s, color 0.12s;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: rgba(176,132,56,0.18); color: #f7e9c4; }
.nav-icon { font-size: 0.85rem; color: var(--accent); width: 16px; text-align: center; }
.sidebar-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.08); display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
.sidebar-foot #me-name, .sidebar-foot #me-name { color: #f1e3c4; font-weight: 500; }
.sidebar-foot .btn-link { color: rgba(245,236,214,0.6); text-align: left; }
.sidebar-foot .btn-link:hover { color: var(--accent); }

.main { padding: 36px 44px; overflow-x: hidden; }
.view-header { margin-bottom: 22px; }
.view-header h2 { font-size: 1.6rem; }
.view-header .muted { color: var(--muted); margin-top: 4px; }
.row-between { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------------- Cards & Grid ---------------- */
.grid { display: grid; gap: 18px; margin-bottom: 24px; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .grid-cols-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) { .grid-cols-2, .grid-cols-3 { grid-template-columns: 1fr; } .app-shell { grid-template-columns: 1fr; } .sidebar { position: sticky; top: 0; z-index: 5; } .main { padding: 24px 18px; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card h3 { margin-bottom: 14px; }

.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.02em; text-transform: uppercase; }
.stat-value { font-family: var(--font-display); font-size: 2rem; font-weight: 600; color: var(--ink); letter-spacing: -0.02em; }
.stat-sub { font-size: 0.82rem; color: var(--muted); }
.stat-total { background: var(--primary); color: #f5ecd6; border-color: var(--primary); }
.stat-total .stat-label, .stat-total .stat-sub { color: rgba(245,236,214,0.7); }
.stat-total .stat-value { color: #f7e9c4; }

.chart-wrap { position: relative; height: 280px; }

/* ---------------- Categories / Assets ---------------- */
.categories { display: flex; flex-direction: column; gap: 18px; }
.category {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.category-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.category-head h3 { font-size: 1.05rem; display: flex; align-items: center; gap: 10px; }
.category-head .badge { font-size: 0.78rem; color: var(--muted); padding: 2px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }
.category-net { font-family: var(--font-display); font-size: 1.05rem; color: var(--ink); }
.category-actions { display: flex; gap: 8px; align-items: center; }

.assets-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  padding: 18px 22px 22px;
}
.asset {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
  display: flex; flex-direction: column; gap: 8px;
}
.asset:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.asset-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.asset-name { font-weight: 600; color: var(--ink); }
.asset-provider { font-size: 0.85rem; color: var(--muted); }
.asset-value { font-family: var(--font-display); font-size: 1.25rem; color: var(--ink); }
.asset-value.liability { color: var(--danger); }
.asset-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); }
.asset-meta span { padding: 2px 7px; background: var(--surface-2); border-radius: 6px; }

.empty-state { padding: 28px 22px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* ---------------- Modal & Drawer ---------------- */
.modal, .drawer {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,29,46,0.4);
  backdrop-filter: blur(2px);
  z-index: 100;
  padding: 24px;
}
.modal[hidden], .drawer[hidden] { display: none !important; }
.drawer { justify-content: flex-end; padding: 0; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.drawer-box {
  background: var(--surface);
  width: 100%; max-width: 620px;
  height: 100vh; overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 1.1rem; }
#modal-body, #drawer-body { padding: 22px; overflow-y: auto; flex: 1; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.field-set { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--surface-2); }
.field-set legend { padding: 0 6px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.custom-fields { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.cf-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.cf-row .icon-btn { color: var(--danger); }

/* ---------------- Table ---------------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }

/* ---------------- Personal Data & Contacts ---------------- */
.section { margin-bottom: 24px; }
.section h4 { font-family: var(--font-display); font-size: 1.05rem; margin-bottom: 10px; color: var(--ink); }
.kv-row { display: grid; grid-template-columns: 220px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.kv-row:last-child { border-bottom: none; }
.kv-label { color: var(--muted); font-size: 0.88rem; }
.kv-value { color: var(--ink); word-break: break-word; }
.kv-actions { display: flex; gap: 4px; }

.contact-card { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 10px; }
.contact-head { display: flex; justify-content: space-between; align-items: start; }
.contact-name { font-weight: 600; }
.contact-rel { font-size: 0.85rem; color: var(--muted); }
.contact-detail { font-size: 0.88rem; color: var(--ink-2); margin-top: 6px; }

/* ---------------- Upcoming ---------------- */
.upcoming { display: flex; flex-direction: column; gap: 8px; }
.upcoming-row { display: flex; justify-content: space-between; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.upcoming-row strong { color: var(--ink); }
.upcoming-row .date { color: var(--accent); font-weight: 600; }

/* ---------------- Print ---------------- */
@media print {
  .sidebar, .app-shell > .sidebar, .row.gap, .icon-btn, button { display: none !important; }
  .app-shell { grid-template-columns: 1fr; }
  .main { padding: 0; }
  body { background: white; }
  .card { box-shadow: none; border-color: #ddd; page-break-inside: avoid; }
}

/* ---------------- Misc ---------------- */
.tag-shared { background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; }
.tag-personal { background: var(--surface-2); color: var(--ink-2); padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; border: 1px solid var(--line); }
.scope-divider { font-family: var(--font-display); font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 20px 0 10px; }

.detail-section { margin-bottom: 22px; }
.detail-section h4 { margin-bottom: 8px; }
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 0.92rem; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; color: var(--ink); }

.history-table { font-size: 0.86rem; width: 100%; }
.history-table td { padding: 4px 8px; }

.danger-zone { margin-top: 24px; padding: 14px; border: 1px dashed var(--danger); border-radius: 10px; background: var(--danger-soft); }
.danger-zone p { color: var(--danger); font-size: 0.85rem; margin-bottom: 8px; }

.print-page { padding: 20px; max-width: 820px; margin: 0 auto; }
.print-page h1 { font-size: 1.8rem; margin-bottom: 4px; }
.print-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 24px; }
/* ---------------- MOBILE (< 768px) ---------------- */
@media (max-width: 767px) {
  /* Layout: Sidebar wird Bottom-Nav */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
  }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    top: auto; height: auto;
    flex-direction: row;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid #1a2740;
    z-index: 50;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.18);
  }
  .sidebar .brand-small, .sidebar-foot { display: none; }
  .sidebar nav {
    flex-direction: row;
    justify-content: space-around;
    align-items: stretch;
    gap: 0;
    width: 100%;
  }
  .sidebar nav a {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    font-size: 0.72rem;
    text-align: center;
    border-radius: 8px;
    min-height: 50px;
  }
  .sidebar nav a .nav-icon { font-size: 1.1rem; width: auto; }
  .sidebar nav a.active { background: rgba(176,132,56,0.22); }

  /* Mobile Top-Bar mit User + Logout */
  .mobile-topbar {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--primary);
    color: #f5ecd6;
    position: sticky; top: 0; z-index: 40;
    box-shadow: var(--shadow-sm);
  }
  .mobile-topbar .brand-small { display: flex; align-items: center; gap: 10px; }
  .mobile-topbar .brand-mark { width: 32px; height: 32px; font-size: 1rem; border-radius: 8px; }
  .mobile-topbar strong { font-family: var(--font-display); font-size: 0.95rem; color: #f5ecd6; }
  .mobile-topbar .role-tag { font-size: 0.62rem; }
  .mobile-topbar .topbar-actions { display: flex; gap: 8px; }
  .mobile-topbar .icon-btn { color: rgba(245,236,214,0.8); }
  .mobile-topbar .icon-btn:hover { color: #f7e9c4; background: rgba(255,255,255,0.06); }

  .main {
    padding: 18px 16px calc(80px + env(safe-area-inset-bottom));
  }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.3rem; }
  .view-header h2 { font-size: 1.3rem; }
  .view-header .muted { font-size: 0.85rem; }
  .row-between { flex-direction: column; align-items: stretch; gap: 12px; }
  .row-between > .row.gap { justify-content: flex-end; flex-wrap: wrap; }

  /* Grids */
  .grid-cols-2, .grid-cols-3 { grid-template-columns: 1fr; gap: 12px; }
  .grid { gap: 12px; margin-bottom: 16px; }
  .card { padding: 16px; }
  .stat-value { font-size: 1.6rem; }
  .chart-wrap { height: 220px; }

  /* Categories & Assets */
  .category-head { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .category-head h3 { font-size: 0.98rem; }
  .assets-grid { padding: 12px 14px 16px; grid-template-columns: 1fr; gap: 10px; }
  .asset { padding: 14px; }
  .asset-value { font-size: 1.1rem; }

  /* Modal & Drawer fullscreen */
  .modal, .drawer { padding: 0; align-items: stretch; }
  .modal-box, .drawer-box {
    max-width: 100%;
    max-height: 100%;
    height: 100vh;
    border-radius: 0;
    width: 100%;
  }
  .modal-head { padding: 14px 16px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
  #modal-body, #drawer-body { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }

  /* Buttons besser touch-bar */
  .btn { padding: 11px 16px; min-height: 44px; }
  .btn-block { padding: 13px 16px; }
  .icon-btn { padding: 8px; min-width: 36px; min-height: 36px; }
  input[type="text"], input[type="password"], input[type="number"],
  input[type="date"], input[type="email"], input[type="tel"],
  select, textarea {
    padding: 12px 14px; font-size: 16px; /* 16px verhindert iOS Zoom */
  }

  /* Tabellen → Karten */
  .table, .table thead, .table tbody, .table tr, .table th, .table td { display: block; }
  .table thead { display: none; }
  .table tr {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px 14px;
  }
  .table td {
    border-bottom: none;
    padding: 4px 0;
    font-size: 0.9rem;
  }
  .table td::before {
    content: attr(data-label);
    display: inline-block;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 8px;
    min-width: 70px;
  }

  /* Personal-Data kv-rows mobile-friendlier */
  .kv-row { grid-template-columns: 1fr; gap: 4px; padding: 12px 0; }
  .kv-actions { justify-content: flex-end; }

  /* Detail-Grid */
  .detail-grid { grid-template-columns: 1fr; gap: 2px; padding: 8px 0; }
  .detail-grid dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
  .detail-grid dd { margin-bottom: 8px; }

  /* Custom-Fields-Editor */
  .cf-row { grid-template-columns: 1fr; gap: 6px; }

  /* Login auf Mobile */
  .login-card { padding: 28px 22px; border-radius: 12px; }
  .brand h1 { font-size: 1.1rem; }
}

/* Desktop: mobile topbar versteckt */
@media (min-width: 768px) {
  .mobile-topbar { display: none !important; }
}

/* PWA standalone tweaks */
@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
  input, textarea, [contenteditable], .asset-name, .asset-value,
  .kv-value, .detail-grid dd { user-select: text; -webkit-user-select: text; }
}

/* === v6 Ergänzungen === */
.vis-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.vis-shared { background: rgba(201, 152, 90, 0.16); color: #8a6628; }
.vis-personal { background: rgba(15, 29, 46, 0.08); color: #0f1d2e; }
.filter-btn { font-size: 0.85rem; padding: 6px 14px; }
.filter-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-danger { background: rgba(180, 60, 60, 0.1); color: #b53d3d; border-color: rgba(180, 60, 60, 0.3); }
.btn-danger:hover { background: rgba(180, 60, 60, 0.18); }
.doc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  gap: 12px;
}
.doc-name { font-weight: 500; color: var(--ink); word-break: break-word; }

.ocr-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 500;
}
.ocr-done { background: rgba(100, 160, 100, 0.18); color: #2d5a2d; }
.ocr-processing { background: rgba(201, 152, 90, 0.16); color: #8a6628; }
.ocr-pending { background: rgba(15, 29, 46, 0.08); color: #5a6478; }
.ocr-info { background: rgba(15, 29, 46, 0.06); color: #5a6478; }
.ocr-error { background: rgba(180, 60, 60, 0.12); color: #b53d3d; cursor: help; }
input[type="search"] {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.95rem;
}
