*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f1f5f9;
    --surface: #fff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-2: #64748b;
    --text-3: #94a3b8;
    --accent: #6366f1;
    --accent-h: #4f46e5;
    --green: #22c55e; --green-bg: #dcfce7; --green-t: #166534;
    --yellow: #eab308; --yellow-bg: #fef9c3; --yellow-t: #854d0e;
    --red: #ef4444; --red-bg: #fee2e2; --red-t: #991b1b;
    --blue: #3b82f6; --blue-bg: #dbeafe; --blue-t: #1e40af;
    --gray: #6b7280; --gray-bg: #f3f4f6; --gray-t: #374151;
    --sidebar-bg: #1e293b;
    --sidebar-t: #94a3b8;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

/* ===== Login ===== */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
}
.login-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-card h1 {
    font-size: 22px;
    margin-bottom: 2px;
}
.login-card .subtitle {
    color: var(--text-2);
    margin-bottom: 28px;
    font-size: 13px;
}
.form-group { margin-bottom: 14px; }
.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}
.form-group input:focus { border-color: var(--accent); }

/* ===== Layout ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 200px;
    background: var(--sidebar-bg);
    color: var(--sidebar-t);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
}
.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-header h2 { font-size: 15px; color: #fff; font-weight: 600; }
.nav-link {
    display: block;
    padding: 10px 16px;
    color: var(--sidebar-t);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all .15s;
}
.nav-link:hover { color: #e2e8f0; background: rgba(255,255,255,.05); }
.nav-link.active {
    color: #fff;
    background: rgba(255,255,255,.08);
    border-left-color: var(--accent);
}
.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}
.content {
    flex: 1;
    margin-left: 200px;
    padding: 28px 32px;
    min-height: 100vh;
}

/* ===== Typography ===== */
h1 { font-size: 20px; font-weight: 600; margin-bottom: 20px; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 14px; }
h1 .text-2 { font-weight: 400; }

/* ===== Stats ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 8px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.stat-danger { border-left: 3px solid var(--red); }
.stat-warn { border-left: 3px solid var(--yellow); }

/* ===== Tables ===== */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-2);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    white-space: nowrap;
}
tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.row-danger { background: var(--red-bg) !important; }
.row-warn { background: var(--yellow-bg) !important; }
.empty-cell { text-align: center; color: var(--text-3); padding: 32px 14px !important; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: 4px; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green-t); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow-t); }
.badge-red { background: var(--red-bg); color: var(--red-t); }
.badge-blue { background: var(--blue-bg); color: var(--blue-t); }
.badge-gray { background: var(--gray-bg); color: var(--gray-t); }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    transition: all .15s;
    line-height: 1.3;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-h); }
