/* ═══════════════════════════════════════════════════════════
   FORMFOLIO – Globale Styles
   ═══════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #d1d5db;
  --border-focus: #2563eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.06);
  --danger: #dc2626;
  --danger-light: rgba(239, 68, 68, 0.08);
  --success: #16a34a;
  --success-light: rgba(34, 197, 94, 0.1);
  --warning: #d97706;
  --warning-light: #fef3c7;
  --navy: #0e2841;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --readonly-bg: #f0f0f0;
}

body {
  font-family: 'Calibri', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Loading ── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.9);
  display: none; align-items: center; justify-content: center;
  z-index: 9999; flex-direction: column; gap: 12px;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-weight: 600; color: var(--text-muted); }

/* ── Navbar ── */
.navbar {
  background: #2e4652;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  position: relative;
  position: sticky; top: 0; z-index: 100;
}
.navbar-logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  min-height: 36px;
  z-index: 2;
  position: relative;
}
.sidebar-open-btn {
  display: none;
  border: none;
  background: transparent;
  color: #fff;
  border-radius: 6px;
  width: 40px;
  height: 40px;
  margin-right: 10px;
  cursor: pointer;
  z-index: 2;
  font-size: 18px;
  align-items: center;
  justify-content: center;
}
.navbar-logo {
  width: 200px;
  height: 45px;
  object-fit: contain;
}
.navbar-logo-fallback {
  font-weight: 700;
  letter-spacing: .3px;
  color: #fff;
}
.navbar-center-title {
  position: absolute;
  left: 230px;
  right: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  pointer-events: none;
}
.navbar-user {
  font-size: 12px;
  color: #dbe7ed;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  gap: 10px;
  z-index: 2;
  position: relative;
}
.navbar-logout-link {
  color: #dbe7ed;
  font-size: 12px;
  text-decoration: none;
}
.navbar-logout-link:hover { color: #fff; }

/* ── App Shell ── */
.app-shell {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 56px);
  transition: grid-template-columns .2s ease;
}
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: width .2s ease, padding .2s ease;
}
.sidebar-foot {
  display: flex;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: var(--surface);
  z-index: 1;
  padding-top: 10px;
  margin-top: auto;
  border-top: 1px solid var(--border);
}
.sidebar-collapse-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 6px;
  min-height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 2;
  cursor: pointer;
}

/* Wenn die untere Submit-Leiste existiert, Button darueber anheben */
.app-shell:has(.submit-bar) .sidebar-foot {
  bottom: 76px;
  z-index: 120;
}

.app-shell:has(.submit-bar) .sidebar-collapse-btn {
  z-index: 121;
}
.sidebar-collapse-icon {
  width: 14px;
  display: inline-flex;
  justify-content: center;
}
.sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 7px;
  transition: all .15s;
}
.sidebar-icon {
  width: 18px;
  display: inline-flex;
  justify-content: center;
}
.sidebar-links a:hover { background: var(--bg); color: var(--text); }
.sidebar-links a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.app-content {
  min-width: 0;
  padding: 20px 18px 86px;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 72px minmax(0, 1fr);
}
body.sidebar-collapsed .navbar-center-title {
  left: 72px;
}
body.sidebar-collapsed .sidebar {
  padding: 14px 8px;
}
body.sidebar-collapsed .sidebar-foot {
  justify-content: center;
}
body.sidebar-collapsed .sidebar-links a {
  justify-content: center;
  gap: 0;
  padding: 10px 8px;
}
body.sidebar-collapsed .sidebar-links a span:last-child {
  display: none;
}
body.sidebar-collapsed .sidebar-collapse-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  justify-content: center;
}
body.sidebar-collapsed .sidebar-collapse-btn .sidebar-collapse-text {
  display: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 210;
}
body.sidebar-open .sidebar-backdrop { display: block; }

/* ── Seiten-Header (Full-Width innerhalb app-content, vor dem Grid) ── */
.page-header-bar {
  text-align: center;
  padding: 16px 24px 12px;
  margin: -20px -18px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.page-header-bar h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 2px;
}
.page-header-bar p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 4px;
}

/* ── Seiten-Header (alt, nur noch Fallback) ── */
.app-header { text-align: center; padding: 20px 0 16px; }
.app-header h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; margin: 0 0 4px; }
.app-header p { color: var(--text-muted); font-size: 14px; }

/* ── Zweispaltiges Form-Layout (BAU / INV / Admin) ── */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 100px;
  align-items: start;
}
.main-form {
  min-width: 0;
  max-width: 1020px;
  margin: 0 auto;
  width: 100%;
}
.right-col {
  position: sticky;
  top: 80px;
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; padding-bottom: 100px; }
  .right-col { position: static; }
}

