:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-bg: #f7f9fc;
    --color-surface: #ffffff;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-success: #10b981;
    --color-error: #ef4444;
    --radius-lg: 1.25rem;
    --radius-md: 0.75rem;
    --radius-sm: 0.5rem;
    --shadow: 0 20px 45px rgba(37, 99, 235, 0.12);
    --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background: var(--color-bg);
    color: #0f172a;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

a.link {
    color: var(--color-primary);
    font-weight: 500;
}

a.link:hover {
    text-decoration: underline;
}

.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.65rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn.primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff;
    box-shadow: 0 12px 25px rgba(37, 99, 235, 0.35);
}

.btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(37, 99, 235, 0.4);
}

.btn.secondary {
    background: rgba(37, 99, 235, 0.12);
    color: var(--color-primary);
}

.btn.ghost {
    background: transparent;
    color: var(--color-primary);
}

.btn.danger {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-error);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: var(--color-surface);
    padding: 3rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    max-width: 420px;
    width: 100%;
}

.brand .logo {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--color-primary);
}

.brand .tagline {
    margin: 0.35rem 0 2rem;
    color: var(--color-muted);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form label {
    font-weight: 600;
}

.auth-form input {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 1rem;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
}

.alert {
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert p {
    margin: 0.25rem 0;
}

.alert-success {
    background: rgba(16, 185, 129, 0.12);
    color: var(--color-success);
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-error);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.topbar .logo {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.inline-form {
    display: inline;
}

.edit-link-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.edit-link-form input[type="url"] {
    width: 220px;
    max-width: 100%;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.edit-link-form .btn {
    white-space: nowrap;
}

.dashboard {
    padding: 2.5rem;
}

.tabs {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-list {
    display: flex;
    flex-wrap: wrap;
    background: rgba(37, 99, 235, 0.08);
    border-bottom: 1px solid var(--color-border);
}

.tab-btn {
    flex: 1 1 220px;
    background: transparent;
    border: none;
    padding: 1.15rem 1.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-muted);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.tab-btn:hover,
.tab-btn:focus {
    color: #0f172a;
}

.tab-btn.active {
    color: #0f172a;
    background: #fff;
    box-shadow: inset 0 -3px 0 var(--color-primary);
}

.tab-panel {
    display: none;
    padding: 2rem;
}

.tab-panel.active {
    display: block;
}

.profile-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.shortener h1 {
    margin-top: 0;
    font-size: 2rem;
}

.subtitle {
    color: var(--color-muted);
    margin-bottom: 1.5rem;
}

.shortener-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.shortener-primary-row {
    display: flex;
    gap: 1rem;
}

.shortener-primary-row input {
    flex: 1;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 1rem;
}

.shortener-primary-row input:focus,
.shortener-options input:focus,
.edit-link-form input[type="url"]:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.shortener-options {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.shortener-options label {
    font-weight: 600;
}

.shortener-options input {
    width: 220px;
    max-width: 100%;
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 0.95rem;
}

.field-hint {
    margin: 0;
    color: var(--color-muted);
    font-size: 0.85rem;
}

.result-card h2 {
    margin-top: 0;
    margin-bottom: 1rem;
}

.result-row {
    display: flex;
    gap: 0.75rem;
}

.result-row input {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
}

.qr-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    margin-top: 1.5rem;
}

.qr-image {
    width: 160px;
    height: 160px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: #fff;
}

.qr-actions {
    display: flex;
    gap: 0.75rem;
}

.short-link {
    font-weight: 600;
    color: var(--color-primary);
    word-break: break-all;
}

.qr-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    z-index: 1000;
}

.qr-modal.is-visible {
    display: flex;
}

.qr-modal-backdrop {
    position: absolute;
    inset: 0;
}

.qr-modal-content {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2.25rem;
    box-shadow: 0 30px 60px rgba(15, 23, 42, 0.45);
    text-align: center;
    max-width: 520px;
    width: 100%;
}

.qr-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-muted);
}

.qr-modal-image {
    width: min(70vw, 360px);
    height: auto;
    margin: 1rem auto 1.25rem;
}

.qr-modal-link {
    display: block;
    font-weight: 600;
    color: var(--color-primary);
    word-break: break-all;
    margin-bottom: 1.5rem;
}

.qr-modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

body.modal-open {
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

table thead {
    background: rgba(37, 99, 235, 0.05);
}

table th,
table td {
    text-align: left;
    padding: 0.85rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.original-url {
    max-width: 100px;
}

.original-url a {
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

table td.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.empty-state {
    color: var(--color-muted);
    font-style: italic;
}

.profile {
    padding: 2.5rem;
}

.profile-card h1 {
    margin-top: 0;
}

.profile-info {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.muted {
    color: var(--color-muted);
    font-size: 0.9rem;
}

.admin-user-row.is-expanded > td {
    border-bottom: none;
}

.admin-user-history > td {
    padding: 0;
    border-top: none;
}

.admin-history-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
}

.admin-history-card h4 {
    margin: 0 0 0.75rem;
}

.admin-history-card .table-wrapper {
    margin-top: 0.75rem;
}

.admin-user-toggle {
    margin-left: 0.5rem;
}

.page-404 {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.35));
    color: #0f172a;
}

.page-404 .container {
    text-align: center;
}

.page-404 h1 {
    font-size: 5rem;
    margin-bottom: 0.5rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 768px) {
    .topbar {
        padding: 1rem 1.25rem;
    }

    .dashboard,
    .profile {
        padding: 1.25rem;
    }

    .tab-panel,
    .profile-card {
        padding: 1.5rem;
    }

    .shortener-primary-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .shortener-primary-row .btn {
        width: 100%;
    }

    .shortener-options {
        align-items: flex-start;
    }

    .shortener-options input,
    .edit-link-form input[type="url"] {
        width: 100%;
    }

    .result-row {
        flex-direction: column;
    }

    .qr-actions {
        flex-direction: column;
        width: 100%;
    }

    .qr-actions .btn {
        width: 100%;
    }

    .qr-modal-actions {
        flex-direction: column;
    }

    .qr-modal-actions .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 2rem;
    }

    .topbar-actions {
        flex-direction: column;
        align-items: flex-start;
    }

    table th,
    table td {
        font-size: 0.85rem;
    }
}
