/* ═══════════════════════════════════════════
   Immo Mgmt — Modern Teal Design System
   Body/UI: Plus Jakarta Sans | Primary: #00A69C (Teal)
   ═══════════════════════════════════════════ */

/* ── Tokens ── */
:root {
  --bg-page:       #f1f5f9;
  --bg-surface:    #ffffff;
  --bg-surface-2:  #f8fafc;
  --bg-header:     #D0D5DD;

  --color-primary:            #00A69C;
  --color-primary-dim:        rgba(0,166,156,.10);
  --color-primary-border:     rgba(0,166,156,.25);
  --color-primary-hover:      #008F86;
  --color-primary-dark:       #006B65;
  --color-primary-btn-border: #00B5AB;

  /* Gold-Aliases → Türkis */
  --color-gold:               #00A69C;
  --color-gold-dim:           rgba(0,166,156,.10);
  --color-gold-border:        rgba(0,166,156,.25);
  --color-gold-nav-bg:        rgba(0,166,156,.10);
  --color-gold-nav-border:    rgba(0,166,156,.25);
  --color-gold-hover:         #008F86;
  --color-gold-btn-border:    #00B5AB;

  --color-green:         #10b981;
  --color-green-dim:     rgba(16,185,129,.12);
  --color-red:           #DC2626;
  --color-red-light:     #EF4444;
  --color-red-dim:       rgba(220,38,38,.10);
  --color-red-hover:     #B91C1C;
  --color-red-btn-border: #EF4444;
  --focus-ring-red:      rgba(220,38,38,.10);
  --color-purple-light:  #A855F7;
  --color-purple-dim:    rgba(88,28,135,.18);

  --text-primary:   #0f172a;
  --text-secondary: #334155;
  --text-muted:     #64748b;
  --text-faint:     #94a3b8;

  --border-subtle:  #f1f5f9;
  --border-default: #e2e8f0;
  --border-strong:  #cbd5e1;
  --border-faint:   #f8fafc;
  --border-hover:   #94a3b8;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-glow: 0 0 12px rgba(0,166,156,.18);
  --shadow-lg:   0 4px 16px rgba(0,0,0,.08);
  --shadow-teal: 0 0 0 3px rgba(0,166,156,.15);

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-full: 9999px;

  --transition: .15s ease;
}

/* ── Reset ── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ── */
body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 13px;
  line-height: 1.5;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--color-primary-hover); }
h1,.page-title {
  font-size: 22px; font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.4px; line-height: 1.2;
}
h2 {
  font-size: 16px; font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}