.btn-warn { background: var(--yellow-bg); color: var(--yellow-t); border-color: var(--yellow); }
.btn-warn:hover { background: var(--yellow); color: #fff; }
.btn-danger { background: var(--red-bg); color: var(--red-t); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { border: none; background: none; color: var(--sidebar-t); padding: 7px 0; }
.btn-ghost:hover { color: #fff; background: none; }
.btn-block { width: 100%; text-align: center; }

/* ===== Forms ===== */
input[type="number"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}
input[type="number"]:focus { border-color: var(--accent); }

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h1 { margin-bottom: 0; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ===== New code display ===== */
.new-code {
    background: var(--blue-bg);
    border: 1px solid var(--blue);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 0;
}
.page-info { font-size: 13px; color: var(--text-2); }

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    z-index: 1000;
    transition: opacity .3s, transform .3s;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.toast.hidden { opacity: 0; transform: translateY(-10px); pointer-events: none; }
.toast-success { background: var(--green-t); color: #fff; }
.toast-error { background: var(--red); color: #fff; }

/* ===== Utility ===== */
.mono { font-family: "SF Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 12px; }
.hidden { display: none !important; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-danger { color: var(--red); font-weight: 600; }
.text-sm { font-size: 11px; }
.nowrap { white-space: nowrap; }
.loading { padding: 48px; text-align: center; color: var(--text-3); }
.error-msg { color: var(--red); font-size: 13px; margin-top: 12px; }
.hint { margin-top: 16px; font-size: 12px; color: var(--text-3); }
.hint code {
    background: var(--gray-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
}

/* ===== Provider Card (legacy, kept so older panel layouts still render) ===== */
.provider-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
@media (max-width: 900px) {
    .provider-cards { grid-template-columns: 1fr; }
}
.provider-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.provider-header {
    font-size: 14px;
    margin-bottom: 10px;
}
.provider-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

/* ===== Provider Strip (compact deploy layout) ===== */
.provider-section {
    margin-bottom: 20px;
}
.deploy-section-title {
    font-size: 15px;
    margin: 0 0 10px 0;
    color: var(--text-2, #666);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.provider-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px;
}
.provider-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    overflow: hidden;
}
.provider-chip-unset {
    border-color: var(--warn, #b58a00);
    background: color-mix(in srgb, var(--warn, #b58a00) 6%, var(--surface));
}
.provider-chip-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
}
.provider-chip-header strong {
    flex: 1;
    font-weight: 500;
    font-size: 13px;
}
.provider-chip-chevron {
    color: var(--text-2, #888);
    font-size: 12px;
}
.provider-form {
    padding: 10px 12px 12px 12px;
    border-top: 1px solid var(--border);
    background: var(--gray-bg, #f7f7f7);
}
.provider-form .deploy-form-row {
    margin-bottom: 8px;
}
.provider-form input { width: 100%; }

.deploy-form-compact input,
.deploy-form-compact select {
    width: 100%;
    max-width: 320px;
}
.deploy-jobs-section { margin-top: 20px; }

/* ===== Deploy Form ===== */
.deploy-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}
.deploy-form h2 { margin-top: 0; margin-bottom: 16px; }
.deploy-form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}
.deploy-form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.deploy-form-row label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-2);
}
.deploy-form-row input,
.deploy-form-row select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    transition: border-color .15s;
}
.deploy-form-row input:focus,
.deploy-form-row select:focus { border-color: var(--accent); }

/* ===== Log Viewer ===== */
.log-viewer {
    background: #1e1e2e;
    color: #cdd6f4;
    font-family: "SF Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 11px;
    line-height: 1.6;
    padding: 14px 16px;
    border-radius: var(--radius);
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ===== Destroy Button ===== */
.btn-destroy {
    background: #1e1e2e;
    color: var(--red);
    border-color: var(--red);
    font-size: 11px;
}
.btn-destroy:hover {
    background: var(--red);
    color: #fff;
}

.wipe-section {
    margin-top: 32px;
    padding: 20px;
    border: 1px dashed var(--red);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(239, 68, 68, 0.04);
}
.btn-wipe {
    background: var(--red);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.btn-wipe:hover { background: #dc2626; }
.wipe-hint {
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.4;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 720px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal-wide { max-width: 920px; }

/* Node detail drawer — v2 config state block */
.v2-empty {
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--gray-bg, #f7f7f7);
}
.v2-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== Usage block (traffic widget in user detail modal) ===== */
.usage-block {
    padding: 10px 12px;
    background: var(--gray-bg, #f7f7f7);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.usage-line {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 14px;
}
.usage-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.usage-bar-fill {
    height: 100%;
    transition: width 0.2s ease-out;
}
.usage-bar-ok     { background: var(--green, #2a8f3f); }
.usage-bar-warn   { background: var(--warn, #b58a00); }
.usage-bar-danger { background: var(--danger, #c0392b); }

/* Wider textarea support in modal forms */
.modal-body textarea {
    width: 100%;
    font-family: monospace;
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: inherit;
    resize: vertical;
}
.modal-body .deploy-form-row label code {
    background: var(--gray-bg);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 20px; }

.cred-block {
    margin-bottom: 16px;
}
.cred-block label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.cred-uri {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.cred-uri code {
    flex: 1;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    word-break: break-all;
    line-height: 1.5;
    color: var(--accent);
}
.cred-uri .btn { flex-shrink: 0; margin-top: 4px; }
.cred-table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}
.cred-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.cred-table td:first-child {
    width: 160px;
    font-weight: 600;
    color: var(--text-2);
}

/* ===== Clickable Rows ===== */
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #eef2ff !important; }

/* ===== Sync Button ===== */
.btn-sync {
    background: var(--blue-bg);
    color: var(--blue-t);
    border-color: var(--blue);
    font-size: 11px;
}
.btn-sync:hover { background: var(--blue); color: #fff; }

/* ===== User Detail Modal ===== */
.user-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 24px;
    margin-bottom: 20px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.user-info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
}
.user-info-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-2);
}
.modal-section-title {
    font-size: 14px;
    font-weight: 600;
    margin: 18px 0 10px;
}
.modal-section-title .text-2 { font-weight: 400; }
.row-revoked { opacity: .55; }

.text-warn { color: var(--yellow-t); font-weight: 600; }
