:root {
    --bg: #0f1420;
    --bg-soft: #161d2e;
    --surface: #1b2436;
    --surface-hover: #212c42;
    --border: #2a3550;
    --text: #eef1f8;
    --text-muted: #9aa5bd;
    --primary: #6c8bff;
    --primary-dark: #5470e0;
    --primary-soft: rgba(108, 139, 255, 0.15);
    --danger: #ff6b6b;
    --success: #37d399;
    --warning: #f5b942;
    --radius: 14px;
    --shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(circle at top left, #1a2338 0%, var(--bg) 55%);
    color: var(--text);
    min-height: 100vh;
}

a { color: inherit; }

/* ---------- Auth (login / install) ---------- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-wrap { width: 100%; max-width: 420px; }

.auth-card-wide { max-width: 480px; }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 36px 32px;
}

.auth-brand { text-align: center; margin-bottom: 24px; }

.auth-logo {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #9f7bff);
    color: white;
}

.auth-logo.small { width: 34px; height: 34px; border-radius: 10px; margin: 0; }

.auth-brand h1 { margin: 0 0 4px; font-size: 22px; }
.auth-brand p { margin: 0; color: var(--text-muted); font-size: 14px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-section-title {
    margin: 8px 0 -4px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }

.field span { color: var(--text-muted); }

.field input {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-hint { color: var(--text-muted); font-size: 12px; }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; }
.btn-primary:hover { opacity: 0.92; }

.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-hover); }

.btn-block { width: 100%; }

/* ---------- Alerts ---------- */

.alert { padding: 12px 14px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; line-height: 1.5; }
.alert-error { background: rgba(255, 107, 107, 0.12); color: #ffb1b1; border: 1px solid rgba(255, 107, 107, 0.3); }
.alert-success { background: rgba(55, 211, 153, 0.12); color: #8be8c4; border: 1px solid rgba(55, 211, 153, 0.3); }
.alert-warning { background: rgba(245, 185, 66, 0.12); color: #f6cf8a; border: 1px solid rgba(245, 185, 66, 0.3); }

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    background: rgba(22, 29, 46, 0.7);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }

.topbar-actions { display: flex; align-items: center; gap: 14px; }

.user-chip { color: var(--text-muted); font-size: 14px; }

/* ---------- Page ---------- */

.page { max-width: 1200px; margin: 0 auto; padding: 32px; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-head h1 { margin: 0 0 4px; font-size: 24px; }

.muted { color: var(--text-muted); margin: 0; font-size: 14px; }

.page-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.search-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    min-width: 220px;
    outline: none;
}

.search-input:focus { border-color: var(--primary); }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
}

.empty-state p { margin-bottom: 16px; }

/* ---------- Cards ---------- */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.card:hover { border-color: var(--primary); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); transform: translateY(-2px); }

.card-open {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.card-favicon { width: 28px; height: 28px; border-radius: 6px; background: var(--bg-soft); flex-shrink: 0; }

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-external { color: var(--text-muted); flex-shrink: 0; }

.card-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    padding: 6px 0;
}

.card-label { color: var(--text-muted); width: 78px; flex-shrink: 0; }

.card-value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover { color: var(--primary); border-color: var(--primary); }

.card-footer {
    display: flex;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.link-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
}

.link-btn:hover { color: var(--primary); }

.link-danger:hover { color: var(--danger); }

/* ---------- Modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 9, 16, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 50;
}

.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 { margin: 0 0 18px; font-size: 18px; }

#app-form { display: flex; flex-direction: column; gap: 14px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.form-error {
    background: rgba(255, 107, 107, 0.12);
    color: #ffb1b1;
    border: 1px solid rgba(255, 107, 107, 0.3);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    font-size: 13.5px;
    z-index: 100;
}

.toast[hidden] { display: none; }

@media (max-width: 640px) {
    .topbar { padding: 14px 18px; }
    .page { padding: 20px; }
    .page-head { align-items: flex-start; }
    .page-head-actions { width: 100%; }
    .search-input { flex: 1; min-width: 0; }
}
