/* LizenzManager – App Styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ——— Default theme (dark) – overridden by PHP-injected :root vars ——— */
:root {
  --bg: #0f1117;
  --surface: #181c27;
  --surface2: #1e2233;
  --surface3: #242840;
  --border: #2a2f45;
  --border2: #353b56;
  --accent: #4f8ef7;
  --accent-hover: #3b7de8;
  --accent2: #7c3aed;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --text: #e8eaf0;
  --text2: #a8b0c0;
  --muted: #6b7280;
  --serif: 'DM Serif Display', serif;
  --sans: 'DM Sans', sans-serif;
  --sidebar-w: 240px;
  --radius: 12px;
  --font-size-base: 15px;
}

/* ——— Light theme ——— */
html.theme-light {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface2: #f0f2f7;
  --surface3: #e8ecf3;
  --border: #dde1ea;
  --border2: #c8cedb;
  --text: #1a1f2e;
  --text2: #4a5368;
  --muted: #7b8299;
}
html.theme-light .nav-item:hover { background: var(--surface2); }
html.theme-light .nav-item.active { background: rgba(79,142,247,.1); }
html.theme-light tbody tr:hover { background: var(--surface2); }
html.theme-light .modal-overlay { background: rgba(0,0,0,.4); }
html.theme-light .badge-gray { background: rgba(107,114,128,.1); color: #555e75; }

/* ——— Soft theme ——— */
html.theme-soft {
  --bg: #eef2f8;
  --surface: #f8fafd;
  --surface2: #eaeff8;
  --surface3: #dce4f2;
  --border: #cdd5e8;
  --border2: #b8c3d8;
  --text: #1e2540;
  --text2: #4d5a7a;
  --muted: #7e8fb0;
}

body {
  font-family: var(--sans);
  font-size: var(--font-size-base, 15px);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
}

/* ——— Sidebar ——— */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}

.sidebar-brand {
  padding: 24px 20px 20px;
  font-family: var(--serif);
  font-size: 1.4rem;
  letter-spacing: -0.3px;
  border-bottom: 1px solid var(--border);
}
.brand-serif { color: var(--text); }
.brand-accent { color: var(--accent); }

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text2);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,142,247,.12); color: var(--accent); }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--text); }
.user-name { font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .72rem; color: var(--muted); }
.logout-btn { color: var(--muted); transition: .15s; }
.logout-btn:hover { color: var(--red); }

/* ——— Main Content ——— */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}
.page-title { font-family: var(--serif); font-size: 1.9rem; letter-spacing: -0.5px; }
.page-subtitle { color: var(--muted); font-size: .875rem; margin-top: 4px; }

/* ——— Cards ——— */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent-color, var(--accent));
}
.stat-icon { font-size: 1.5rem; margin-bottom: 12px; }
.stat-value { font-size: 2rem; font-weight: 700; font-family: var(--serif); line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ——— Table ——— */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 14px 16px;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

/* ——— Badges ——— */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: rgba(34,197,94,.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,.15); color: var(--red); }
.badge-amber { background: rgba(245,158,11,.15); color: var(--amber); }
.badge-blue { background: rgba(79,142,247,.15); color: var(--accent); }
.badge-gray { background: rgba(107,114,128,.15); color: var(--muted); }

/* ——— Buttons ——— */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-ghost { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface3); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-icon { padding: 7px; border-radius: 7px; }

/* ——— Forms ——— */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.full { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.field input,
.field select,
.field textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--sans);
  font-size: .875rem;
  outline: none;
  transition: .2s;
  width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,142,247,.12);
}
.field textarea { resize: vertical; min-height: 90px; }
.field small { font-size: .75rem; color: var(--muted); }

.section-divider {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin: 24px 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ——— Flash messages ——— */
.flash {
  padding: 13px 18px;
  border-radius: 10px;
  font-size: .875rem;
  margin-bottom: 20px;
}
.flash-success { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3); color: #86efac; }
.flash-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
.flash-info { background: rgba(79,142,247,.1); border: 1px solid rgba(79,142,247,.3); color: #93c5fd; }

/* ——— Alerts ——— */
.alert { padding: 13px 16px; border-radius: 9px; font-size: .85rem; margin-bottom: 16px; }
.alert-warn { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3); color: #fcd34d; }
.alert-danger { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }

/* ——— Search & Filter bar ——— */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search-wrap input { padding-left: 38px; }

/* ——— Progress bar ——— */
.progress { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 3px; transition: width .4s; }

/* ——— Empty state ——— */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h3 { font-family: var(--serif); font-size: 1.2rem; color: var(--text2); margin-bottom: 6px; }

/* ——— Detail page ——— */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: .8rem; color: var(--muted); }
.detail-value { font-size: .9rem; font-weight: 500; }

/* ——— Modal ——— */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: none;
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
}
.modal h3 { font-family: var(--serif); font-size: 1.4rem; margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: .875rem; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ——— Mobile topbar: hidden by default, shown on small screens ——— */
.mobile-topbar { display: none; }

/* ——— Responsive 2-col grids ——— */
.responsive-grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 680px) {
  .responsive-grid-2-1 { grid-template-columns: 1fr; }
}

