:root {
    --font: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --bg: #0b0f1a;
    --bg-elevated: #111827;
    --surface: #151c2c;
    --surface-hover: #1a2236;
    --border: rgba(148, 163, 184, 0.12);
    --border-strong: rgba(148, 163, 184, 0.22);
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.35);
    --accent: #22d3ee;
    --success: #34d399;
    --warning: #fb923c;
    --danger: #f87171;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.45);
    --nav-height: 64px;
    --transition: 160ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

a:hover {
    color: var(--accent);
}

img {
    max-width: 100%;
}

/* ── Layout ── */

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 32px 24px 48px;
}

.app-main--narrow {
    max-width: 720px;
}

/* ── Navbar ── */

.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--nav-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(11, 15, 26, 0.82);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.navbar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    letter-spacing: -0.02em;
}

.navbar__brand:hover {
    color: var(--text);
}

.navbar__logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid;
    place-items: center;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.navbar__logo svg {
    width: 18px;
    height: 18px;
    color: white;
}

.navbar__links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
    background: var(--surface);
    color: var(--text);
}

.nav-link.is-active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-hover);
}

.nav-link--muted {
    color: var(--text-subtle);
}

/* ── Auth layout ── */

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.auth-hero {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 48px 56px;
    background:
        radial-gradient(ellipse 80% 60% at 20% 40%, rgba(99, 102, 241, 0.22), transparent),
        radial-gradient(ellipse 60% 50% at 80% 80%, rgba(34, 211, 238, 0.12), transparent),
        var(--bg-elevated);
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.auth-hero__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 48px;
}

.auth-hero__title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin: 0 0 16px;
    max-width: 18ch;
}

.auth-hero__subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 1.05rem;
    max-width: 36ch;
    line-height: 1.6;
}

.auth-hero__features {
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-feature {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.auth-feature__icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.2);
    display: grid;
    place-items: center;
    color: var(--primary-hover);
}

.auth-feature__icon svg {
    width: 18px;
    height: 18px;
}

.auth-feature__text strong {
    display: block;
    font-size: 0.92rem;
    margin-bottom: 2px;
}

.auth-feature__text span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 32px;
    background: var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.auth-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.auth-card__header h1 {
    margin: 0;
}

.auth-card__lead {
    margin: 0 0 28px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ── Demo credentials popover (login) ── */

.demo-trigger-wrap {
    position: relative;
    flex-shrink: 0;
}

.demo-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.demo-pill:hover,
.demo-pill[aria-expanded="true"] {
    color: var(--text);
    border-color: rgba(99, 102, 241, 0.45);
    background: rgba(99, 102, 241, 0.08);
}

.demo-pill__icon {
    width: 14px;
    height: 14px;
    opacity: 0.85;
}

.demo-popover {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: min(320px, calc(100vw - 48px));
    padding: 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.demo-popover.is-open {
    display: block;
}

.demo-popover[hidden] {
    display: none;
}

.demo-popover__title {
    margin: 0 0 14px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.demo-cred {
    margin-bottom: 12px;
}

.demo-cred__label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-subtle);
}

.demo-cred__value {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--border);
    font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
    font-size: 0.82rem;
    color: var(--text);
    word-break: break-all;
}

.demo-popover .btn {
    margin-top: 4px;
}

/* ── Components ── */

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    margin: 0 0 6px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

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

.card + .card {
    margin-top: 16px;
}

.card__title {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 600;
}

.card__desc {
    margin: 0 0 20px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.field {
    margin-bottom: 18px;
}

.field:last-of-type {
    margin-bottom: 0;
}

.field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input {
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input::placeholder {
    color: var(--text-subtle);
}

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

.input-group {
    display: flex;
    gap: 8px;
}

.input-group .input {
    flex: 1;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    white-space: nowrap;
}

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

.btn--primary {
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    color: white;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn--primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--primary));
}

.btn--secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.btn--secondary:hover {
    background: var(--surface-hover);
}

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

.btn--ghost:hover {
    background: var(--surface);
    color: var(--text);
}

.btn--block {
    width: 100%;
    margin-top: 8px;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    margin-bottom: 16px;
    display: none;
}

