/* ============================================================
   Conduxa — Swiss Precision Industrial Design
   IBM Plex Mono für Zahlen | IBM Plex Sans für Text
   Palette: Tiefes Blau-Grau + Orange-Akzent + Neutralgrau
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --c-bg:          #F5F4F0;    /* Warmes Off-White — Papier */
  --c-surface:     #FFFFFF;
  --c-surface-2:   #F0EEE9;
  --c-border:      #D8D4CC;
  --c-border-strong: #B8B2A8;

  --c-text-primary:   #1A1814;
  --c-text-secondary: #5C5750;
  --c-text-muted:     #9C9690;

  --c-brand:       #1A3050;    /* Tiefes Marineblau */
  --c-brand-light: #2E5080;
  --c-accent:      #D4540A;    /* Baumaschinen-Orange */
  --c-accent-light: #F4861A;

  --c-green:  #1A7A42;  --c-green-bg:  #E8F5EE;
  --c-yellow: #A06B00;  --c-yellow-bg: #FFF8E1;
  --c-red:    #C0200A;  --c-red-bg:    #FDECEA;
  --c-blue:   #0B4F8C;  --c-blue-bg:   #E3EEF8;

  --sidebar-w: 220px;
  --topbar-h:  52px;

  --font-ui:   'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
  --font-display: 'Instrument Serif', Georgia, serif;

  --radius-sm: 3px;
  --radius:    6px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 2px 8px rgba(0,0,0,.10);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.12);

  --transition: 180ms ease;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; min-height: 100vh; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font-ui); background: var(--c-bg); color: var(--c-text-primary); width: 100%; min-height: 100vh; }
a { color: var(--c-brand); text-decoration: none; }
a:hover { color: var(--c-brand-light); }
button { cursor: pointer; font-family: inherit; }
img { max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────── */
.layout-root {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  transition: grid-template-columns var(--transition);
}
.layout-root:has(#sidebar.collapsed) {
  grid-template-columns: 56px minmax(0, 1fr);
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-w);
  background: var(--c-brand);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,.08);
  transition: width var(--transition);
  z-index: 100;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .sidebar-project,
.sidebar.collapsed .user-info,
.sidebar.collapsed .logout-btn { display: none; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand-mark {
  width: 28px; height: 28px;
  background: var(--c-accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600; font-size: 11px;
  letter-spacing: .5px;
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .5px;
  color: rgba(255,255,255,.95);
}

.sidebar-project {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.05);
}
.project-label { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.4); margin-bottom: 2px; }
.project-code  { font-family: var(--font-mono); font-size: 11px; color: var(--c-accent-light); font-weight: 600; }
.project-name  { font-size: 11px; color: rgba(255,255,255,.75); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); }

.nav-section-label {
  font-size: 9px; text-transform: uppercase; letter-spacing: 1.2px;
  color: rgba(255,255,255,.35); padding: 12px 16px 4px;
  font-weight: 500;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px;
  color: rgba(255,255,255,.7);
  font-size: 12.5px; font-weight: 400;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,.1);
  border-left-color: var(--c-accent);
  color: #fff;
  font-weight: 500;
}
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
.nav-item.active .nav-icon, .nav-item:hover .nav-icon { opacity: 1; }

