/* =========================================================================
   emerve Backend – Design-System
   Corporate Identity emerve.com: Korall (#fa754c) auf warmem Anthrazit,
   Fonts Outfit (Headings) + Source Sans Pro (Text), self-hosted.
   ========================================================================= */

@font-face {
    font-family: "Outfit";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("fonts/outfit-600.woff2") format("woff2");
}
@font-face {
    font-family: "Source Sans Pro";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/source-sans-regular.woff2") format("woff2");
}
@font-face {
    font-family: "Source Sans Pro";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("fonts/source-sans-600.woff2") format("woff2");
}

:root {
    /* Marke */
    --coral:      #fa754c;
    --coral-600:  #e16944;
    --coral-050:  #fff1ed;

    /* Dunkle Flächen (Sidebar) – warmes Anthrazit */
    --ink-900:    #141110;
    --ink-800:    #1f1a18;
    --ink-700:    #2a2422;

    --accent:     var(--coral);
    --accent-600: var(--coral-600);
    --accent-050: var(--coral-050);

    --bg:       #faf9f8;
    --surface:  #ffffff;
    --border:   #e6e5e4;
    --text:     #141110;
    --muted:    #6b6968; /* AA-konform auf Weiß/bg (4.5:1) */

    --success:  #2f7d5b;
    --success-bg: #e9f5ee;
    --danger:   #c9483d;
    --danger-bg: #fcefee;

    --radius:   12px;
    --radius-sm: 8px;
    --shadow:   0 1px 2px rgba(20,17,16,.06), 0 6px 20px rgba(20,17,16,.07);
    --shadow-sm: 0 1px 2px rgba(20,17,16,.08);

    --font: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    --font-head: "Outfit", var(--font);
    --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-600); }
