@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Colors */
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --surface-3: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: var(--surface-3);
  
  /* Brand */
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-glow: rgba(59, 130, 246, 0.4);
  
  /* Metrics */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --surface-3: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #3b82f6;
  }
}

/* --- RESET & BASE --- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  background-image: radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
                    radial-gradient(at 100% 0%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
}
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* --- LAYOUT --- */
.container { max-width: 1200px; margin: 40px auto; padding: 0 20px; }
.app {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  min-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden;
}

main > h2, .section-title {
  padding: 0 24px;
  margin-top: 24px;
  margin-bottom: 8px;
  font-weight: 700;
}
.section-title { font-size: 1.5rem; }
#budi-info { padding: 0 24px; margin-bottom: 20px; }

/* --- HEADER --- */
header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 20px; font-weight: 700; margin: 0; }
header .sub { font-size: 13px; color: var(--text-muted); margin: 0; }

/* --- TABS --- */
.tabs { display: flex; gap: 8px; }
.tablist { display: flex; padding: 4px; background: var(--surface-2); border-radius: var(--radius-md); list-style: none; margin: 0; gap: 2px; }
.tab {
  appearance: none; border: none; background: transparent;
  color: var(--text-muted); padding: 6px 14px; font-size: 13px; font-weight: 600;
  border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"], .tab.active, a.tab:hover {
  background: var(--surface); color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* --- PANELS & GRIDS --- */
.panel { display: none; padding: 24px; animation: fadeIn 300ms ease; }
.panel[aria-hidden="false"] { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.span-2 { grid-column: span 2; }

/* --- COMPONENTS --- */
.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px dashed var(--border);
  flex-wrap: wrap; gap: 16px;
}
.toolbar .muted { font-weight: 600; font-size: 14px; color: var(--text-muted); text-transform: uppercase; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; font-size: 13px; font-weight: 600; height: 36px;
  border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; transition: var(--transition);
}
.btn:hover:not(:disabled) { background: var(--surface-2); transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
label span { font-size: 13px; font-weight: 600; color: var(--text-muted); }
input, select, textarea {
  width: 100%; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); color: var(--text); font-family: inherit; font-size: 14px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
input:read-only { opacity: 0.7; background: var(--surface-2); cursor: default; }

/* Tables */
.norm-table {
  width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden;
}
.norm-table th {
  background: var(--surface-2); color: var(--text-muted); font-weight: 600; text-align: left;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 12px; text-transform: uppercase;
}
.norm-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.norm-table tbody tr:hover td { background: var(--surface-2); }
.norm-table tbody tr[aria-selected="true"] td, .norm-table tr.selected td {
  background: color-mix(in srgb, var(--primary) 15%, var(--surface)); color: var(--primary-hover);
}
.interactive-cell { cursor: pointer; color: var(--primary); font-weight: 500; }
.interactive-cell:hover { text-decoration: underline; }

/* Specific Row Status Colors (Validity) */
/* Draft: Yellowish */
.norm-table tbody tr.row-draft td {
  background-color: color-mix(in srgb, #facc15 15%, var(--surface));
  color: #ca8a04; /* Darker yellow/brown for visibility */
}
/* Invalid: Reddish */
.norm-table tbody tr.row-invalid td {
  background-color: color-mix(in srgb, #ef4444 15%, var(--surface));
  color: #b91c1c; /* Dark red */
}

/* Hover States for Status Rows */
.norm-table tbody tr.row-draft:hover td {
  background-color: color-mix(in srgb, #facc15 25%, var(--surface));
}
.norm-table tbody tr.row-invalid:hover td {
  background-color: color-mix(in srgb, #ef4444 25%, var(--surface));
}

/* Spezifität erhöht, um !important zu entfernen */
table .norm-table td.disabled-cell { 
    color: var(--text-muted); 
    font-style: italic; 
    background: var(--surface-2); 
    pointer-events: none; 
}

/* Filter Row */
.filter-row th { padding: 4px 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.filter-row input {
  width: 100%; font-size: 12px; padding: 6px; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px; color: var(--text);
}
.filter-row input:focus { border-color: var(--primary); outline: none; }

/* Tree View */
.group h3 { font-size: 13px; color: var(--text-muted); margin: 0 0 10px 4px; text-transform: uppercase; }
.option {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); margin-bottom: 8px; color: var(--text); cursor: pointer; transition: var(--transition); text-align: left;
}
.option:hover { border-color: var(--primary); background: var(--surface-2); }
.option[aria-pressed="true"] { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); border-color: var(--primary); color: var(--primary-hover); }
.option[data-children]::after { content: '›'; font-size: 18px; color: var(--text-muted); transition: transform var(--transition); }
.option[aria-pressed="true"]::after { transform: rotate(90deg); color: var(--primary); }
.nested { max-height: 0; overflow: hidden; opacity: 0; padding-left: 20px; margin-left: 12px; border-left: 2px solid var(--border); transition: all 300ms; }
.nested.visible { max-height: 2000px; opacity: 1; margin: 8px 0 16px; }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.2s; }
.modal.open { display: flex; opacity: 1; }
.modal__card {
  background: var(--surface); width: 100%; max-width: 1100px; max-height: 90vh; overflow-y: auto;
  border-radius: var(--radius-lg); border: 1px solid var(--border); padding: 32px; transform: scale(0.95); transition: transform 0.2s;
}
.modal.open .modal__card { transform: scale(1); }
.modal__card h3 { margin-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 16px; }

/* Utils & Icons */
.badge { display: inline-block; padding: 4px 10px; background: var(--surface-2); border-radius: 99px; font-size: 11px; font-weight: 700; color: var(--text-muted); border: 1px solid var(--border); }
.kv { display: flex; flex-direction: column; }
.kv span { font-size: 11px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.warning-icon { color: #f59e0b; font-size: 1.2em; margin-left: 8px; vertical-align: middle; cursor: help; }
.error-icon { color: #ef4444; font-size: 1.2em; margin-left: 8px; vertical-align: middle; cursor: help; }

/* Checkbox Lists */
.checkbox-list {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px; max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
}
.checkbox-list label {
  display: flex; align-items: flex-start; gap: 12px; font-size: 13px; padding: 4px 0;
  cursor: pointer; line-height: 1.5; transition: background-color 0.1s; border-radius: 4px;
}
.checkbox-list label:hover { background-color: var(--surface-2); }

/* Klassen-Selektor für Performance statt nur Attribut */
.checkbox-item, .checkbox-list input[type="checkbox"] {
  accent-color: var(--primary); width: 16px; height: 16px; margin-top: 3px; flex-shrink: 0; cursor: pointer;
}

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
  header, .toolbar { flex-direction: column; align-items: flex-start; }
  .toolbar-actions { width: 100%; margin-top: 10px; justify-content: space-between; }
}