h3 {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.subtitle,.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Top Navigation ── */
.topnav {
  height: 56px; background: #fff;
  border-bottom: 1px solid var(--border-default);
  display: flex; align-items: center;
  padding: 0 24px; position: sticky;
  top: 0; z-index: 40; flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topnav-logo {
  display: flex; align-items: center; gap: 8px;
  margin-right: 32px; text-decoration: none; flex-shrink: 0;
}
.topnav-logo:hover { text-decoration: none; opacity: .9; }
.topnav-logo-mark {
  width: 34px; height: 34px;
  display: block;
}
.topnav-logo-text { font-size: 15px; font-weight: 700; color: var(--text-primary); letter-spacing: -.3px; }
.topnav-logo-text span { color: var(--color-primary); }
.topnav-nav { display: flex; align-items: center; flex: 1; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  white-space: nowrap; cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.nav-link:hover { color: var(--text-secondary); background: var(--bg-surface-2); text-decoration: none; }
.nav-link.active { color: var(--color-primary); background: var(--color-primary-dim); font-weight: 600; }
.nav-ico { font-size: 14px; flex-shrink: 0; }
.nav-label { font-size: 13px; }
.topnav-right { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
.topnav-user { width: 34px; height: 34px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.topnav-user:hover { opacity: .85; }
.user-avatar {
  width: 34px; height: 34px; border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-avatar-img { width: 34px; height: 34px; border-radius: var(--radius-full); object-fit: cover; flex-shrink: 0; }

/* User-Menu Dropdown */
.user-menu { position: relative; }
.user-menu-dropdown {
  display: none;
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 220px;
}
.user-menu-dropdown.open { display: block; }

/* Bell */
.bell-container { position: relative; }
#bell-btn {
  width: 34px; height: 34px; border-radius: var(--radius-full);
  background: var(--bg-surface-2); border: 1px solid var(--border-default);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted); font-size: 14px;
  position: relative; padding: 0;
}
#bell-btn:hover { border-color: var(--border-hover); color: var(--text-secondary); }
#notif-panel {
  display: none;
  position: absolute; right: 0; top: 110%;
  width: 300px; z-index: 100;
}
#notif-panel.open { display: block; }
.notif-unread { border-left: 2px solid var(--color-red); }
.notif-badge {
  position: absolute; top: -3px; right: -3px;
  background: var(--color-red); color: #fff;
  font-size: 8px; border-radius: var(--radius-full);
  padding: 1px 3px; font-weight: 700; line-height: 1;
}

/* ── Main content ── */
.main { flex: 1; padding: 24px 28px; min-height: calc(100vh - 56px); }

/* ── Page header ── */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Breadcrumb ── */
.breadcrumb { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text-secondary); text-decoration: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 20px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  text-decoration: none; white-space: nowrap;
  letter-spacing: .2px; line-height: 1;
  transition: background var(--transition), opacity var(--transition);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary-btn-border); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: #fff; color: var(--color-primary); border-color: var(--color-primary); }
.btn-secondary:hover { background: var(--color-primary-dim); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border-default); }
.btn-ghost:hover { background: var(--bg-surface-2); }
.btn-utility {
  background: rgba(34,197,94,.10);
  color: #15803d;
  border-color: rgba(34,197,94,.35);
}
.btn-utility:hover { background: rgba(34,197,94,.18); color: #166534; }
.btn-danger { background: var(--color-red); color: #fff; border-color: var(--color-red-btn-border); }
.btn-danger:hover { background: var(--color-red-hover); }
.btn-sm { font-size: 12px; padding: 5px 13px; }
.btn:disabled,.btn[disabled] { opacity: .35; cursor: not-allowed; pointer-events: none; }

/* ── Detail-page action buttons (Bearbeiten, Start/Ende setzen, Abbrechen) ── */
.page-header .btn,
.page-header a.btn {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary-btn-border);
  box-shadow: none;
}
.page-header .btn:hover,
.page-header a.btn:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
}

/* ── Cards ── */
.card {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, border-color .2s ease;
}
.card:hover { border-color: var(--color-primary-border); box-shadow: var(--shadow-glow); }
.card-accent { border-top: 2px solid var(--color-primary); }
.card-label {
  font-size: 10px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 5px;
}

/* Disable hover glow on detail page info cards */
.page-header ~ .grid-3 .card:hover,
.page-header + .grid-3 .card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border-default);
}

/* ── Stat cards ── */
.stat-card {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); padding: 13px 15px; border-top-width: 2px;
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 10px; font-weight: 600;
  color: var(--text-muted); letter-spacing: .8px; text-transform: uppercase; margin-bottom: 6px;
}
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; color: var(--text-primary); }
.stat-delta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-card.accent,
.stat-card.warn   { border-top-color: var(--color-primary); }
.stat-card.accent .stat-value,
.stat-card.warn   .stat-value { color: var(--color-primary); }
.stat-card.danger { border-top-color: var(--color-red); }
.stat-card.danger .stat-value { color: var(--color-red); }

/* ── Table wrapper ── */
.table-card {
  background: var(--bg-surface); border: 1px solid var(--border-default);
  border-radius: var(--radius-md); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; }
th {
  padding: 11px 14px; text-align: left;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary);
  border-bottom: 2px solid var(--border-strong);
  background: var(--bg-surface-2);
}
tfoot td, tfoot th {
  padding: 10px 14px; font-size: 13px;
  background: var(--bg-surface-2);
  border-top: 2px solid var(--border-strong);
  color: var(--text-secondary);
}
td {
  padding: 10px 14px; font-size: 13px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}
