/* ============================================================================
 * TEKA Design System — Single Source of Truth
 *
 * Basiert auf Design-Doku v2.1.
 * Wird von ALLEN TEKA-Apps eingebunden.
 *
 * Bei Anpassungen: erst hier ändern, dann _template ansehen, dann Apps mitziehen.
 * Logo kommt aus js/teka-logo.js (TEKA_LOGO_BASE64).
 * Theme aus js/teka-theme.js (data-theme="light|dark" auf <html>).
 * ========================================================================== */

/* ---------- CSS-Variablen: Light Mode (Standard) -------------------------- */

:root {
  /* Surfaces */
  --bg-body:        #e6edf4;
  --card-bg:        #ffffff;
  --card-border:    #e5e7eb;
  --card-shadow:    0 1px 3px rgba(0,0,0,0.04);
  --header-bg:      #1B3A6B;
  --input-bg:       #ffffff;
  --input-border:   #d1d5db;
  --hover-bg:       rgba(59, 130, 246, 0.04);
  --table-header-bg: #f3f6fa;

  /* Text */
  --text-main:      #000000;
  --text-muted:     #4b5563;
  --text-white:     #ffffff;

  /* Akzentfarben */
  --color-blue:        #3b82f6;
  --color-blue-hover:  #2563eb;
  --color-green:       #10b981;
  --color-orange:      #f59e0b;
  --color-red:         #ef4444;
  --color-red-hover:   #dc2626;
  --color-grey:        #6b7280;
  --color-purple:      #7c3aed;

  /* Status-Backgrounds (Tabellen-Zellen) */
  --status-ok:        #a5d6a7;
  --status-warn:      #ffc107;
  --status-error:     #e57373;

  /* Radii */
  --radius-container: 12px;
  --radius-card:       8px;
  --radius-input:      6px;
  --radius-pill:      999px;

  /* Transition */
  --transition: all 0.2s ease;
}

/* ---------- Dark Mode ----------------------------------------------------- */

[data-theme="dark"] {
  --bg-body:        #374151;
  --card-bg:        #4b5563;
  --card-border:    #334155;
  --card-shadow:    0 1px 3px rgba(0,0,0,0.2);
  --input-bg:       #1f2937;
  --input-border:   #4b5563;
  --hover-bg:       rgba(59, 130, 246, 0.10);
  --table-header-bg: #374151;

  --text-main:      #ffffff;
  --text-muted:     #94a3b8;
}

/* ---------- Reset --------------------------------------------------------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-body);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------- App-Wrapper --------------------------------------------------- */

.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 10px 24px;
  gap: 10px;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ============================================================================
 * Header (64px)
 * ========================================================================== */

.header {
  height: 64px;
  background: var(--header-bg);
  color: var(--text-white);
  border-radius: var(--radius-container);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  height: 32px;
  width: auto;
  filter: brightness(0) invert(1);
}

.app-name {
  font-size: 18px;
  font-weight: 700;
}

.icon-btn {
  background: rgba(255,255,255,0.15);
  color: var(--text-white);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover  { background: rgba(255,255,255,0.25); }
.icon-btn.active { background: rgba(255,255,255,0.30); }

.user-info {
  font-size: 12px;
  opacity: 0.9;
  white-space: nowrap;
}

/* Filter-Selects/Inputs im Header (auf dunklem Grund) */
.header select,
.header input[type="text"],
.header input[type="search"] {
  background: rgba(255,255,255,0.95);
  color: var(--text-main);
  border: 1px solid rgba(255,255,255,0.3);
}

/* ============================================================================
 * Toolbar / Filter-Leiste (border-radius 12px, gleiche Breite wie Header)
 * ========================================================================== */

.toolbar {
  padding: 12px 20px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-container);
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.toolbar-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.toolbar-info {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ============================================================================
 * Form Inputs (einheitlich)
 * ========================================================================== */

input[type="text"],
input[type="date"],
input[type="email"],
input[type="number"],
input[type="search"],
select,
textarea {
  padding: 6px 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input);
  background: var(--input-bg);
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

input[type="checkbox"] {
  accent-color: var(--color-blue);
  cursor: pointer;
}

label {
  font-size: 13px;
  color: var(--text-muted);
}

/* ============================================================================
 * Buttons
 * ========================================================================== */

.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 6px 14px;
  border-radius: var(--radius-input);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-blue);
  color: var(--text-white);
  border-color: var(--color-blue);
}
.btn-primary:hover { background: var(--color-blue-hover); border-color: var(--color-blue-hover); }

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-main);
  border-color: var(--input-border);
}
.btn-secondary:hover { background: var(--bg-body); }

