/* =====================================================================
   ÄKSA Webservice – Oberfläche des Endpunkt-Builders
   ===================================================================== */

:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e7ef;
    --border-strong: #cfd6e2;
    --text: #18212f;
    --text-muted: #5f6b80;
    --text-subtle: #8a94a6;

    --primary: #2355d8;
    --primary-hover: #1b46b8;
    --primary-soft: #e8eefc;
    --success: #18884a;
    --success-soft: #e3f5ea;
    --danger: #c8333a;
    --danger-soft: #fbe9ea;
    --warning: #b57607;
    --warning-soft: #fdf3dc;

    --sidebar: #0f1a2b;
    --sidebar-text: #aab5c8;
    --sidebar-active: #1d2b44;

    --radius: 10px;
    --radius-small: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-large: 0 20px 45px rgba(16, 24, 40, .18);

    --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

code, .mono { font-family: var(--font-mono); font-size: 13px; }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); font-size: 13px; }

/* ---------------------------------------------------------------------
   Grundgerüst: Seitenleiste + Inhalt
   --------------------------------------------------------------------- */

.layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 24px;
    color: #fff;
}
.brand img { width: 32px; height: 32px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .02em; }
.brand-sub { font-size: 12px; color: var(--sidebar-text); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6c7891;
    padding: 14px 12px 6px;
}
.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-small);
    color: var(--sidebar-text);
    font-weight: 500;
}
.nav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid #22314b;
    padding-top: 14px;
}
.user-box { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #2a3b5c;
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}
.user-name { color: #fff; font-weight: 500; font-size: 13px; }
.user-actions { display: flex; gap: 4px; margin-top: 8px; }
.user-actions button {
    flex: 1;
    background: transparent;
    border: 1px solid #2a3b5c;
    color: var(--sidebar-text);
    border-radius: var(--radius-small);
    padding: 6px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}
.user-actions button:hover { background: var(--sidebar-active); color: #fff; }

.main { min-width: 0; }

.content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 32px 60px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.page-header p { margin: 4px 0 0; color: var(--text-muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 6px;
}
.back-link svg { width: 14px; height: 14px; }

/* ---------------------------------------------------------------------
   Karten
   --------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-header p { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat { padding: 18px 20px; }
.stat-label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 4px; }
.stat-note { font-size: 12px; color: var(--text-subtle); margin-top: 2px; word-break: break-word; }

.status-dot {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-small);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-muted); border-color: #b9c2d1; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #eeb7ba; }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #12703c; border-color: #12703c; }

.btn-small { height: 30px; padding: 0 10px; font-size: 13px; }

.btn-icon {
    width: 30px; height: 30px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
}
.btn-icon:hover { background: var(--surface-muted); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------------
   Formulare
   --------------------------------------------------------------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
}
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }

.field label, .field-label {
    display: block;
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 6px;
}
.field .help { font-size: 12px; color: var(--text-subtle); margin-top: 4px; }

.input, select.input, textarea.input {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-small);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.input-small { height: 32px; font-size: 13px; }

.input-group { display: flex; }
.input-group .addon {
    display: flex;
    align-items: center;
    padding: 0 10px;
    border: 1px solid var(--border-strong);
    border-right: none;
    border-radius: var(--radius-small) 0 0 var(--radius-small);
    background: var(--surface-muted);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 13px;
}
.input-group .input { border-radius: 0 var(--radius-small) var(--radius-small) 0; font-family: var(--font-mono); }

.sql-editor {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    min-height: 180px;
    background: #fbfcfe;
    tab-size: 4;
}

.search { position: relative; }
.search svg {
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--text-subtle);
}
.search .input { padding-left: 34px; width: 280px; }

/* Schalter (Checkbox im Look eines Toggles) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
    width: 36px; height: 20px;
    background: var(--border-strong);
    border-radius: 10px;
    position: relative;
    transition: background .15s;
}
.switch .track::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
    transition: transform .15s;
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--primary-soft); }

/* Auswahl der HTTP-Methode */
.segmented {
    display: inline-flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-small);
    overflow: hidden;
}
.segmented button {
    border: none;
    border-right: 1px solid var(--border-strong);
    background: var(--surface);
    padding: 0 12px;
    height: 34px;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}
.segmented button:last-child { border-right: none; }
.segmented button:hover { background: var(--surface-muted); }
.segmented button.active { color: #fff; }
.segmented button.active.m-get { background: var(--success); }
.segmented button.active.m-post { background: var(--primary); }
.segmented button.active.m-put { background: var(--warning); }
.segmented button.active.m-patch { background: #7a4bd1; }
.segmented button.active.m-delete { background: var(--danger); }

/* ---------------------------------------------------------------------
   Tabellen
   --------------------------------------------------------------------- */

.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    background: var(--surface-muted);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: #f7f9fd; }
.table .actions { text-align: right; white-space: nowrap; }
.table .shrink { width: 1%; white-space: nowrap; }

.table.compact th, .table.compact td { padding: 6px 8px; }
.table.compact td .input { height: 32px; }

.table-scroll { overflow: auto; max-height: 420px; }
.table-scroll .table th { position: sticky; top: 0; }

.empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty svg { width: 40px; height: 40px; color: var(--text-subtle); margin-bottom: 10px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty-inline { padding: 18px; text-align: center; color: var(--text-subtle); font-size: 13px; }

/* ---------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------- */

.method {
    display: inline-block;
    min-width: 58px;
    text-align: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em;
}
.m-get { background: var(--success-soft); color: var(--success); }
.m-post { background: var(--primary-soft); color: var(--primary); }
.m-put { background: var(--warning-soft); color: var(--warning); }
.m-patch { background: #efe8fb; color: #6a3fc0; }
.m-delete { background: var(--danger-soft); color: var(--danger); }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.on { background: var(--success-soft); color: var(--success); }
.pill.off { background: #eef0f4; color: var(--text-muted); }

.path { font-family: var(--font-mono); font-size: 13px; }
.path .prefix { color: var(--text-subtle); }

/* ---------------------------------------------------------------------
   Editor
   --------------------------------------------------------------------- */

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 440px;
    gap: 20px;
    align-items: start;
}
.editor-side { position: sticky; top: 20px; }

.section-hint {
    background: var(--surface-muted);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-small);
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.toolbar-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.test-result { margin-top: 16px; }
.test-meta { display: flex; gap: 16px; font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.test-meta strong { color: var(--text); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.tabs button {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 12px;
    font: inherit;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: -1px;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.code-block {
    background: #0f1a2b;
    color: #d7e0ee;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.55;
    padding: 14px 16px;
    border-radius: var(--radius-small);
    overflow: auto;
    max-height: 460px;
    margin: 0;
    white-space: pre;
}
.code-block .k { color: #8cc4ff; }
.code-block .s { color: #a8e0a0; }
.code-block .n { color: #f5c07a; }
.code-block .b { color: #e59ad7; }

.alert {
    padding: 10px 12px;
    border-radius: var(--radius-small);
    font-size: 13px;
    margin-bottom: 12px;
}
.alert-error { background: var(--danger-soft); color: #8f1f25; border: 1px solid #f1c3c6; white-space: pre-wrap; word-break: break-word; }
.alert-info { background: var(--primary-soft); color: #1b3d99; border: 1px solid #c9d6f7; }
.alert-warning { background: var(--warning-soft); color: #7a4f05; border: 1px solid #f0d9a6; }

/* ---------------------------------------------------------------------
   Modal, Toast
   --------------------------------------------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 26, 43, .45);
    display: grid;
    place-items: center;
    z-index: 100;
    padding: 20px;
    animation: fade-in .12s ease-out;
}
.modal {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-large);
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    animation: pop-in .15s ease-out;
}
.modal.wide { max-width: 720px; }
.modal-header { padding: 18px 22px 0; }
.modal-body { padding: 16px 22px; overflow: auto; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
    border-radius: 0 0 12px 12px;
}

.secret-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    padding: 8px 10px;
    margin-bottom: 12px;
}
.secret-box code { flex: 1; word-break: break-all; }

.toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
}
.toast {
    min-width: 260px;
    max-width: 420px;
    padding: 12px 16px;
    border-radius: 8px;
    background: #1b2638;
    color: #fff;
    box-shadow: var(--shadow-large);
    font-size: 13px;
    animation: slide-in .18s ease-out;
    border-left: 4px solid var(--primary);
}
.toast.success { border-left-color: #35c172; }
.toast.error { border-left-color: #ef5a61; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(20px); } }

.loading { padding: 60px; text-align: center; color: var(--text-muted); }
.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle;
}
.btn .spinner { width: 14px; height: 14px; border-color: rgba(255, 255, 255, .4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------
   Login
   --------------------------------------------------------------------- */

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.login-visual {
    background: linear-gradient(145deg, #0f1a2b 0%, #18305e 60%, #2355d8 140%);
    color: #fff;
    padding: 56px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.login-visual h2 { font-size: 30px; font-weight: 600; line-height: 1.25; max-width: 440px; }
.login-visual p { color: #b9c6dd; max-width: 440px; font-size: 15px; }
.login-visual .brand { padding: 0; }
.login-form-wrap { display: grid; place-items: center; padding: 40px; background: var(--surface); }
.login-form { width: 100%; max-width: 360px; }
.login-form h1 { margin-bottom: 6px; }
.login-form > p { color: var(--text-muted); margin: 0 0 28px; }
.login-form .field { margin-bottom: 16px; }
.login-form .input { height: 42px; }
.login-form .btn { width: 100%; height: 42px; margin-top: 8px; }

/* ---------------------------------------------------------------------
   Kleinere Bildschirme
   --------------------------------------------------------------------- */

@media (max-width: 1200px) {
    .editor-grid { grid-template-columns: 1fr; }
    .editor-side { position: static; }
}

@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .content { padding: 20px 16px 40px; }
    .login-page { grid-template-columns: 1fr; }
    .login-visual { display: none; }
    .form-grid > [class^="col-"] { grid-column: span 12; }
    .search .input { width: 100%; }
}

/* Abstand zwischen Feldern in Dialogen */
.modal-body .field + .field { margin-top: 14px; }
.modal-body p { margin: 0 0 12px; }
.test-inputs { margin-bottom: 16px; }
