:root {
  /* MACH corporate palette (sourced from mach.de design tokens) */
  --mach-red: #cc1216;
  --mach-red-dark: #a60e12;
  --petrol: #014258;      /* primary structural color */
  --petrol-2: #39576d;
  --petrol-3: #4d7a8a;
  --teal: #8bd2d9;        /* light accent */
  --teal-2: #349db2;

  --bg: #eef3f5;
  --card: #ffffff;
  --ink: #10171d;
  --muted: #5a6b78;
  --line: #dbe6ea;
  --brand: #cc1216;       /* CTA / active = MACH red */
  --brand-ink: #014258;   /* links / structural */
  --sidebar: #014258;     /* deep petrol */
  --sidebar-ink: #b9d3dc;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(1, 66, 88, .10), 0 1px 2px rgba(1, 66, 88, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5;
}
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--mach-red); }
h1, h2, h3 { margin: 0 0 .3em; line-height: 1.25; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px; background: linear-gradient(135deg,#e11b1f,#cc1216);
  color: #fff; font-weight: 800; font-size: 20px; display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(204,18,22,.4);
}
.brand-logo { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); overflow: hidden; }
.brand-logo img { display: block; object-fit: contain; }
.brand-name { color: #fff; font-weight: 700; letter-spacing: .01em; }
.brand-name .dot { color: var(--mach-red); }
.brand-sub { color: #6f9aa8; font-size: 12px; }
.nav { display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { color: var(--sidebar-ink); padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a.active { box-shadow: 0 2px 6px rgba(204,18,22,.35); }
.nav-group { color: #6f9aa8; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin: 14px 12px 4px; font-weight: 700; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 6px; }
.env-badge { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.env-dev { background: #422006; color: #fbbf24; }
.env-staging { background: #052e16; color: #4ade80; }
.env-prod { background: #450a0a; color: #f87171; }
.auth-badge { font-size: 11px; color: #64748b; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: 12px; }
.user-meta { text-align: right; }
.user-name { font-weight: 600; }
.user-role { font-size: 11px; padding: 1px 8px; border-radius: 20px; display: inline-block; }
.role-platform_admin { background: #fde5e5; color: #a60e12; }
.role-owner { background: #f3e8ff; color: #7c3aed; }
.role-sales { background: #dcfce7; color: #15803d; }
.role-support { background: #fff3e0; color: #b45309; }
.role-org_owner { background: #e0f2fe; color: #0369a1; }
.role-org_admin { background: #d7e7ec; color: #014258; }
.role-member { background: #eef3f5; color: #4d7a8a; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--petrol); color: #fff; display: grid; place-items: center; font-weight: 700; }
.logout { color: var(--muted); font-size: 20px; padding: 0 4px; }
.content { padding: 28px; max-width: 1200px; width: 100%; }

/* ---------- Cards & grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 700; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; } .sidebar { display: none; } }

/* ---------- Stat tiles ---------- */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat .num { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat .ico { float: right; font-size: 22px; opacity: .35; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfe; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 20px; white-space: nowrap; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-violet { background: #ede9fe; color: #6d28d9; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ---------- App tile ---------- */
.app-ico { width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--mach-red-dark); border-color: var(--mach-red-dark); }
.btn-danger { color: #b91c1c; border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { border-color: transparent; background: transparent; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); border-color: var(--petrol); }
textarea { resize: vertical; min-height: 90px; }
.field { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-inline { display: flex; gap: 8px; align-items: end; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; }

/* ---------- Collapsible "modal" via details ---------- */
details.panel { margin-bottom: 18px; }
details.panel > summary { list-style: none; cursor: pointer; display: inline-flex; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel[open] > summary .btn { background: #eef2ff; }
.panel-body { margin-top: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { display: flex; justify-content: space-between; align-items: center; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.pill-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.pill-tabs a { padding: 6px 12px; border-radius: 20px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: 13px; }
.pill-tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.progress { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--brand); }
.notice { background: #e6eef1; border: 1px solid #c8dce3; color: #014258; padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 18px; border-left: 3px solid var(--mach-red); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg,#013243,#014258 55%,#0a5c6e); padding: 20px; position: relative; }
.login-wrap::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 85% 15%, rgba(204,18,22,.35), transparent 40%); pointer-events: none; }
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.35); position: relative; z-index: 1; border-top: 4px solid var(--mach-red); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 24px; }
.login-err { background: #fee2e2; color: #b91c1c; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--muted); background: #f8fafc; border: 1px dashed var(--line); border-radius: 8px; padding: 12px; }
.oidc-btn { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.divider { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0; position: relative; }

/* ---------- Ticketing (Jira-like) ---------- */
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.view-toggle a { padding: 6px 14px; font-weight: 600; font-size: 13px; color: var(--muted); }
.view-toggle a:hover { text-decoration: none; background: #f8fafc; }
.view-toggle a.active { background: var(--petrol); color: #fff; }
.label-chip { display: inline-block; background: #e6eef1; color: #014258; border: 1px solid #c8dce3; font-size: 11px; padding: 1px 8px; border-radius: 6px; margin-left: 4px; }
.mini-avatar { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--petrol-2); color: #fff; font-size: 11px; font-weight: 700; }

.board { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board-col { background: #e9eef1; border-radius: 10px; padding: 8px; min-width: 210px; }
.board-col-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; padding: 6px 8px 10px; color: #334f5c; }
.board-count { margin-left: auto; background: #fff; border-radius: 20px; padding: 0 8px; font-size: 12px; color: var(--muted); }
.board-col-body { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.board-empty { text-align: center; color: #9fb3bc; font-size: 12px; padding: 8px; }
.ticket-card { background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; box-shadow: var(--shadow); }
.ticket-card-title { display: block; font-weight: 600; color: var(--ink); margin: 6px 0; }
.ticket-card-title:hover { color: var(--mach-red); text-decoration: none; }
.ticket-card-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.ticket-card-foot { align-items: center; }
.card-moves { display: inline-flex; gap: 3px; }
.move-btn { width: 22px; height: 22px; border: 1px solid var(--line); background: #f4f7f9; border-radius: 5px; font-size: 11px; font-weight: 700; color: var(--petrol-3); cursor: pointer; }
.move-btn:hover { background: var(--petrol); color: #fff; border-color: var(--petrol); }

.dot-green,.dot-blue,.dot-amber,.dot-red,.dot-gray,.dot-violet,.dot-orange { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-green { background: #16a34a; } .dot-blue { background: #2563eb; } .dot-amber { background: #d97706; }
.dot-red { background: #dc2626; } .dot-gray { background: #94a3b8; } .dot-violet { background: #7c3aed; } .dot-orange { background: #ea580c; }

/* Activity timeline */
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 8px 0 8px 4px; }
.tl-dot { position: absolute; left: -19px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--petrol); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.tl-event .tl-dot { background: #94a3b8; }
.tl-comment .tl-dot { background: var(--mach-red); }
@media (max-width: 900px) { .board { grid-template-columns: repeat(5, 220px); } }