/* ——— Touch-friendly sizing ——— */
@media (max-width: 680px) {
  /* Larger touch targets for buttons */
  .btn { min-height: 42px; }
  .btn-sm { min-height: 34px; }
  .btn-icon { min-width: 34px; min-height: 34px; }

  /* Bigger form inputs */
  .field input,
  .field select,
  .field textarea { padding: 12px 14px; font-size: 1rem; }

  /* Bigger nav items for tap */
  .nav-item { padding: 13px 14px; font-size: .9rem; }

  /* Sidebar wider on small screens */
  .sidebar { width: min(280px, 85vw); }

  /* Progress bars and labels */
  .stat-label { font-size: .72rem; }

  /* Card table-like 2-col layout for report tables */
  .reports-table td[data-label]::before { min-width: 110px; }
}

/* ——— Tablet (≤ 900px) ——— */
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid.cols-3 { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ——— Mobile (≤ 680px) ——— */
@media (max-width: 680px) {

  /* Sidebar: hidden off-canvas, slides in */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    z-index: 300;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }

  /* Overlay behind open sidebar */
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 299;
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.open { display: block; }

  /* Main content full width, space for top bar */
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: 72px; /* room for mobile topbar */
  }

  /* ——— Mobile top bar ——— */
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    z-index: 200;
  }
  .mobile-topbar .topbar-brand {
    font-family: var(--serif);
    font-size: 1.15rem;
  }
  .mobile-topbar .topbar-brand span { color: var(--accent); }

  /* Hamburger button */
  .hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px; height: 36px;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    transition: background .15s;
  }
  .hamburger:hover { background: var(--surface2); }
  .hamburger span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: .25s;
  }
  .hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .hamburger.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
  .hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* Page header stacks on mobile */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
  }
  .page-header .btn { width: 100%; justify-content: center; }

  /* Grids collapse to single column */
  .form-grid,
  .form-grid.cols-3 { grid-template-columns: 1fr; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 1.6rem; }

  /* Cards less padding */
  .card { padding: 16px; }

  /* ——— Responsive tables: card-style on mobile ——— */
  .table-wrap { overflow-x: unset; }
  table, thead, tbody, th, td, tr { display: block; }

  thead tr { display: none; } /* hide header row */

  tbody tr {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 12px 14px;
  }
  tbody tr:hover { background: var(--surface3); }
  tbody tr:last-child td { border-bottom: none; }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
    gap: 10px;
  }
  tbody td:last-child { border-bottom: none; padding-bottom: 0; }
  tbody td:first-child { padding-top: 0; }

  /* Add label via data-label attribute */
  tbody td[data-label]::before {
    content: attr(data-label);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    flex-shrink: 0;
    min-width: 90px;
  }

  /* Action buttons cell: full width row */
  tbody td.td-actions {
    justify-content: flex-end;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
    border-bottom: none;
  }

  /* Toolbar stacks */
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: 0; }
  .toolbar select { width: 100%; }

  /* Detail page */
  .detail-grid { grid-template-columns: 1fr; }
  .detail-row { flex-wrap: wrap; gap: 4px; }
  .detail-value { text-align: right; }

  /* Modal full screen on mobile */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    padding: 24px 20px 32px;
  }

  /* Page title smaller */
  .page-title { font-size: 1.5rem; }

  /* Users / categories 2-col grid → stacked */
  [style*="grid-template-columns:2fr 1fr"] {
    display: flex !important;
    flex-direction: column;
  }

  /* Section tabs wrap */
  [style*="display:flex;gap:4px;margin-bottom:24px"] {
    flex-wrap: wrap;
  }

  /* Stat grid buttons full width */
  .btn-primary, .btn-ghost { white-space: nowrap; }
}

/* ——— Very small (≤ 380px) ——— */
@media (max-width: 380px) {
  .main-content { padding: 12px; padding-top: 70px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 1.4rem; }
  .page-title { font-size: 1.3rem; }
}