.btn-danger {
  background: var(--color-red);
  color: var(--text-white);
  border-color: var(--color-red);
}
.btn-danger:hover { background: var(--color-red-hover); border-color: var(--color-red-hover); }

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mini-Icon-Button in Tabellen-Zellen (Plus, Hide, Show, etc.) */
.cell-btn {
  background: var(--color-blue);
  color: var(--text-white);
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  vertical-align: middle;
}
.cell-btn:hover { background: var(--color-blue-hover); }

.cell-btn--ghost {
  background: transparent;
  border: 1px solid var(--input-border);
  color: var(--text-muted);
}
.cell-btn--ghost:hover {
  background: var(--color-red);
  color: var(--text-white);
  border-color: var(--color-red);
}

/* ============================================================================
 * Tabelle (mit vertikalen Trennstrichen)
 * ========================================================================== */

.table-wrapper {
  overflow: auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-container);
  box-shadow: var(--card-shadow);
  flex: 1;
  min-height: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);   /* vertikale Trennstriche */
  vertical-align: top;
  white-space: nowrap;
}

.data-table th:last-child,
.data-table td:last-child {
  border-right: none;
}

.data-table th {
  background: var(--table-header-bg);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table tbody tr:hover { background: var(--hover-bg); }

.data-table tbody tr.row-hidden {
  opacity: 0.45;
  font-style: italic;
}
.data-table tbody tr.row-hidden:hover { opacity: 0.7; }

.table-info {
  color: var(--text-muted);
  font-size: 12px;
  padding: 0 4px;
}

/* ============================================================================
 * Popup (Dropdown / Settings / Menu)
 *
 * Per Default: position: absolute relativ zum nächsten positioned parent.
 * Für Header-rechts: .popup--header-right
 * ========================================================================== */

.popup {
  display: none;
  position: absolute;
  background: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgba(0,0,0,0.16);
  padding: 12px;
  min-width: 240px;
  z-index: 100;
}
.popup.open { display: block; }

.popup--header-right {
  top: calc(100% + 6px);
  right: 0;
}

.popup h4 {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.popup h4:not(:first-child) { margin-top: 14px; }

.popup-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 60vh;
  overflow-y: auto;
}

.popup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-main);
}
.popup-item:hover { background: var(--bg-body); }

/* ============================================================================
 * Modal (HTML5 <dialog>)
 * ========================================================================== */

.modal {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 24px;
  max-width: 480px;
  background: var(--card-bg);
  color: var(--text-main);
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  font-family: inherit;
}
.modal::backdrop { background: rgba(0,0,0,0.4); }

.modal h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--header-bg);
}
.modal p { margin: 6px 0; font-size: 13px; }

.modal-label {
  display: block;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.modal-label input,
.modal-label select {
  display: block;
  margin-top: 4px;
  width: 100%;
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ============================================================================
 * Toast (Notification)
 * ========================================================================== */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-card);
  background: var(--card-bg);
  color: var(--text-main);
  border-left: 4px solid var(--color-grey);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  font-size: 13px;
  max-width: 360px;
  min-width: 220px;
  white-space: pre-wrap;
  pointer-events: auto;
  animation: toast-slidein 0.2s ease;
}
.toast-info    { border-left-color: var(--color-blue);   }
.toast-warning { border-left-color: var(--color-orange); }
.toast-error   { border-left-color: var(--color-red);    }
.toast-fadeout { animation: toast-fadeout 0.3s ease forwards; }

@keyframes toast-slidein {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes toast-fadeout {
  to { transform: translateX(20px); opacity: 0; }
}

/* ============================================================================
 * Login Screen
 * ========================================================================== */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-body);
}

.login-box {
  text-align: center;
  padding: 2rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-container);
  box-shadow: var(--card-shadow);
  max-width: 400px;
}

.login-box h1 {
  margin-top: 0;
  color: var(--header-bg);
  font-weight: 700;
}

/* ============================================================================
 * Misc Status / Messages
 * ========================================================================== */

.busy {
  font-size: 16px;
  display: inline-flex;
  align-items: center;
}

.loading-msg {
  color: var(--text-muted);
  font-style: italic;
  padding: 16px 20px;
}

.error-msg {
  color: #b91c1c;
  padding: 12px 16px;
  background: #fee2e2;
  border-left: 4px solid var(--color-red);
  border-radius: var(--radius-card);
}
[data-theme="dark"] .error-msg {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}