h1 { font-family: var(--font-head); font-weight: 600; font-size: 1.55rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .86em; }
.icon { flex: 0 0 auto; vertical-align: middle; }
code { font-family: var(--mono); background: #f2f0ef; padding: .1em .35em; border-radius: 5px; font-size: .85em; }

/* ---------- App-Shell ---------- */
body.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

.sidebar {
    background: linear-gradient(180deg, var(--ink-800), var(--ink-900));
    color: #e8e4e1;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 24px; }
.brand-logo { height: 22px; width: auto; display: block; }
.brand-tag {
    font-family: var(--font-head); font-weight: 600;
    font-size: .62rem; letter-spacing: .08em; text-transform: uppercase;
    color: #a8a29e; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.16);
}

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: #b8b3af; font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.is-active { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.09); }
.user { display: flex; align-items: center; gap: 8px; color: #a8a29e; font-size: .82rem; padding: 4px 8px 12px; overflow: hidden; }
.user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { padding: 34px 40px 60px; max-width: 1160px; width: 100%; }

/* ---------- Guest / Login ---------- */
body.guest { display: grid; place-items: center; min-height: 100vh;
    background: radial-gradient(1200px 500px at 50% -10%, #2a2422 0%, var(--bg) 55%); }
.guest-wrap { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 34px 30px; }
.login-head { text-align: center; margin-bottom: 24px; }
.login-logo { height: 34px; width: auto; display: block; margin: 0 auto 12px; }
.guest-flashes { margin-bottom: 14px; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-head p { margin: 0; }
.link.back { display: inline-flex; align-items: center; gap: 5px; font-size: .85rem; margin-bottom: 8px; color: var(--muted); }
.link.back:hover { color: var(--accent); }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 26px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; align-items: center; gap: 15px; box-shadow: var(--shadow-sm); }
.stat-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 11px; background: var(--accent-050); color: var(--accent); }
.stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .82rem; }

/* ---------- Panel ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 22px; }
.panel-narrow { max-width: 620px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.detail-grid { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 13px 20px; text-align: left; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.table td { border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #faf9f8; }
/* .right muss die generische th/td-Ausrichtung überschreiben (höhere Spezifität) */
.right, .table th.right, .table td.right { text-align: right; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.inline { display: inline; margin: 0; }

/* ---------- Tags / dots ---------- */
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; background: #f2f0ef; color: #57534f; font-size: .76rem; font-weight: 600; }
.tag-accent { background: var(--accent-050); color: var(--accent-600); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot-on { background: var(--success); }
.dot-off { background: #cbc7c4; }

/* ---------- Buttons ---------- */
.btn, .btn-ghost { display: inline-flex; align-items: center; gap: 7px; font-family: inherit; font-size: .9rem; font-weight: 600; padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s; }
.btn:focus-visible, .btn-ghost:focus-visible, .nav-item:focus-visible, .link:focus-visible {
    outline: 2px solid var(--coral); outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-600); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f7f5f4; color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: #f0ccc8; }
.sidebar .btn-ghost { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.12); color: #e8e4e1; }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ---------- Forms ---------- */
.form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.login-card .form { padding: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .84rem; font-weight: 600; color: #3c3938; }
.field em { color: var(--danger); font-style: normal; }
.field input, .field select { font-family: inherit; font-size: .95rem; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text); width: 100%; transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-050); }
.field .hint { color: var(--muted); font-size: .78rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: flex-start; gap: 9px; font-size: .88rem; color: #3c3938; padding: 4px 0; }
.check input[type="checkbox"] { width: auto; flex: 0 0 auto; margin-top: 3px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- Flash ---------- */
.flashes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash { display: flex; align-items: center; gap: 9px; padding: 12px 15px; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: #1e6b4a; border-color: #c3e3d1; }
.flash-error { background: var(--danger-bg); color: #a33128; border-color: #f0ccc8; }

/* ---------- Empty / meta / code ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty .icon { color: #c4bfbb; }
.error-state .icon { color: var(--danger); }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; padding: 18px 20px; margin: 0; }
.meta dt { color: var(--muted); font-size: .84rem; }
.meta dd { margin: 0; font-weight: 600; text-align: right; }
.code { margin: 0; padding: 18px 20px; background: #1f1a18; color: #e8e4e1; font-family: var(--mono); font-size: .82rem; line-height: 1.6; overflow-x: auto; max-height: 560px; }

/* ---------- Duplizieren: Preflight ---------- */
.panel-form .form { padding: 20px; }
.check-list { display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; }
.check-list .check { display: flex; width: 100%; align-items: center; justify-content: flex-start; gap: 9px; padding: 8px 10px; border-radius: 6px; margin: 0; cursor: pointer; }
.check-list .check input[type="checkbox"] { margin: 0; }
.check-list .check > span { text-align: left; }
.check-list .check:hover { background: #faf9f8; }
.preflight { padding: 18px 20px 20px; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); font-size: .88rem; margin: 4px 0 14px; border: 1px solid transparent; }
.note .icon { flex: 0 0 auto; margin-top: 1px; }
.note-ok { background: var(--success-bg); color: #1e6b4a; border-color: #c3e3d1; }
.note-warn { background: var(--coral-050); color: #9a4a2c; border-color: #f6cdba; }
.ref-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ref-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #faf9f8; border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* ---------- Modal (ersetzt native confirm/alert) ---------- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: rgba(20, 17, 16, .45);
    opacity: 0; transition: opacity .12s ease;
}
.modal-overlay.open { opacity: 1; }
.modal-overlay.closing { opacity: 0; }
.modal {
    background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(20,17,16,.28);
    width: 100%; max-width: 420px; padding: 24px;
    transform: translateY(6px) scale(.98); transition: transform .12s ease;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-body { font-size: 1rem; color: var(--text); line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #b23a30; color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    body.app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px 12px; }
    .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: none; display: flex; align-items: center; gap: 10px; }
    .sidebar-foot .user { display: none; } /* E-Mail auf Mobile ausblenden, Logout bleibt sichtbar */
    .sidebar-foot form { margin: 0; }
    .sidebar-foot .btn-ghost { padding: 8px 12px; }
    .nav { flex-direction: row; margin: 0; }
    .brand { padding: 0 8px 0 0; }
    .content { padding: 22px; }
    .stat-grid, .detail-grid, .field-row { grid-template-columns: 1fr; }
}
