:root {
    --color-bg: #0a0d13;
    --color-bg-texture: #0c0f16;
    --color-surface: #121620;
    --color-surface-raised: #171c28;
    --color-border: #242a3a;
    --color-border-soft: #1a2030;
    --color-text: #e7e9f0;
    --color-text-muted: #8791a8;
    --color-primary: #7c7ff5;
    --color-primary-hover: #9294f8;
    --color-primary-soft: rgba(124, 127, 245, 0.14);
    --color-success: #2fd671;
    --color-success-soft: rgba(47, 214, 113, 0.14);
    --color-danger: #f04848;
    --color-danger-soft: rgba(240, 72, 72, 0.14);
    --color-warning: #f5a623;
    --color-muted-soft: #1b2130;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
    --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.035) 1px, transparent 0) 0 0 / 22px 22px,
        var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; color: var(--color-text); }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
p { margin: 0; }

/* ---------- Layout ---------- */

.app-shell {
    display: grid;
    grid-template-columns: 236px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border-soft);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 24px;
    font-weight: 700;
    font-size: 17px;
    font-family: var(--mono);
    color: var(--color-text);
}

.brand .dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--color-primary);
    box-shadow: 0 0 0 4px var(--color-primary-soft), 0 0 10px 0 var(--color-primary);
}

.sidebar-close {
    display: none;
    margin-left: auto;
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

/* ---------- Mobile navigation ---------- */

.page-title-row { display: flex; align-items: center; gap: 10px; }

.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    cursor: pointer;
}
.mobile-menu-btn svg { width: 18px; height: 18px; }
.mobile-menu-btn.is-hidden { display: none; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(3, 5, 10, 0.6);
    z-index: 55;
}
.sidebar-backdrop.is-open { display: block; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-weight: 500;
    border: 1px solid transparent;
}

.nav-link:hover { background: var(--color-surface-raised); text-decoration: none; color: var(--color-text); }
.nav-link.active { background: var(--color-primary-soft); color: var(--color-primary); border-color: rgba(124, 127, 245, 0.35); }

.sidebar .spacer { flex: 1; }

.sidebar .logout-form { padding: 4px 10px; }
.sidebar .user-email { padding: 0 10px 8px; font-size: 12px; color: var(--color-text-muted); overflow-wrap: anywhere; font-family: var(--mono); }

.main {
    padding: 32px 40px;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-header p.subtitle { color: var(--color-text-muted); margin-top: 4px; }

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

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-padded { padding: 20px 24px; }

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

.toolbar form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.search-bar { display: flex; gap: 10px; flex: 1; min-width: 220px; max-width: 420px; }
.search-bar .input { flex: 1; }

.filters-panel {
    display: none;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    padding: 14px 16px;
    margin: -6px 0 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.filters-panel.is-open { display: flex; }

.filter-dropdown { position: relative; }
.filter-dropdown-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 20;
    flex-direction: column;
    gap: 2px;
    width: max-content;
    min-width: 220px;
    max-width: calc(100vw - 40px);
    max-height: 320px;
    overflow-y: auto;
    padding: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.5);
}
.filter-dropdown-panel.is-open { display: flex; }
.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    margin-bottom: 0;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
}
.filter-checkbox:hover { background: var(--color-surface-raised); }
.filter-checkbox input { width: auto; margin: 0; accent-color: var(--color-primary); cursor: pointer; }

/* ---------- View toggle ---------- */

.view-toggle {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
}
.view-toggle button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 34px;
    background: var(--color-surface);
    border: none;
    border-left: 1px solid var(--color-border);
    color: var(--color-text-muted);
    cursor: pointer;
}
.view-toggle button:first-child { border-left: none; }
.view-toggle button:hover { color: var(--color-text); background: var(--color-surface-raised); }
.view-toggle button.active { color: var(--color-primary); background: var(--color-primary-soft); }
.view-toggle svg { width: 17px; height: 17px; }

/* ---------- Forms ---------- */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }

.input, select.input, textarea.input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    font-size: 16px;
    color: var(--color-text);
    font-family: inherit;
}

.input:focus, select.input:focus, textarea.input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.field { margin-bottom: 16px; }
.field .hint { font-size: 12px; color: var(--color-text-muted); margin-top: 5px; }
.input-group { display: flex; align-items: center; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.input-prefix { color: var(--color-text-muted); font-size: 14px; white-space: nowrap; font-family: var(--mono); }

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 13.5px;
    cursor: pointer;
    margin-bottom: 0;
}
.checkbox-field input { width: auto; margin: 0; accent-color: var(--color-primary); cursor: pointer; flex-shrink: 0; }

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--color-primary); color: #0a0d13; }
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-secondary { background: var(--color-surface-raised); border-color: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-border); }

.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-danger:hover { background: rgba(240, 72, 72, 0.24); }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px 8px; }

/* ---------- Table (vista de lista) ---------- */

table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
}
tbody td { padding: 13px 14px; border-bottom: 1px solid var(--color-border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-raised); }

.mono { font-family: var(--mono); font-size: 13px; }
.text-muted { color: var(--color-text-muted); }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }

/* ---------- Status dot ---------- */