td:first-child { color: var(--text-primary); font-weight: 600; }
tbody tr:hover { background: rgba(0,166,156,.035); }
tbody tr:last-child td { border-bottom: none; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600;
  letter-spacing: .4px; text-transform: uppercase;
}
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-ok,
.badge-done    { background: var(--color-green-dim); color: var(--color-green); }
.badge-warn,
.badge-accent,
.badge-scheduled,
.badge-due_soon,
.badge-active  { background: var(--color-gold-dim);  color: var(--color-gold); }
.badge-danger,
.badge-overdue { background: var(--color-red-dim);   color: var(--color-red-light); }
.badge-muted,
.badge-skipped,
.badge-open_ended,
.badge-cancelled,
.badge-not_started,
.badge-pending    { background: rgba(0,0,0,.06); border: 1px solid var(--border-default); color: var(--text-muted); }
.badge-obsolete { background: rgba(0,0,0,.06); border: 1px solid var(--border-default); color: var(--text-muted); }
.badge-info      { background: var(--color-purple-dim); color: var(--color-purple-light); }
.badge-apartment { background: rgba(59,130,246,.15);  color: #60a5fa; }
.badge-parking   { background: var(--color-primary-dim); color: var(--color-primary); }

/* ── Badge aliases — dynamic status values from model properties ── */

/* contracts: Contract.status property */
.badge-active      { background: var(--color-green-dim); color: var(--color-green); }
.badge-expired     { background: var(--color-red-dim);   color: var(--color-red-light); }
.badge-expiring    { background: var(--color-gold-dim);  color: var(--color-gold); }
.badge-renewing_soon { background: var(--color-gold-dim); color: var(--color-gold); }
.badge-open_ended  { background: rgba(0,0,0,.06); border: 1px solid var(--border-default); color: var(--text-muted); }

/* Contract detail badge — larger & readable */
.page-header .badge {
  padding: 5px 14px;
  font-size: 13px;
  letter-spacing: .5px;
  white-space: nowrap;
}

/* renovation: Measure.status & MaintenanceTask.status */
.badge-in_progress { background: var(--color-gold-dim);  color: var(--color-gold); }
.badge-planning    { background: var(--color-purple-dim); color: var(--color-purple-light); }

/* renovation: PhaseInstance.status choices */
.badge-completed   { background: var(--color-green-dim); color: var(--color-green); }

/* renovation: Milestone.status & WarrantyTickler.status */
.badge-due         { background: var(--color-red-dim);   color: var(--color-red-light); }
.badge-delayed     { background: var(--color-red-dim);   color: var(--color-red-light); }

/* renovation: milestone row status indicators */
.ms-row--done    { border-color: rgba(34,197,94,.25) !important; border-left-color: var(--color-green) !important; }
.ms-row--delayed { border-color: rgba(220,38,38,.2)  !important; border-left-color: var(--color-red-light) !important; }

/* maintenance: MaintenanceInstance.status & MaintenanceTask.status */
.badge-planned     { background: var(--color-gold-dim);  color: var(--color-gold); }
.badge-open        { background: var(--color-purple-dim); color: var(--color-purple-light); }

/* ── Messages ── */
.messages { margin-bottom: 16px; }
.message { border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 8px; font-size: 13px; }
.message.success { background: var(--color-green-dim);  border: 1px solid rgba(34,197,94,.25);  color: var(--color-green); }
.message.error   { background: var(--color-red-dim);    border: 1px solid rgba(153,27,27,.35);  color: var(--color-red-light); }
.message.warning { background: var(--color-gold-dim);   border: 1px solid var(--color-gold-border);  color: var(--color-gold); }
.message.info    { background: var(--color-purple-dim); border: 1px solid rgba(88,28,135,.35);  color: var(--color-purple-light); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 5px;
}
input,textarea {
  width: 100%; padding: 8px 11px; height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface); color: var(--text-primary);
  font-size: 13px;
}
textarea { height: auto; padding-top: 9px; resize: vertical; }
select {
  width: 100%; height: 38px; padding: 8px 32px 8px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface); color: var(--text-primary);
  font-size: 13px;
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
input:hover,select:hover,textarea:hover { border-color: var(--border-hover); }
input:focus,select:focus,textarea:focus {
  border-color: var(--color-primary); outline: none;
  box-shadow: var(--shadow-teal);
}
input.error,select.error,textarea.error {
  border-color: var(--color-red);
  box-shadow: 0 0 0 3px var(--focus-ring-red);
}
input[type=checkbox] { width: auto; height: auto; }
input[type=radio] { width: auto; height: auto; }
input::placeholder,textarea::placeholder { color: var(--text-faint); }

