/* ===== CSS Variables ===== */
:root {
  --bg: #f4f5f7;
  --bg2: #ffffff;
  --text: #1a1a2e;
  --text-muted: #555;
  --border: #dde1e8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.08);
  --nav-bg: #1e293b;
  --nav-text: #e2e8f0;
}
html.dark {
  --bg: #0f172a;
  --bg2: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 4px rgba(0,0,0,.3);
  --nav-bg: #0f172a;
  --nav-text: #e2e8f0;
}
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 15px; line-height: 1.6; }

/* ===== Navbar ===== */
.navbar {
  background: var(--nav-bg);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: relative;
  z-index: 100;
  flex-wrap: wrap;
}
.nav-brand { color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.nav-links { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.nav-links a { color: var(--nav-text); text-decoration: none; font-size: .9rem; opacity: .85; transition: opacity .15s; }
.nav-links a:hover { opacity: 1; }

main { padding: 1.5rem 1rem; }

/* ===== Container ===== */
.container { max-width: 1100px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; gap: .5rem; }
.page-header h2 { font-size: 1.4rem; }

/* ===== Card ===== */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.card h3 { margin-bottom: .75rem; font-size: 1rem; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg2); color: var(--text); text-decoration: none; cursor: pointer; font-size: .875rem; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* ===== Forms ===== */
label { display: block; margin-bottom: .25rem; font-size: .875rem; font-weight: 500; color: var(--text-muted); }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: .875rem; margin-bottom: 1rem; outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.form-actions { display: flex; gap: .75rem; margin-top: .5rem; flex-wrap: wrap; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.form-row > div label { margin-bottom: .25rem; }

/* ===== Alerts ===== */
.alert { padding: .6rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info  { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
html.dark .alert-error { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
html.dark .alert-info  { background: #1e3a5f; color: #93c5fd; border-color: #1d4ed8; }

/* ===== Login ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-box { width: 100%; max-width: 380px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }
.login-box h1 { margin-bottom: 1.25rem; font-size: 1.3rem; text-align: center; }

/* ===== Ticket Table ===== */
.ticket-table { width: 100%; border-collapse: collapse; }
.ticket-table th, .ticket-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); text-align: left; font-size: .875rem; }
.ticket-table th { background: var(--bg); font-weight: 600; }
.clickable-row { cursor: pointer; transition: background .1s; }
.clickable-row:hover { background: var(--bg); }
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }

/* Mobile: Tabelle scrollbar machen */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-problem  { background: #fee2e2; color: #b91c1c; }
.badge-request  { background: #dbeafe; color: #1d4ed8; }
html.dark .badge-problem { background: #450a0a; color: #fca5a5; }
html.dark .badge-request { background: #1e3a5f; color: #93c5fd; }
.badge-prio-critical { background: #fef3c7; color: #92400e; }
.badge-prio-normal   { background: #d1fae5; color: #065f46; }
html.dark .badge-prio-critical { background: #451a03; color: #fbbf24; }
html.dark .badge-prio-normal   { background: #022c22; color: #6ee7b7; }
.badge-status-open        { background: #dbeafe; color: #1d4ed8; }
.badge-status-in_progress { background: #fef3c7; color: #92400e; }
.badge-status-waiting     { background: #f3e8ff; color: #6b21a8; }
.badge-status-resolved    { background: #d1fae5; color: #065f46; }
.badge-status-closed      { background: #f1f5f9; color: #64748b; }
html.dark .badge-status-open        { background: #1e3a5f; color: #93c5fd; }
html.dark .badge-status-in_progress { background: #451a03; color: #fbbf24; }
html.dark .badge-status-waiting     { background: #3b0764; color: #d8b4fe; }
html.dark .badge-status-resolved    { background: #022c22; color: #6ee7b7; }
html.dark .badge-status-closed      { background: #1e293b; color: #94a3b8; }
.badge-role-admin  { background: #fce7f3; color: #be185d; }
.badge-role-agent  { background: #e0e7ff; color: #3730a3; }
.badge-role-user   { background: #f1f5f9; color: #475569; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: flex-end; }
.filter-bar input, .filter-bar select { width: auto; margin-bottom: 0; min-width: 130px; flex: 1 1 130px; }

/* ===== Ticket Type Choice ===== */
.type-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.btn-type { display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: 1.5rem; font-size: 1rem; font-weight: 600; border: 2px solid var(--border); background: var(--bg); border-radius: var(--radius); cursor: pointer; transition: border-color .15s, background .15s; }
.btn-type:hover { border-color: var(--primary); background: var(--bg2); }
.btn-type small { font-size: .8rem; font-weight: 400; color: var(--text-muted); }

/* ===== Ticket Meta ===== */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; font-size: .875rem; }
.ticket-desc { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); font-size: .9rem; }
.ticket-actions { margin-top: 1rem; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ===== Comments ===== */
.comment { border-left: 3px solid var(--primary); padding: .5rem .75rem; margin-bottom: .75rem; }
.comment-meta { font-size: .8rem; color: var(--text-muted); margin-bottom: .25rem; }
.comment-body { font-size: .9rem; }

/* ===== Toggle ===== */
.toggle-label { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .9rem; }
.toggle-label input { width: auto; margin: 0; }

/* ===== Notification Bell ===== */
.notif-wrap { position: relative; display: flex; align-items: center; }
.notif-bell {
  background: none; border: none; cursor: pointer;
  padding: .3rem .4rem; position: relative;
  color: var(--nav-text); display: flex; align-items: center;
  opacity: .8; transition: opacity .15s; border-radius: var(--radius);
}
.notif-bell:hover { opacity: 1; background: rgba(255,255,255,.08); }
.notif-bell svg { display: block; }
.notif-badge {
  position: absolute; top: 1px; right: 1px;
  background: #ef4444; color: #fff;
  font-size: .6rem; font-weight: 700; border-radius: 999px;
  min-width: 15px; height: 15px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px; pointer-events: none;
}

.notif-dropdown {
  position: fixed; top: 52px; right: 1rem;
  width: min(320px, calc(100vw - 2rem)); max-height: 420px; overflow-y: auto;
  background: #ffffff;
  border: 1px solid #dde1e8;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 9999;
}
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem .9rem;
  border-bottom: 1px solid #dde1e8;
  font-size: .875rem; font-weight: 600;
  color: #1a1a2e;
  position: sticky; top: 0;
  background: #ffffff;
}
.notif-mark-all {
  background: none; border: none; cursor: pointer;
  font-size: .78rem; color: #3b82f6; padding: 0; font-weight: 500;
}
.notif-mark-all:hover { text-decoration: underline; }
.notif-empty { padding: 1.25rem; text-align: center; color: #777; font-size: .875rem; }
.notif-item {
  display: block; padding: .65rem .9rem;
  border-bottom: 1px solid #dde1e8;
  text-decoration: none;
  color: #1a1a2e;
  transition: background .1s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: #f4f5f7; }
.notif-unread { border-left: 3px solid #3b82f6; background: #eff6ff; }
.notif-unread:hover { background: #dbeafe; }
.notif-read { color: #666; }
.notif-msg  { font-size: .85rem; line-height: 1.4; color: #1a1a2e; }
.notif-read .notif-msg { color: #666; }
.notif-time { font-size: .75rem; color: #888; margin-top: .2rem; }

html.dark .notif-dropdown { background: #1e293b; border-color: #334155; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
html.dark .notif-header { background: #1e293b; border-color: #334155; color: #e2e8f0; }
html.dark .notif-mark-all { color: #60a5fa; }
html.dark .notif-empty { color: #94a3b8; }
html.dark .notif-item { border-color: #334155; color: #e2e8f0; }
html.dark .notif-item:hover { background: #0f172a; }
html.dark .notif-unread { background: #1e3a5f; border-left-color: #3b82f6; }
html.dark .notif-unread:hover { background: #1d4ed8; }
html.dark .notif-read { color: #94a3b8; }
html.dark .notif-msg { color: #e2e8f0; }
html.dark .notif-read .notif-msg { color: #94a3b8; }
html.dark .notif-time { color: #64748b; }

/* ===== User List (Accordion) ===== */
.user-list { display: flex; flex-direction: column; gap: .5rem; }
.user-row { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color .15s; user-select: none; }
.user-row:hover, .user-row-open { border-color: var(--primary); }
.user-row-main { display: flex; align-items: center; gap: 1rem; padding: .75rem 1rem; flex-wrap: wrap; }
.user-row-info { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem; min-width: 0; }
.user-row-name  { font-weight: 600; }
.user-row-code  { font-size: .8rem; background: var(--bg); padding: .1rem .4rem; border-radius: 4px; }
.user-row-email { font-size: .8rem; color: var(--text-muted); word-break: break-all; }
.user-row-meta  { display: flex; gap: .4rem; align-items: center; flex-shrink: 0; }
.user-row-arrow { font-size: .9rem; color: var(--text-muted); flex-shrink: 0; }
.user-active    { font-size: .8rem; color: #16a34a; }
.user-detail { border: 1px solid var(--primary); border-top: none; border-radius: 0 0 var(--radius) var(--radius); background: var(--bg); margin-top: -6px; }
.user-detail-inner { padding: 1rem; display: flex; flex-direction: column; gap: 0; }
.detail-section { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.detail-section:first-child { padding-top: 0; }
.detail-section:last-child { border-bottom: none; }
.detail-section h4 { font-size: .85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .6rem; }

/* ===== Permission Chips ===== */
.perm-chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .65rem; border-radius: 999px; border: 1px solid var(--border); background: var(--bg2); font-size: .8rem; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.perm-chip input { display: none; }
.perm-chip:hover { border-color: var(--primary); }
.perm-chip-on { background: var(--primary); border-color: var(--primary); color: #fff; }
.save-ok { font-size: .8rem; color: #16a34a; margin-left: .5rem; }
.text-muted { color: var(--text-muted); }

/* ===== Avatars ===== */
.nav-profile {
  display: flex; align-items: center; gap: .5rem;
  color: var(--nav-text); text-decoration: none;
  font-size: .9rem; opacity: .85; transition: opacity .15s;
}
.nav-profile:hover { opacity: 1; }
.nav-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.25); flex-shrink: 0; }
.nav-avatar-placeholder { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .75rem; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid rgba(255,255,255,.25); flex-shrink: 0; }

.avatar-section { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.avatar-preview { flex-shrink: 0; }
.avatar-img-large { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 3px solid var(--border); display: block; }
.avatar-placeholder-large { width: 96px; height: 96px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 2rem; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 3px solid var(--border); }
.avatar-actions { display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.avatar-hint { font-size: .78rem; color: var(--text-muted); margin: 0; }

/* ===== Mobile Responsive ===== */
@media (max-width: 640px) {
  main { padding: 1rem .75rem; }

  .navbar { padding: .6rem .75rem; gap: .5rem; }
  .nav-links { gap: .5rem; }
  .nav-links a { font-size: .8rem; }

  /* Tickets-Tabelle: unwichtige Spalten ausblenden */
  .ticket-table .col-priority,
  .ticket-table .col-creator { display: none; }

  /* Ticket-Detail Meta untereinander */
  .meta-grid { grid-template-columns: 1fr 1fr; }

  /* Typ-Auswahl untereinander */
  .type-choice { grid-template-columns: 1fr; }

  /* Filter-Bar: volle Breite */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select { min-width: 100%; }
  .filter-bar .btn { width: 100%; justify-content: center; }

  /* Buttons volle Breite in Formularen */
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* Ticket-Aktionen umbrechen */
  .ticket-actions { flex-direction: column; }
  .ticket-actions .btn { width: 100%; justify-content: center; }

  /* User-Accordion */
  .user-row-main { gap: .5rem; }
  .user-row-meta { flex-wrap: wrap; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn { width: 100%; justify-content: center; }

  /* Notification dropdown volle Breite */
  .notif-dropdown { right: .5rem; left: .5rem; width: auto; }
}

.badge-status-rejected { background: #fee2e2; color: #b91c1c; }
html.dark .badge-status-rejected { background: #450a0a; color: #fca5a5; }

.badge-status-rejected { background: #fee2e2; color: #b91c1c; }
html.dark .badge-status-rejected { background: #450a0a; color: #fca5a5; }