.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.1);
  background: rgba(0,0,0,.15);
}
.user-avatar {
  width: 28px; height: 28px;
  background: var(--c-accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-email { font-size: 11px; color: rgba(255,255,255,.85); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { font-size: 9px; text-transform: uppercase; letter-spacing: .8px; color: rgba(255,255,255,.4); }
.logout-btn { color: rgba(255,255,255,.4); padding: 4px; border-radius: var(--radius-sm); background: none; border: none; display: flex; }
.logout-btn:hover { color: rgba(255,255,255,.9); background: rgba(255,255,255,.1); }

/* ── Main Content ───────────────────────────────────────────── */
.main-content { display: flex; flex-direction: column; min-height: 100vh; overflow-x: auto; overflow-y: auto; min-width: 0; width: 100%; }

.topbar {
  height: var(--topbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.sidebar-toggle {
  background: none; border: none; color: var(--c-text-secondary);
  padding: 4px; border-radius: var(--radius-sm);
  display: flex;
}
.sidebar-toggle:hover { background: var(--c-surface-2); color: var(--c-text-primary); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--c-text-muted); }
.breadcrumb a { color: var(--c-text-secondary); }
.breadcrumb a:hover { color: var(--c-brand); }
.breadcrumb a + a::before { content: '/'; margin-right: 6px; color: var(--c-border-strong); }

.page-content { flex: 1; padding: 20px 24px; width: 100%; min-width: 0; box-sizing: border-box; }

/* ── HTMX Loading ───────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: flex; align-items: center; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-brand);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Flash Messages ─────────────────────────────────────────── */
#flash-container { padding: 0 24px; }
.flash {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; margin-bottom: 8px;
  border-radius: var(--radius); font-size: 13px;
  border-left: 4px solid;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { opacity:0; transform: translateY(-8px); } }
.flash-success { background: var(--c-green-bg);  border-color: var(--c-green);  color: var(--c-green); }
.flash-error   { background: var(--c-red-bg);    border-color: var(--c-red);    color: var(--c-red); }
.flash-warning { background: var(--c-yellow-bg); border-color: var(--c-yellow); color: var(--c-yellow); }
.flash-info    { background: var(--c-blue-bg);   border-color: var(--c-blue);   color: var(--c-blue); }
.flash-close { background: none; border: none; font-size: 18px; color: inherit; opacity: .6; padding: 0 4px; }

/* ── Typography ─────────────────────────────────────────────── */
.page-header { margin-bottom: 20px; }
.page-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  color: var(--c-text-primary);
  line-height: 1.2;
}
.page-subtitle { font-size: 13px; color: var(--c-text-muted); margin-top: 3px; }

h2 { font-size: 16px; font-weight: 600; color: var(--c-text-primary); }
h3 { font-size: 14px; font-weight: 600; color: var(--c-text-primary); }

.mono { font-family: var(--font-mono); }
.amount { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--c-text-muted); font-weight: 500; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--c-text-primary); }

/* ── KPI-Kacheln ────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-color, var(--c-brand));
}
.kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--c-text-muted); margin-bottom: 6px; }
.kpi-value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; color: var(--c-text-primary); line-height: 1; }
.kpi-sub   { font-size: 11px; color: var(--c-text-muted); margin-top: 4px; }
.kpi-card.green  { --kpi-color: var(--c-green); }
.kpi-card.yellow { --kpi-color: var(--c-yellow); }
.kpi-card.red    { --kpi-color: var(--c-red); }
.kpi-card.brand  { --kpi-color: var(--c-brand); }
.kpi-card.accent { --kpi-color: var(--c-accent); }

/* ── Ampel-Badge ────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px; font-weight: 500;
}
.badge-green  { background: var(--c-green-bg);  color: var(--c-green); }
.badge-yellow { background: var(--c-yellow-bg); color: var(--c-yellow); }
.badge-red    { background: var(--c-red-bg);    color: var(--c-red); }
.badge-blue   { background: var(--c-blue-bg);   color: var(--c-blue); }
.badge-grey   { background: var(--c-surface-2); color: var(--c-text-secondary); }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px; font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--c-brand); color: #fff;
  border-color: var(--c-brand);
}
.btn-primary:hover { background: var(--c-brand-light); border-color: var(--c-brand-light); }
.btn-accent  { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.btn-accent:hover { background: var(--c-accent-light); }
.btn-secondary {
  background: var(--c-surface);
  color: var(--c-text-primary);
  border-color: var(--c-border-strong);
}
.btn-secondary:hover { background: var(--c-surface-2); }
.btn-ghost   { background: none; border-color: transparent; color: var(--c-text-secondary); }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-text-primary); }
.btn-danger  { background: var(--c-red-bg); color: var(--c-red); border-color: #FFCDD2; }
.btn-sm { padding: 4px 10px; font-size: 11.5px; }
.btn-icon { padding: 6px; }
.btn svg { width: 14px; height: 14px; }

/* ── Tabellen ───────────────────────────────────────────────── */
.table-container { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 600px;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--c-text-muted);
  font-weight: 600;
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.data-table th.amount-col { text-align: right; }
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text-primary);
  vertical-align: middle;
}
.data-table td.amount-col {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--c-surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .total-row td {
  font-weight: 600;
  background: var(--c-surface-2);
  border-top: 2px solid var(--c-border-strong);
}

/* ── Formulare ──────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 11px; font-weight: 500; color: var(--c-text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.form-label .required { color: var(--c-accent); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px;
  background: var(--c-surface);
  color: var(--c-text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px rgba(26,48,80,.1);
}
.form-input.mono { font-family: var(--font-mono); }
.form-hint  { font-size: 11px; color: var(--c-text-muted); }
.form-error { font-size: 11px; color: var(--c-red); }

/* ── Modals ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(540px, 90vw);
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(.96) translateY(-12px); } }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body   { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--c-border); display: flex; gap: 8px; justify-content: flex-end; }

/* ── Ampel-Indikatoren ──────────────────────────────────────── */
.traffic-light {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500;
}
.tl-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tl-green  .tl-dot { background: var(--c-green); }
.tl-yellow .tl-dot { background: var(--c-yellow); }
.tl-red    .tl-dot { background: var(--c-red); animation: pulse 1.4s ease infinite; }
.tl-green  { color: var(--c-green); }
.tl-yellow { color: var(--c-yellow); }
.tl-red    { color: var(--c-red); }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.45; } }

