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

:root {
    --bg: #f0f4f8;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.page {
    max-width: 680px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

.page--center {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.page--center .page-inner {
    width: 100%;
    max-width: 400px;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.brand h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

/* Header */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 2rem;
}

.top-bar .brand {
    margin-bottom: 0;
}

/* Cards & sections */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.section-title {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    font-weight: 600;
}

.section-hint {
    margin: 0 0 1rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.75rem;
}

.list-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.link-count {
    font-size: 0.8rem;
    color: var(--muted);
    background: var(--bg);
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
}

/* Forms */
label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.875rem;
}

input[type="text"],
input[type="password"],
input[type="url"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input::placeholder {
    color: #94a3b8;
}

.add-form {
    display: flex;
    gap: 0.625rem;
}

.add-form input {
    flex: 1;
    min-width: 0;
}

.login-form button[type="submit"] {
    width: 100%;
    margin-top: 0.25rem;
}

/* Buttons */
button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.7rem 1.1rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, transform 0.1s;
}

button:hover,
.btn:hover {
    background: var(--primary-hover);
}

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

.btn-sm {
    padding: 0.5rem 0.85rem;
    font-size: 0.8125rem;
}

.btn-secondary {
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 0.5rem 0.85rem;
}

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

.btn-ghost.copied {
    color: var(--success);
    border-color: var(--success-border);
    background: var(--success-bg);
}

.btn-icon {
    padding: 0.5rem;
    min-width: 36px;
}

/* Alerts */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.9375rem;
}

.alert-error {
    color: var(--error);
    background: var(--error-bg);
    border: 1px solid var(--error-border);
}

.alert-success {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid var(--success-border);
}

/* Link list */
.link-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.link-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.125rem;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 0.5rem 1rem;
    align-items: center;
}

.link-meta {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.link-domain {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-date {
    font-size: 0.8125rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.link-date::before {
    content: "·";
    margin-right: 0.5rem;
    color: var(--border);
}

.link-preview {
    grid-column: 1 / -1;
    grid-row: 2;
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.8125rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--bg);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
}

.link-actions {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    gap: 0.375rem;
    flex-shrink: 0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    line-height: 1;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
}

.empty-state strong {
    display: block;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 0.35rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.page-info {
    font-size: 0.875rem;
    color: var(--muted);
    min-width: 7rem;
    text-align: center;
}

/* Mobile */
@media (max-width: 540px) {
    .page {
        padding: 1.25rem 1rem 2rem;
    }

    .top-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .top-bar .btn-secondary {
        align-self: flex-start;
    }

    .add-form {
        flex-direction: column;
    }

    .add-form button {
        width: 100%;
    }

    .link-item {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .link-meta {
        grid-row: 1;
    }

    .link-actions {
        grid-column: 1;
        grid-row: 3;
        justify-content: flex-start;
    }

    .link-preview {
        grid-row: 2;
    }

    .pagination .btn {
        flex: 1;
        min-width: 0;
    }
}