/* ── Checkbox pills ── */
.checkbox-pills ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.checkbox-pills li { margin: 0; }
.checkbox-pills label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--radius-sm);
  background: var(--bg-surface); border: 1px solid var(--border-strong);
  font-size: 12px; color: var(--text-muted);
  text-transform: none; letter-spacing: 0; font-weight: 500;
  margin: 0; cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.checkbox-pills label:hover { background: var(--bg-surface-2); }
.checkbox-pills label:has(input:checked) {
  background: var(--color-primary); color: #fff; border-color: var(--color-primary);
}
.checkbox-pills input[type=checkbox] { width: auto; margin: 0; }

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 1px solid var(--border-default); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  padding: 9px 16px;
  font-size: 13px; font-weight: 500; letter-spacing: .2px;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  text-decoration: none; display: inline-block;
  transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text-secondary); text-decoration: none; }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

/* ── Inline form (action panels: ratings, quick-create forms) ── */
.inline-form {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-top: 12px;
  box-shadow: var(--shadow-sm);
}

/* ── Filter / search bar (wraps GET filter forms) ── */
.filter-bar,
.filter-row {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.filter-bar input,
.filter-bar select,
.filter-row input,
.filter-row select { margin: 0; }

/* ── Contract list filter columns ── */
.filter-col { position: relative; flex-shrink: 0; }
.filter-icon {
  position: absolute; left: .5rem; top: 50%; transform: translateY(-50%);
  font-size: 13px; z-index: 1; pointer-events: none; line-height: 1;
}
.filter-col select { width: 12rem; padding: 6px 8px 6px 1.8rem; }
.filter-col.filter-active::after {
  content: ''; position: absolute; top: 3px; right: 3px;
  width: 7px; height: 7px;
  background: var(--color-red); border-radius: 50%; pointer-events: none;
}

/* ── Form section (replaces raw fieldset inline styles) ── */
.form-section {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 16px;
  background: var(--bg-surface);
}
.form-section-legend {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin-bottom: 12px;
}

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 40px; color: var(--text-muted); font-size: 14px; }

/* ── Grids ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── HTMX ── */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator { opacity: 1; }

/* ── Login ── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; width: 100%; padding: 24px;
}
.login-card { width: 100%; max-width: 400px; }
.login-card h1 {
  font-size: 20px; font-weight: 700; margin-bottom: 24px;
  color: var(--color-primary); letter-spacing: -.3px;
}

/* ── Profile ── */
.profile-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.profile-avatar-placeholder {
  width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: #fff;
}

/* ── Bottom Nav — hidden on desktop ── */
.bottom-nav { display: none; }

/* ═══════════════════════════════════════════════
   Mobile — max-width: 767px
   All rules here override desktop ONLY on mobile.
   Desktop (≥ 768px) is completely unaffected.
   ═══════════════════════════════════════════════ */
