/* =====================================================================
   Spacecraft Materialfluss-Planer — Theme
   Dunkel, schlicht, tabellarisch, responsive.
   ===================================================================== */

:root {
    --bg:        #0a0f1e;
    --bg-grad:   radial-gradient(1200px 600px at 80% -10%, #142142 0%, transparent 60%),
                 radial-gradient(900px 500px at -10% 10%, #10203a 0%, transparent 55%),
                 #0a0f1e;
    --panel:     #111a30;
    --panel-2:   #0d1526;
    --row:       #0f1830;
    --row-alt:   #0c1426;
    --border:    #20304f;
    --border-soft:#172139;
    --text:      #d9e2f7;
    --muted:     #7e8db1;
    --accent:    #54c8ec;   /* Telemetrie-Cyan */
    --accent-2:  #8e7cf0;   /* Rezept-Violett */
    --surplus:   #56d28b;
    --shortage:  #f0686f;
    --warn:      #e6b15a;

    --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Consolas", monospace;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --radius: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg-grad);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px clamp(12px, 3vw, 28px) 60px;
}

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 6px 2px 18px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
    width: 34px; height: 34px;
    border-radius: 9px;
    background:
        conic-gradient(from 210deg, var(--accent), var(--accent-2), var(--accent));
    box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 6px 20px -8px var(--accent);
    position: relative;
}
.brand-mark::after {
    content: "";
    position: absolute; inset: 9px;
    border-radius: 4px;
    background: var(--bg);
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .2px; font-weight: 650; }
.brand .sub { margin: 0; color: var(--muted); font-size: 12px; }

.controls { display: flex; align-items: center; gap: 12px; }
.hours { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.hours-field {
    display: inline-flex; align-items: center;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 10px 0 4px;
}
.hours-field input {
    width: 78px;
    background: transparent; border: 0; color: var(--text);
    font-family: var(--mono); font-size: 15px; padding: 8px;
    text-align: right;
}
.hours-field input:focus { outline: none; }
.hours-field .unit { color: var(--muted); font-family: var(--mono); }

/* ---------- Buttons ---------- */
.btn {
    background: linear-gradient(180deg, #1d3a5f, #16314f);
    color: #eaf4ff;
    border: 1px solid #2a4a73;
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font: inherit; font-weight: 600;
    cursor: pointer;
    transition: border-color .15s, transform .05s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
    font-weight: 500;
}
.btn.ghost:hover { border-color: var(--accent); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger {
    background: transparent; border-color: #4a2330; color: var(--shortage);
    padding: 5px 10px; font-size: 12px;
}
.btn.danger:hover { border-color: var(--shortage); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Panels ---------- */
.panel {
    background: linear-gradient(180deg, var(--panel), var(--panel-2));
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 16px clamp(12px, 2vw, 20px) 18px;
    margin-bottom: 18px;
    box-shadow: 0 18px 40px -28px rgba(0,0,0,.9);
}
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    margin-bottom: 12px;
}
.panel-head h2 { font-size: 14px; margin: 0; font-weight: 650; letter-spacing: .3px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }

/* ---------- Legende / Tags ---------- */
.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
    font-size: 11px; padding: 3px 9px; border-radius: 999px;
    border: 1px solid var(--border); color: var(--muted);
    display: inline-flex; align-items: center; gap: 6px;
}
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag.shortage { color: var(--shortage); border-color: #432029; }
.tag.surplus  { color: var(--surplus);  border-color: #1f3e2e; }
.tag.neutral  { color: var(--muted); }

/* ---------- Tabellen ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
table.grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 640px;
}
table.grid th, table.grid td {
    padding: 9px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
}
table.grid thead th {
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    background: var(--panel-2);
    position: sticky; top: 0; z-index: 2;
}
table.grid tbody tr:nth-child(odd)  { background: var(--row-alt); }
table.grid tbody tr:nth-child(even) { background: var(--row); }
table.grid tbody tr:hover { background: #16223c; }
table.grid .num { text-align: right; font-family: var(--mono); }
table.grid .actions { text-align: right; width: 1%; }
.sticky-col { position: sticky; left: 0; z-index: 3; background: var(--panel-2); }
table.grid tbody td.sticky-col { background: inherit; font-weight: 600; }

td.empty { color: var(--muted); text-align: center; padding: 22px; }

/* Plan-Tabelle: Netto/Status farblich */
td.netto-pos { color: var(--surplus); font-weight: 600; }
td.netto-neg { color: var(--shortage); font-weight: 600; }
.status-pill {
    font-size: 11px; padding: 2px 9px; border-radius: 999px;
    border: 1px solid var(--border); white-space: nowrap;
}
.status-pill.shortage { color: var(--shortage); border-color: #43222b; background: #1c0f14; }
.status-pill.surplus  { color: var(--surplus);  border-color: #1f3e2e; background: #0e1c16; }
.status-pill.neutral  { color: var(--muted); }
.range { color: var(--warn); font-family: var(--mono); font-size: 11px; }

/* Bestand-nach-X negativ hervorheben */
td.after-neg { color: var(--shortage); }

/* ---------- Forms ---------- */
.row-form {
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    padding: 10px; margin-bottom: 12px;
    background: var(--panel-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}
.row-form input, .row-form select {
    background: #0a1322;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font: inherit;
    min-width: 120px;
}
.row-form input[type="number"] { font-family: var(--mono); max-width: 130px; }
.row-form input:focus, .row-form select:focus { outline: none; border-color: var(--accent); }
.row-form select { cursor: pointer; }

.recipe-form { flex-direction: column; align-items: stretch; }
.recipe-line { display: flex; flex-wrap: wrap; gap: 12px; }
.recipe-line label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.recipe-inputs {
    border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
    padding: 10px; background: #0a1322;
}
.recipe-inputs-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.input-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
.input-row select { flex: 1; }
.input-row .rm { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 6px; cursor: pointer; padding: 6px 10px; }
.input-row .rm:hover { border-color: var(--shortage); color: var(--shortage); }
.recipe-chip { display: inline-block; background: #141d33; border: 1px solid var(--border-soft); border-radius: 6px; padding: 1px 7px; margin: 1px 3px 1px 0; font-size: 11px; font-family: var(--mono); color: var(--muted); }

/* ---------- Tabs ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tab {
    background: transparent; border: 1px solid transparent; color: var(--muted);
    padding: 7px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px;
}
.tab:hover { color: var(--text); }
.tab.active { color: #fff; background: #16223c; border-color: var(--border); }
.tabpane { display: none; }
.tabpane.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Sankey ---------- */
.sankey-wrap { width: 100%; overflow-x: auto; }
.sankey-wrap svg { display: block; max-width: 100%; }
.sankey-wrap .node rect { rx: 2; cursor: default; }
.sankey-wrap .node text { fill: var(--text); font-size: 11px; }
.sankey-wrap .node text.outline { stroke: var(--bg); stroke-width: 3px; paint-order: stroke; }
.sankey-wrap .link { fill: none; stroke-opacity: .38; transition: stroke-opacity .15s; }
.sankey-wrap .link:hover { stroke-opacity: .65; }
.sankey-empty { color: var(--muted); padding: 24px 4px; font-size: 13px; }

/* ---------- Footer / Toast ---------- */
.foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.muted { color: var(--muted); font-size: 12px; }
.toast {
    background: #16223c; border: 1px solid var(--border); color: var(--text);
    padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px;
    box-shadow: 0 14px 30px -18px #000;
}
.toast.error { border-color: #43222b; color: var(--shortage); }
.toast.success { border-color: #1f3e2e; color: var(--surplus); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .topbar { align-items: flex-start; }
    .controls { width: 100%; justify-content: space-between; }
    .brand h1 { font-size: 16px; }
    .row-form { gap: 6px; }
    .row-form input, .row-form select { min-width: 0; flex: 1 1 130px; }
    table.grid { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