.status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 500;
}
.status-dot { width: 9px; height: 9px; border-radius: 999px; flex-shrink: 0; }
.status-online .status-dot { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-soft), 0 0 8px 0 var(--color-success); }
.status-offline .status-dot { background: var(--color-danger); box-shadow: 0 0 0 3px var(--color-danger-soft), 0 0 8px 0 var(--color-danger); }
.status-unchecked .status-dot { background: #6b7385; box-shadow: 0 0 0 3px var(--color-muted-soft); }
.status-online { color: var(--color-success); }
.status-offline { color: var(--color-danger); }
.status-unchecked { color: var(--color-text-muted); }

/* ---------- Badges / tag chips ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--mono);
}
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--mono);
    cursor: pointer;
}
.tag-chip:hover { border-color: var(--color-primary); color: var(--color-text); }
.tag-chip.is-selected {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #0a0d13;
}

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

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    border: 1px solid transparent;
}
.alert-success { background: var(--color-success-soft); color: var(--color-success); border-color: rgba(47, 214, 113, 0.3); }
.alert-error { background: var(--color-danger-soft); color: var(--color-danger); border-color: rgba(240, 72, 72, 0.3); }

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

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(3, 5, 10, 0.65);
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 50;
}
.modal-backdrop.is-open { display: flex; }

.modal {
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    padding: 24px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--color-text-muted); line-height: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Empty state ---------- */

.empty-state { text-align: center; padding: 56px 24px; color: var(--color-text-muted); }

/* ---------- Pagination ---------- */

.pagination { display: flex; gap: 6px; margin-top: 20px; justify-content: flex-end; }
.pagination a, .pagination span {
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 13px;
    color: var(--color-text);
}
.pagination .current { background: var(--color-primary); color: #0a0d13; border-color: var(--color-primary); }

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

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    background:
        radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.035) 1px, transparent 0) 0 0 / 22px 22px,
        radial-gradient(ellipse at top, rgba(124, 127, 245, 0.12), transparent 60%),
        var(--color-bg);
}
.terminal-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg), 0 0 80px -30px rgba(124, 127, 245, 0.45);
}
.terminal-titlebar {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 12px 16px;
    background: var(--color-surface-raised);
    border-bottom: 1px solid var(--color-border);
}
.terminal-dot { width: 11px; height: 11px; border-radius: 999px; }
.terminal-dot.red { background: #f04848; }
.terminal-dot.yellow { background: #f5a623; }
.terminal-dot.green { background: #2fd671; }
.terminal-titlebar-label { margin-left: 8px; font-family: var(--mono); font-size: 12px; color: var(--color-text-muted); }
.terminal-body { padding: 36px 32px; }
.terminal-body .brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 10px; font-weight: 700; font-size: 19px; font-family: var(--mono); }

.login-prompt {
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--color-success);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 26px;
    opacity: 0.85;
}
.blink-cursor { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Link grid (vista "default") ---------- */

[data-view-panel="list"] { display: none; }

.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.tag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.tag-card {
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}
.tag-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag-card-top .badge { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-card-count { font-size: 11.5px; color: var(--color-text-muted); font-family: var(--mono); flex-shrink: 0; }
.tag-card-actions { display: flex; gap: 6px; margin-top: auto; }
.tag-card-actions form { display: contents; }
.tag-card-actions .btn { flex: 1; }

.link-card {
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}
.link-card:hover { transform: translateY(-2px); }
.link-card:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.link-card.status-online { border-color: var(--color-success); box-shadow: 0 0 0 1px rgba(47, 214, 113, 0.12), 0 8px 24px -8px rgba(47, 214, 113, 0.35); }
.link-card.status-offline { border-color: var(--color-danger); box-shadow: 0 0 0 1px rgba(240, 72, 72, 0.12), 0 8px 24px -8px rgba(240, 72, 72, 0.35); }
.link-card.status-unchecked { border-color: var(--color-border); }

.link-card-top { display: flex; align-items: center; gap: 10px; }
.link-card-favicon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--color-muted-soft);
    flex-shrink: 0;
    object-fit: cover;
}
.link-card-slug { font-family: var(--mono); font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-card-title { font-size: 12px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-card-status { margin-left: auto; flex-shrink: 0; }

.link-card-url {
    font-size: 12.5px;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.link-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 8px;
    gap: 8px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--color-border-soft);
}
.link-card-date { font-size: 11.5px; color: var(--color-text-muted); font-family: var(--mono); }
.link-card-actions { display: flex; gap: 4px; }
.link-card-actions button, .link-card-actions .btn-icon-link {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface-raised);
    color: var(--color-text-muted);
    cursor: pointer;
}
.link-card-actions button:hover, .link-card-actions .btn-icon-link:hover { color: var(--color-text); background: var(--color-border); }
.link-card-actions svg { width: 14px; height: 14px; }
.link-card-actions form { display: contents; }

/* ---------- Misc ---------- */

.kv { display: flex; flex-direction: column; gap: 2px; }
.kv .k { font-size: 12px; color: var(--color-text-muted); }
.kv .v { font-weight: 600; }

code.token {
    display: block;
    background: #05070b;
    color: var(--color-success);
    border: 1px solid var(--color-border);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--mono);
    word-break: break-all;
}

.section-gap { margin-bottom: 28px; }

@media (max-width: 860px) {
    .app-shell { grid-template-columns: 1fr; }
    .mobile-menu-btn { display: flex; }
    .sidebar-close { display: block; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 56;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .sidebar.is-open { transform: translateX(0); }
    .main { padding: 20px; }
}