/* ── Right-Col Overlay (schmale Screens) ── */
.right-col-toggle {
  display: none;
  position: fixed;
  top: 10px;
  right: 16px;
  z-index: 201;
  background: #2e4652;
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  align-items: center;
  justify-content: center;
}
.right-col-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 202;
}
.right-col-backdrop.rc-open { display: block; }
@media (max-width: 1150px) {
  .right-col-toggle {
    display: flex;
    top: 10px;
  }
  .app-layout { grid-template-columns: 1fr; }
  .right-col {
    display: none;
    position: fixed;
    top: 56px;
    right: 0;
    width: 360px;
    max-width: 92vw;
    height: calc(100vh - 56px);
    max-height: none;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 24px rgba(0,0,0,0.15);
    z-index: 203;
    overflow-y: auto;
    padding: 12px;
  }
  .right-col.rc-open { display: block; }
  .right-col-close {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }
  .right-col-close button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0;
  }
}

@media (min-width: 641px) and (max-width: 1150px) {
  .navbar-user {
    padding-right: 52px;
  }
}

@media (max-width: 1200px) {
  body.sidebar-collapsed .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }
  body.sidebar-collapsed .navbar-center-title {
    left: 72px;
  }
  body.sidebar-collapsed .sidebar {
    padding: 14px 8px;
  }
}

/* ── Dashboard ── */
.dashboard {
  max-width: 900px; margin: 0 auto; padding: 0 16px;
}
.doc-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px; text-align: left;
}
.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px; cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  text-decoration: none; color: inherit;
  display: block;
}
.doc-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.doc-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.doc-card .icon { font-size: 26px; line-height: 1; }
.doc-card h2 { font-size: 18px; font-weight: 700; margin: 0; }
.doc-card p { font-size: 13px; color: var(--text-muted); }

/* ── Card (generisch) ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 15px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.card-title .icon { font-size: 18px; }

/* ── Form Elemente ── */
.form-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 12px;
}
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.form-row.full { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; }
.form-group label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 4px;
}
.form-group input, .form-group select, .form-group textarea {
  font-family: inherit; font-size: 14px;
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface);
  color: var(--text); transition: border-color 0.15s;
  outline: none; width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Globaler blauer Fokus für alle Eingabefelder */
input:focus, select:focus, textarea:focus {
  border-color: var(--primary) !important;
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-group input[readonly] {
  background: var(--readonly-bg); color: #374151; cursor: default;
}
.form-group textarea { resize: vertical; min-height: 60px; }

/* ── Buttons ── */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 20px; border-radius: 6px; border: none;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn-outline {
  background: var(--surface); color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-danger-ghost {
  background: transparent; color: var(--danger);
  border: none; padding: 6px 10px; font-size: 13px;
}
.btn-danger-ghost:hover { background: var(--danger-light); border-radius: 4px; }
.btn-sm { font-size: 12px; padding: 6px 12px; }

/* ── Submit Bar ── */
.submit-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 14px 24px; display: flex; justify-content: center;
  gap: 12px; box-shadow: 0 -2px 8px rgba(0,0,0,0.06); z-index: 100;
}
.submit-bar .btn { min-width: 200px; justify-content: center; }

/* ── Toast ── */
.toast {
  position: fixed; top: 20px; right: 20px;
  padding: 14px 20px; border-radius: var(--radius);
  font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow-lg); z-index: 9999;
  display: none; animation: slideIn 0.3s ease;
}
.toast.show { display: block; }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.loading { background: var(--primary); color: #fff; }
@keyframes slideIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Setup Wizard ── */
.setup-container {
  max-width: 600px; margin: 80px auto; padding: 0 24px;
}
.setup-container h1 { font-size: 28px; margin-bottom: 8px; text-align: center; }
.setup-container .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 32px; }
.setup-step { margin-bottom: 24px; }
.setup-step h3 { font-size: 16px; margin-bottom: 12px; }
.setup-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

/* ── Admin ── */
.admin-container {
  max-width: 1020px;
  margin: 0 auto;
}
.admin-container h1 {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  padding: 20px 0 16px;
  margin: 0 0 8px;
}
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; text-align: center;
}
.stat-card .stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .form-row, .form-row.three { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  .navbar {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .navbar-center-title {
    position: static;
    width: 100%;
    text-align: center;
    font-size: 17px;
    pointer-events: auto;
  }
  .navbar-user { justify-content: flex-start; }
  .sidebar-open-btn { display: inline-flex; align-items: center; justify-content: center; }
  .app-shell { grid-template-columns: 1fr !important; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    width: 230px;
    max-width: 80vw;
    height: calc(100vh - 56px);
    border-right: 1px solid var(--border);
    border-bottom: none;
    transform: translateX(-100%);
    z-index: 211;
    box-shadow: 0 10px 30px rgba(0,0,0,.2);
    transition: transform .2s ease;
    overflow-y: auto;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-foot { display: none; }
  .sidebar-links { flex-direction: column; }
  .sidebar-links a { justify-content: flex-start; gap: 8px; }
  .sidebar-links a span:last-child { display: inline; }
  .app-content { padding: 14px 10px 86px; }
}