@media (max-width: 767px) {

  /* ── Base ── */
  body { font-size: 15px; padding-bottom: 64px; }
  .main { padding: 16px 16px; }

  /* ── Topnav — slim ── */
  .topnav { padding: 0 16px; }
  .topnav-nav { display: none; }
  .topnav-logo { margin-right: 0; }

  /* ── Bottom Navigation ── */
  .bottom-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid var(--border-default);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 40;
  }
  .bn-tab {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px; padding: 8px 4px;
    font-size: 10px; color: var(--text-faint);
    text-decoration: none; line-height: 1;
  }
  .bn-tab:hover { color: var(--text-muted); text-decoration: none; }
  .bn-tab.bn-active { color: var(--color-primary); font-weight: 600; }
  .bn-ico { font-size: 18px; line-height: 1; }
  .bn-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

  /* ── Touch targets ── */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  input:not([type=hidden]):not([type=checkbox]),
  select,
  textarea { min-height: 44px; }

  /* ── Page header ── */
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-actions { width: 100%; flex-direction: column; }
  .header-actions .btn,
  .page-header > .btn,
  .page-header > a.btn { width: 100%; justify-content: center; }

  /* ── Filter forms — wrap on narrow screens ── */
  form[method="get"] { flex-wrap: wrap !important; }
  form[method="get"] select { min-width: 140px; flex: 1 1 140px; }

  /* ── Grids → single column ── */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* ── Tables → Cards ── */
  .table-card {
    border: none; background: transparent;
    box-shadow: none; overflow: visible;
  }
  .table-card table,
  .table-card thead,
  .table-card tbody,
  .table-card tr,
  .table-card td { display: block; width: 100%; }
  .table-card thead { display: none; }
  .table-card tbody tr {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
  }
  .table-card tbody tr:hover {
    background: var(--bg-surface);
    box-shadow: var(--shadow-glow);
  }
  .table-card tbody tr:last-child td { border-bottom: none; }
  .table-card td {
    padding: 5px 0; border-bottom: none;
    display: flex; align-items: flex-start; gap: 8px;
  }
  .table-card td::before {
    content: attr(data-label);
    font-size: 11px; font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase; letter-spacing: .05em;
    min-width: 90px; flex-shrink: 0; padding-top: 1px;
  }
  .table-card td:first-child { font-size: 14px; font-weight: 600; }
  .table-card td:first-child::before { display: none; }

  /* ── Detail tables inside panels — horizontal scroll ── */
  .card > .table-card,
  .card > table { overflow-x: auto; }
}

/* ═══════════════════════════════════════════════
   Tablet — 768px to 1024px
   Top-nav stays visible, bottom-nav stays hidden.
   Tables get horizontal scroll (no card conversion).
   ═══════════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1024px) {
  .main { padding: 20px 16px; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .table-card,
  .card > table { overflow-x: auto; }
  .page-header { flex-wrap: wrap; gap: 12px; }
}

/* ═══════════════════════════════════════════════
   Desktop — ≥ 1025px: centered 3/5 content column
   White side margins, grey centered column.
   Scoped to body.app-shell so login + mobile/tablet
   are unaffected. Width-only (height unchanged).
   ═══════════════════════════════════════════════ */
@media (min-width: 1025px) {
  body.app-shell { background: #fff; }            /* 1/5 side margins white */

  body.app-shell .main {
    width: 60%;                                    /* 3/5 centered */
    max-width: 1280px;                             /* reading cap on large monitors */
    margin: 16px auto 0;                           /* horizontally centered + gap for the radius */
    background: var(--bg-page);                    /* centre column stays grey (#f1f5f9) */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;  /* soft top corners */
    box-shadow: var(--shadow-sm);                  /* subtle "sheet" shadow */
    min-height: calc(100vh - 56px - 16px);         /* 56px topnav + 16px top margin */
  }

  /* Wide / many-column tables (e.g. meter list in edit mode) must scroll
     horizontally inside their card instead of being clipped by the narrow
     centered column. Mirrors the tablet/mobile escape valve above; the base
     `.table-card { overflow: hidden }` keeps overflow-y hidden so the rounded
     corners survive. */
  body.app-shell .table-card { overflow-x: auto; }
}

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
@keyframes modal-shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-8px); }
  40%     { transform: translateX(8px); }
  60%     { transform: translateX(-5px); }
  80%     { transform: translateX(5px); }
}
.modal.is-shaking { animation: modal-shake 0.35s ease; }

/* New structured modal */
@keyframes modalIn {
  from { opacity: 0; transform: scale(.97) translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.06);
  width: 100%; max-width: 540px;
  max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column;
  animation: modalIn .18s cubic-bezier(.16,1,.3,1);
}
.modal.modal-lg  { max-width: 720px; }
.modal.modal-xl  { max-width: 900px; }
.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-default);
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 12px;
  flex-shrink: 0;
}
.modal-title    { font-size: 16px; font-weight: 700; color: var(--text-primary); letter-spacing: -.3px; }
.modal-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.modal-close {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-default); background: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-faint);
  font-size: 14px; line-height: 1; flex-shrink: 0;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-surface-2); color: var(--text-secondary); border-color: var(--border-strong); }