/* ── Utilities ──────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.flex    { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-16  { margin-bottom: 16px; }
.mb-20  { margin-bottom: 20px; }
.text-right { text-align: right; }
.text-muted { color: var(--c-text-muted); }
.text-small { font-size: 11px; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout-root { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Zusätzliche Utility-Klassen ── */
.flex-between { display:flex; justify-content:space-between; align-items:center; }
.grid-2 { display:grid; grid-template-columns:repeat(2,1fr); }
.grid-3 { display:grid; grid-template-columns:repeat(3,1fr); }
.alert { padding:12px 16px; border-radius:3px; margin-bottom:16px; font-family:'IBM Plex Sans',sans-serif; font-size:14px; }
.alert-error { background:#FEE2E2; border:1px solid #FECACA; color:#DC2626; }
.alert-success { background:#D1FAE5; border:1px solid #A7F3D0; color:#065F46; }
.form-hint { font-size:12px; color:var(--c-text-muted); margin-top:4px; }
.form-hint a { color:var(--c-blue); text-decoration:none; }
.badge-red { background:#FEE2E2; color:#DC2626; }
.badge-blue { background:#DBEAFE; color:#1D4ED8; }
.logout-btn { font-size:13px; color:var(--c-text-muted); text-decoration:none; padding:4px 8px; border-radius:3px; }
.logout-btn:hover { background:var(--c-bg-hover); }
textarea.form-control { resize:vertical; min-height:60px; }
@media (max-width:768px) { .grid-2,.grid-3 { grid-template-columns:1fr; } }

/* ── Responsive Spalten ────────────────────────────────────── */
@media (max-width: 1200px) {
  .col-hide-sm { display: none; }
}

/* ── Empty State (S25-D) ──────────────────────────────────────────── */
.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--c-text-muted);
}
.empty-state-icon { font-size: 36px; margin-bottom: 12px; display: block }
.empty-state h3   { font-size: 15px; font-weight: 600; margin: 0 0 6px; color: var(--c-text) }
.empty-state p    { font-size: 13px; margin: 0 0 16px }
