/* ============================================================
   Operix Design-System v2 — operix-new.css
   ============================================================ */

:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #eff6ff;
  --success:        #16a34a;
  --success-light:  #dcfce7;
  --warning:        #d97706;
  --warning-light:  #fef3c7;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --info:           #0284c7;
  --info-light:     #e0f2fe;

  --bg:             #f4f6fa;
  --bg-card:        #ffffff;
  --border:         #e5e7eb;
  --text:           #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;

  --sidebar-w:      220px;
  --topbar-h:       54px;
  --radius:         10px;
  --radius-sm:      6px;
  --shadow:         0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:      0 4px 24px rgba(0,0,0,.12);

  /* Brand-Color (dynamisch via JS) */
  --brand-color:    #2563eb;
}

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

html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── App-Wrapper ────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: #1e293b;
  color: #f1f5f9;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1.25rem;
  z-index: 1100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.topbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
  white-space: nowrap;
  text-decoration: none;
}
.topbar-brand:hover { text-decoration: none; color: #93c5fd; }

.topbar-divider {
  width: 1px;
  height: 22px;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}

.topbar-title {
  font-size: .95rem;
  font-weight: 600;
  color: #e2e8f0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-left: auto;
}

.topbar-user {
  font-size: .78rem;
  color: #94a3b8;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.topbar-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: .3rem .5rem;
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  line-height: 1;
  transition: background .15s, color .15s;
  display: none;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ── App-Body (Sidebar + Main) ──────────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  transition: transform .25s ease;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 999;
}
.sidebar-overlay.visible { display: block; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0 1rem;
  scroll-behavior: smooth;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }

.nav-section { margin-bottom: .25rem; }

.nav-section-title {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  padding: .7rem 1rem .3rem;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .52rem 1rem;
  color: var(--text-secondary);
  font-size: .82rem;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-item:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.nav-item.active svg { opacity: 1; }

.nav-sub-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .42rem 1rem .42rem 2.4rem;
  color: var(--text-secondary);
  font-size: .79rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s;
}
.nav-sub-item:hover { background: #f9fafb; color: var(--primary); text-decoration: none; }
.nav-sub-item.active { color: var(--primary); font-weight: 600; background: var(--primary-light); border-left-color: var(--primary); }

.nav-badge {
  margin-left: auto;
  font-size: .68rem;
  font-weight: 700;
  padding: .05rem .4rem;
  border-radius: 999px;
  min-width: 1.2rem;
  text-align: center;
  line-height: 1.5;
}
.nav-badge-red   { background: #fee2e2; color: #dc2626; }
.nav-badge-green { background: #dcfce7; color: #16a34a; }
.nav-badge-blue  { background: #dbeafe; color: #2563eb; }

/* Collapsible-Subgruppen */
.nav-collapsible { display: flex; align-items: center; user-select: none; }
.nav-chevron {
  margin-left: auto;
  width: 1rem; height: 1rem;
  flex-shrink: 0;
  transition: transform .2s ease;
  border-radius: .25rem;
  color: var(--text-muted);
}
.nav-chevron:hover { background: rgba(0,0,0,.06); }
.nav-collapsible.open .nav-chevron { transform: rotate(90deg); }
.nav-sub-group { max-height: 0; overflow: hidden; transition: max-height .25s ease-out; }
.nav-sub-group.open { max-height: 500px; transition: max-height .35s ease-in; }

/* Sidebar-Footer */
.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: #f9fafb;
}
.user-info { display: flex; align-items: center; gap: .6rem; }
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-details { min-width: 0; }
.user-name { font-size: .78rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Main Content ───────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content-area {
  flex: 1;
  padding: 1.5rem;
  max-width: 100%;
}

/* ── Flash-Messages ─────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  border-left: 4px solid;
}
.alert-success { background: var(--success-light); color: #14532d; border-color: var(--success); }
.alert-danger, .alert-error { background: var(--danger-light); color: #7f1d1d; border-color: var(--danger); }
.alert-warning { background: var(--warning-light); color: #78350f; border-color: var(--warning); }
.alert-info { background: var(--info-light); color: #0c4a6e; border-color: var(--info); }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}
.card-header {
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}
.card-body { padding: 1.25rem; }
.card-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border); background: #f9fafb; border-radius: 0 0 var(--radius) var(--radius); }

/* ── Page-Header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header-left h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}
.page-header-left p {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-top: .2rem;
}
.page-header-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .48rem .9rem;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .15s;
  line-height: 1.4;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #15803d; color: #fff; }

.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-warning   { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #b45309; color: #fff; }

.btn-secondary { background: #fff; color: var(--text-secondary); border-color: var(--border); }
.btn-secondary:hover { background: #f9fafb; color: var(--text); border-color: #d1d5db; }

.btn-ghost     { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

.btn-sm { padding: .3rem .65rem; font-size: .75rem; }
.btn-lg { padding: .65rem 1.25rem; font-size: .9rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 600; color: var(--text); margin-bottom: .35rem; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: .52rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
  line-height: 1.5;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-input::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 90px; }

.form-hint { font-size: .73rem; color: var(--text-muted); margin-top: .25rem; }
.form-error { font-size: .73rem; color: var(--danger); margin-top: .25rem; }

.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
.table-container { overflow-x: auto; }

table, .table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
table thead th, .table thead th {
  background: #f9fafb;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .65rem .9rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  text-align: left;
}
table tbody td, .table tbody td {
  padding: .65rem .9rem;
  border-bottom: 1px solid #f3f4f6;
  color: var(--text);
  vertical-align: middle;
}
table tbody tr:last-child td, .table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover td, .table tbody tr:hover td { background: #f9fafb; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-success { background: var(--success-light); color: #14532d; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-danger  { background: var(--danger-light);  color: #7f1d1d; }
.badge-info    { background: var(--info-light);    color: #0c4a6e; }
.badge-gray    { background: #f3f4f6; color: #6b7280; }
.badge-blue    { background: var(--primary-light); color: var(--primary-dark); }

/* ── Stats-Grid ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .35rem;
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-lg); }

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}
.stat-label { font-size: .75rem; color: var(--text-secondary); font-weight: 500; }

.stat-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 18px; height: 18px; }
.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.modal-title { font-size: .95rem; font-weight: 700; flex: 1; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* ── Utilities ──────────────────────────────────────────── */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: .75rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Login-Page ─────────────────────────────────────────── */
.login-page {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 60%, #1e3a5f 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 400px;
}
.login-header { text-align: center; margin-bottom: 2rem; }
.login-logo {
  width: 60px; height: 60px;
  background: var(--primary-light);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}
.login-logo svg { width: 32px; height: 32px; color: var(--primary); }
.login-title { font-size: 1.6rem; font-weight: 800; color: var(--text); letter-spacing: -.5px; }
.login-subtitle { font-size: .83rem; color: var(--text-secondary); margin-top: .35rem; }

/* ── Bottom-Nav (Mobile) ────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 1050;
  padding: .3rem 0 .5rem;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  color: var(--text-secondary);
  font-size: .62rem;
  font-weight: 500;
  padding: .35rem .5rem;
  text-decoration: none;
  flex: 1;
  border-radius: var(--radius-sm);
  transition: color .15s;
}
.bottom-nav a svg { width: 20px; height: 20px; }
.bottom-nav a.active, .bottom-nav a:hover { color: var(--primary); text-decoration: none; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: flex; }

  .form-grid   { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-grid-4 { grid-template-columns: 1fr 1fr; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .content-area { padding: 1rem; }

  .bottom-nav {
    display: flex;
    justify-content: space-around;
  }
  .content-area { padding-bottom: calc(3.5rem + env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .page-header-right { width: 100%; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .content-area { padding: 1.1rem; }
}