.modal > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.modal-body   { padding: 18px 22px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer {
  padding: 12px 22px; border-top: 1px solid var(--border-default);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--bg-surface-2); flex-shrink: 0;
}
/* ── Dropdowns ── */
.dropdown-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 30px rgba(0,0,0,.12), 0 0 0 1px rgba(0,0,0,.04);
  padding: 6px; min-width: 180px;
}
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-secondary); font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background var(--transition);
}
.dropdown-item:hover { background: var(--bg-surface-2); color: var(--text-primary); text-decoration: none; }
.dropdown-item.danger { color: var(--color-red); }
.dropdown-item.danger:hover { background: var(--color-red-dim); }
.dropdown-item svg { width: 15px; height: 15px; color: var(--text-faint); flex-shrink: 0; }
.dropdown-sep  { height: 1px; background: var(--border-default); margin: 4px 0; }

/* ── Data Cards (Stammdaten-Ansichten) ── */
.data-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.data-card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 16px; border-bottom: 1px solid var(--border-default);
  background: var(--bg-surface-2);
}
.data-card-icon {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--color-primary-dim);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.data-card-icon svg { width: 13px; height: 13px; color: var(--color-primary); }
.data-card-title    { font-size: 12px; font-weight: 700; color: var(--text-primary); letter-spacing: -.1px; }
.data-card-subtitle { font-size: 10px; color: var(--text-muted); margin-top: 1px; }
.data-card-body     { padding: 0; }
.data-row {
  display: grid; grid-template-columns: 44% 56%;
  align-items: center; padding: 8px 16px;
  border-bottom: 1px solid var(--border-default); gap: 8px;
  transition: background var(--transition);
}
.data-row:last-child { border-bottom: none; }
.data-row:hover      { background: var(--bg-surface-2); }
.data-row-label {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.data-row-value {
  font-size: 12px; color: var(--text-primary); font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.data-row-value.muted { color: var(--text-faint); font-weight: 400; }
.feature-tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 12px; border-top: 1px solid var(--border-default); }
.feature-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600;
  background: var(--color-primary-dim); color: var(--color-primary);
  border: 1px solid var(--color-primary-border);
}
.feature-tag svg { width: 11px; height: 11px; }
.feature-tag.inactive {
  background: var(--bg-surface-2); color: var(--text-faint);
  border-color: var(--border-default); font-weight: 400; opacity: .6;
}
.stamm-grid      { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stamm-grid-wide { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

/* ── Compact form layout (unit edit modal A+B) ── */
input.compact, select.compact    { height: 28px; font-size: 12px; padding: 0 8px; }
input.compact-year               { height: 28px; font-size: 12px; padding: 0 8px; max-width: 90px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.form-inspector {
  display: flex; flex-direction: column;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); overflow: hidden;
  margin-bottom: 4px;
}
.form-inspector-row {
  display: grid; grid-template-columns: 120px 1fr;
  align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.form-inspector-row:last-child { border-bottom: none; }
.form-inspector-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.check-dense   { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; }
.check-dense-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.check-dense-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-secondary); padding: 4px 6px;
  border-radius: var(--radius-sm);
}
.check-dense-item:hover { background: var(--bg-surface-2); }
.check-dense-item input[type=checkbox] { width: 13px; height: 13px; accent-color: var(--color-primary); cursor: pointer; }
.check-dense-item label { cursor: pointer; margin: 0; font-size: 11px; font-weight: 400; color: var(--text-secondary); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.form-col .form-group {
  margin-bottom: 0;
}

/* ── Ablesen inline row ───────────────────────────── */
.btn-ablesen {
  background: var(--color-primary-dim);
  color: var(--color-primary);
  border: 1px solid var(--color-primary-border);
  font-size: 12px;
  padding: 5px 11px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  line-height: 1;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-ablesen.open {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary-btn-border);
}
/* Higher specificity than `tbody tr:last-child td` so border survives */
.table-card tr.ablesen-row td {
  background: #f0fafa;
  border-top: 1px solid var(--color-primary-border);
  border-bottom: 2px solid var(--color-primary-border);
  padding: 12px 14px;
  vertical-align: middle;
}
tr.ablesen-row td:first-child { font-weight: 400; color: var(--text-secondary); }

.ablesen-fields { display: flex; align-items: center; gap: 16px; flex-wrap: nowrap; }
.ablesen-field-group { display: flex; align-items: center; gap: 6px; }
.ablesen-divider { width: 1px; height: 22px; background: var(--border-default); flex-shrink: 0; }
.ablesen-unit { font-size: 12px; color: var(--text-muted); }
.ablesen-hint { font-size: 11px; color: var(--text-faint); margin-top: 5px; }
.ablesen-error { font-size: 12px; color: var(--color-red); margin-top: 4px; }

.ablesen-toggle { display: flex; gap: 4px; margin-bottom: 8px; }
.ablesen-toggle .toggle-btn {
  padding: 4px 12px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
}
.ablesen-toggle .toggle-btn.active {
  background: var(--color-primary-dim);
  color: var(--color-primary);
  border-color: var(--color-primary-border);
}

/* ── Global HTMX loading indicator ── */
#global-htmx-indicator { display: none; position: fixed; bottom: 16px; right: 16px; background: var(--color-primary, #2563eb); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 9998; }
#global-htmx-indicator.htmx-request { display: block; }

/* -- Cross-building meter overview ------------------------------------- */
.ov-table th.ov-th { position: relative; cursor: pointer; user-select: none; white-space: nowrap; }
.ov-table th.ov-th.sorted { color: var(--color-primary); }
.ov-th .ov-ar { font-size: 9px; color: var(--text-muted); margin-left: 4px; }
.ov-th.sorted .ov-ar { color: var(--color-primary); }
.ov-th .ov-fdot { display:inline-block; width:6px; height:6px; border-radius:50%;
  background: var(--color-primary); margin-left:5px; vertical-align:middle; }
.ov-pop { display:none; position:absolute; top:100%; left:6px; z-index:30; width:220px;
  background:#fff; border:1px solid var(--border-default); border-radius:8px;
  box-shadow:0 10px 30px rgba(15,23,42,.16); padding:6px; font-weight:400;
  max-height:320px; overflow:auto; }
.ov-th.open .ov-pop { display:block; }
.ov-pop .ov-it { display:block; width:100%; text-align:left; background:none; border:none;
  padding:6px 8px; border-radius:6px; font-size:12px; color:var(--text-default); cursor:pointer; }
.ov-pop .ov-it:hover { background: var(--bg-surface-2); }
.ov-pop .ov-sep { height:1px; background:var(--border-default); margin:5px 2px; }
.ov-pop .ov-lbl { font-size:10px; text-transform:uppercase; letter-spacing:.04em;
  color:var(--text-muted); padding:2px 8px; }
.ov-pop .ov-search { width:100%; box-sizing:border-box; font-size:11.5px; padding:5px 7px;
  border:1px solid var(--border-default); border-radius:6px; margin:3px 0 4px; }
.ov-pop .ov-chk { display:flex; align-items:center; gap:7px; padding:4px 8px;
  font-size:12px; color:var(--text-default); cursor:pointer; }
.ov-col-new { background:#e6f7f5; }
.ov-table th.ov-col-new { background:#d1f0ec; color:#0f766e; }

/* ──────────────────────────────────────────────────────────────
   Legal pages (Impressum / Datenschutz) — editorial reading layout
   ────────────────────────────────────────────────────────────── */
.legal { max-width: 1000px; margin: 0 auto; width: 100%; }

.legal-hero {
  position: relative;
  padding: 8px 0 28px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border-default);
}
.legal-hero::before {
  content: ""; position: absolute; left: 0; top: 14px;
  width: 36px; height: 3px; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-dark));
}
.legal-back {
  display: inline-block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 22px;
}
.legal-back::before { content: "← "; }
.legal-back:hover { color: var(--color-primary); text-decoration: none; }
.legal-eyebrow {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .14em; color: var(--color-primary); margin-bottom: 10px;
}
.legal-title {
  font-size: 34px; font-weight: 800; letter-spacing: -.6px;
  line-height: 1.1; color: var(--text-primary);
}
.legal-lede {
  margin-top: 12px; max-width: 60ch;
  font-size: 15px; line-height: 1.6; color: var(--text-muted);
}

.legal-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 56px;
  align-items: start;
}