.alert.is-visible {
    display: block;
}

.alert--error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.25);
    color: #fca5a5;
}

.alert--success {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.25);
    color: #6ee7b7;
}

.alert--info {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
}

.auth-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ── Stats grid ── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.stat-card__icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.stat-card__icon--links {
    background: rgba(99, 102, 241, 0.14);
    color: var(--primary-hover);
}

.stat-card__icon--clicks {
    background: rgba(34, 211, 238, 0.12);
    color: var(--accent);
}

.stat-card__icon svg {
    width: 20px;
    height: 20px;
}

.stat-card__label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-card__value {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

/* ── Table ── */

.table-wrap {
    overflow-x: auto;
    margin-top: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--text-subtle);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.data-table td {
    vertical-align: middle;
}

.data-table .code-link {
    font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 500;
}

.data-table .url-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

/* ── Shortener result ── */

.result-box {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    display: none;
}

.result-box.is-visible {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.result-box__url {
    font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
    font-size: 0.9rem;
    color: var(--accent);
    word-break: break-all;
}

.result-box__url a {
    color: inherit;
}

.result-box__url a:hover {
    text-decoration: underline;
}

/* ── Toast ── */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 200ms ease, transform 200ms ease;
    pointer-events: none;
    z-index: 100;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Empty state ── */

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.empty-state a {
    font-weight: 500;
}

/* ── Toolbar & search ── */

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

.search-box {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 360px;
}

.search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-subtle);
    pointer-events: none;
}

.search-box .input {
    padding-left: 38px;
}

/* ── Row actions ── */

.actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.btn--sm {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.btn--danger {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(248, 113, 113, 0.25);
}

.btn--danger:hover {
    background: rgba(248, 113, 113, 0.2);
}

/* ── Modal ── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.modal-backdrop.is-open {
    display: flex;
}

.modal {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.modal p {
    margin: 0 0 18px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

/* ── Link detail ── */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.breadcrumb a {
    color: var(--text-muted);
}

.breadcrumb a:hover {
    color: var(--primary-hover);
}

.link-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.link-hero__code {
    font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin: 0 0 6px;
}

.link-hero__dest {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    word-break: break-all;
    max-width: 560px;
}

.link-hero__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.analytics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.chart-card {
    margin-top: 16px;
}

.chart-wrap {
    position: relative;
    height: 260px;
    margin-top: 8px;
}

.breakdown-list {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
}

.breakdown-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.88rem;
}

.breakdown-bar {
    grid-column: 1 / -1;
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 999px;
    overflow: hidden;
}

.breakdown-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 999px;
}

.period-tabs {
    display: inline-flex;
    gap: 4px;
    background: var(--bg-elevated);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.period-tabs button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
}

.period-tabs button.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ── QR code ── */

.qr-card {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.qr-card__image {
    width: 160px;
    height: 160px;
    padding: 10px;
    background: white;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.qr-card__image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.qr-card__body {
    flex: 1;
    min-width: 200px;
}

.qr-card__body p {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

/* ── Live analytics ── */

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #6ee7b7;
    background: rgba(52, 211, 153, 0.12);
    border: 1px solid rgba(52, 211, 153, 0.25);
}

.live-badge--off {
    color: var(--text-subtle);
    background: var(--bg-elevated);
    border-color: var(--border);
}

.live-badge__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
    animation: live-pulse 1.4s ease-in-out infinite;
}

.live-badge--off .live-badge__dot {
    background: var(--text-subtle);
    box-shadow: none;
    animation: none;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ── Responsive ── */

@media (max-width: 900px) {
    .auth-page {
        grid-template-columns: 1fr;
    }

    .auth-hero {
        display: none;
    }

    .auth-panel {
        min-height: 100vh;
    }
}

@media (max-width: 640px) {
    .navbar {
        padding: 0 16px;
    }

    .navbar__links .nav-link:not(.nav-link--logout) {
        display: none;
    }

    .app-main {
        padding: 24px 16px 40px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .input-group {
        flex-direction: column;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .data-table .actions {
        flex-direction: column;
        align-items: flex-start;
    }
}
