:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #273449;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

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

.hidden { display: none !important; }

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; }
.nav { display: flex; gap: 16px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.nav a.active, .nav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.user-area { display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--muted); }

.container { padding: 24px 32px; max-width: 1400px; margin: 0 auto; }

.auth-card {
    max-width: 400px;
    margin: 80px auto;
    background: var(--surface);
    padding: 32px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.auth-card h1 { margin-top: 0; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.section-header h1 { margin: 0; font-size: 20px; }
.actions { display: flex; gap: 8px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.form { display: flex; flex-direction: column; gap: 12px; }
.form-wide { max-width: 500px; }
.form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--muted);
}
.form input, .form select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
}
.form input:focus, .form select:focus {
    outline: none;
    border-color: var(--primary);
}
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }

.btn {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-alt); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filters input, .filters select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
}
.filters input { flex: 1; min-width: 200px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th {
    background: var(--surface-alt);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}
.data-table th[data-sort]::after { content: ""; opacity: 0.4; margin-left: 4px; }
.data-table th.sort-asc::after  { content: "▲"; opacity: 1; }
.data-table th.sort-desc::after { content: "▼"; opacity: 1; }
.data-table tbody tr:hover { background: var(--surface-alt); cursor: pointer; }
.data-table tbody tr:last-child td { border-bottom: 0; }

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.status-active   { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.status-disabled { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

.risk-low    { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.risk-medium { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
.risk-high   { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 16px;
}

.kv {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    margin: 0;
}
.kv dt { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.kv dd { margin: 0; word-break: break-all; }

.hint { color: var(--muted); font-size: 13px; }

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-width: 360px;
    z-index: 100;
}
.toast.err { border-color: var(--danger); }
.toast.ok  { border-color: var(--success); }

code {
    background: var(--surface-alt);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.row-actions { display: flex; gap: 6px; }
.icon-btn {
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.danger:hover { color: #fca5a5; }