/* Sticky section index */
.legal-toc { position: sticky; top: 80px; }
.legal-toc-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-faint); margin-bottom: 12px;
}
.legal-toc ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.legal-toc a {
  display: block; padding: 5px 12px; font-size: 13px;
  color: var(--text-muted); border-left: 2px solid var(--border-default);
  transition: all var(--transition);
}
.legal-toc a:hover {
  color: var(--color-primary); border-left-color: var(--color-primary);
  background: var(--color-primary-dim); text-decoration: none;
}

/* Readable body column */
.legal-body { font-size: 14.5px; line-height: 1.72; color: var(--text-secondary); }
.legal-body section { scroll-margin-top: 76px; padding-bottom: 36px; }
.legal-body section + section { border-top: 1px solid var(--border-subtle); padding-top: 36px; }
.legal-body h2 {
  font-size: 19px; font-weight: 700; letter-spacing: -.2px;
  color: var(--text-primary); margin-bottom: 16px; line-height: 1.3;
}
.legal-body p { margin-bottom: 14px; }
.legal-body p:last-child { margin-bottom: 0; }
.legal-body a { color: var(--color-primary); font-weight: 500; word-break: break-word; }

.legal-dl {
  display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  gap: 8px 24px; margin: 4px 0 16px;
}
.legal-dl dt { font-weight: 600; color: var(--text-muted); }
.legal-dl dd { color: var(--text-primary); }

.legal-list { margin: 4px 0 16px; padding-left: 0; list-style: none; }
.legal-list li { position: relative; padding-left: 22px; margin-bottom: 8px; }
.legal-list li::before {
  content: ""; position: absolute; left: 4px; top: .62em;
  width: 6px; height: 6px; border-radius: var(--radius-full);
  background: var(--color-primary);
}

/* Operator-facing placeholders — deliberately conspicuous until filled in */
.legal-ph {
  background: #fef3c7; color: #92400e;
  font-weight: 600; font-style: normal;
  padding: 1px 7px; border-radius: var(--radius-sm);
  border: 1px dashed #f59e0b; overflow-wrap: anywhere;
}

.legal-note {
  font-size: 12.5px; line-height: 1.55; color: var(--text-muted);
  background: var(--bg-surface-2); border: 1px solid var(--border-default);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-sm); padding: 10px 14px; margin: 14px 0 0;
}
.legal-updated { font-size: 13px; color: var(--text-faint); margin-top: 8px; }

/* ── Site footer (always visible, incl. login screen) ── */
.site-footer { border-top: 1px solid var(--border-default); background: var(--bg-surface); }
.site-footer-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 18px 28px; display: flex; flex-wrap: wrap; gap: 12px 24px;
  align-items: center; justify-content: space-between;
}
.site-footer-brand { font-size: 13px; font-weight: 700; color: var(--text-muted); letter-spacing: -.2px; }
.site-footer-brand span { color: var(--color-primary); }
.site-footer-nav { display: flex; gap: 22px; }
.site-footer-nav a { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.site-footer-nav a:hover { color: var(--color-primary); text-decoration: none; }

@media (max-width: 880px) {
  .legal-title { font-size: 27px; }
  .legal-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .legal-toc, .legal-body { min-width: 0; }
  .legal-toc {
    position: static; margin-bottom: 28px; padding-bottom: 24px;
    border-bottom: 1px solid var(--border-default);
  }
  .legal-toc ul { flex-flow: row wrap; gap: 6px; }
  .legal-toc a { border-left: none; border: 1px solid var(--border-default); border-radius: var(--radius-full); }
  .legal-dl { grid-template-columns: 1fr; gap: 2px; }
  .legal-dl dt { margin-top: 10px; }
  .site-footer-inner { padding: 16px; justify-content: center; }
}

