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

:root {
    --brand-900: #244127;
    --brand-800: #2f5431;
    --brand-700: #3a6a3b;
    --brand-600: #4b804c;
    --brand-500: #5f9a61;
    --brand-200: #d8e8d8;
    --brand-100: #edf5ed;
    --brand-50: #f6faf6;
    --text-900: #162018;
    --text-700: #334336;
    --text-500: #5d6c60;
    --line-200: #d6e0d7;
    --line-300: #c4d1c6;
    --danger-500: #c0392b;
    --danger-50: #fdf0ee;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow: 0 8px 22px rgba(16, 36, 18, 0.12);
    --shadow-lg: 0 20px 40px rgba(16, 36, 18, 0.18);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text-900);
    background: linear-gradient(180deg, #f7fbf7 0%, #f4f8f4 100%);
    line-height: 1.45;
}

a {
    color: inherit;
}

/* Login */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: radial-gradient(circle at top left, #5f9a61 0%, #335636 42%, #223b25 100%);
}

.login-card {
    width: min(460px, 100%);
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 2rem;
}

.login-header {
    margin-bottom: 1.5rem;
}

.brand-eyebrow {
    margin: 0 0 0.35rem;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand-700);
    font-weight: 700;
}

.login-header h1 {
    margin: 0;
    font-size: 1.45rem;
    line-height: 1.3;
}

.subtitle {
    margin: 0.6rem 0 0;
    color: var(--text-500);
    font-size: 0.95rem;
}

.error-banner {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    background: var(--danger-50);
    color: var(--danger-500);
    border: 1px solid #f6cdc8;
    border-radius: var(--radius-sm);
    padding: 0.8rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.google-btn {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    background: #fff;
    border: 1px solid var(--line-300);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-700);
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.google-btn:hover {
    border-color: var(--brand-500);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.login-points {
    list-style: none;
    margin: 1rem 0 0.6rem;
    padding: 0;
    display: grid;
    gap: 0.4rem;
    color: var(--text-700);
    font-size: 0.9rem;
}

.login-points li::before {
    content: "✓";
    color: var(--brand-600);
    font-weight: 700;
    margin-right: 0.5rem;
}

.domain-note {
    margin: 0.4rem 0 0;
    color: var(--text-500);
    font-size: 0.82rem;
}

/* App layout */
.app-layout {
    min-height: 100vh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.4rem;
    background: linear-gradient(90deg, var(--brand-900), var(--brand-700));
    color: #ecf7ec;
    box-shadow: var(--shadow);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-mark {
    display: inline-flex;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.25);
    font-weight: 700;
}

.brand-copy .brand-eyebrow {
    color: #cae7cb;
    margin: 0;
    font-size: 0.67rem;
}

.header-title {
    margin: 0.15rem 0 0;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 0.3rem 0.55rem 0.3rem 0.35rem;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--brand-900);
    background: #e8f5e9;
}

.user-meta {
    display: grid;
    line-height: 1.15;
}

.user-name {
    font-size: 0.82rem;
    font-weight: 600;
}

.user-email {
    font-size: 0.72rem;
    opacity: 0.85;
}

.admin-badge {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: #cae7cb;
    color: var(--brand-900);
    border-radius: 999px;
    padding: 0.2rem 0.45rem;
}

.logout-btn {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.84rem;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.logout-btn:hover {
    background: #e9f5ea;
    color: var(--brand-900);
}

.main-content {
    max-width: 1080px;
    margin: 0 auto;
    padding: 1.5rem;
}

.card {
    background: var(--white);
    border: 1px solid var(--line-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.section-heading h2 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.section-heading p {
    margin: 0.35rem 0 0;
    color: var(--text-500);
    font-size: 0.9rem;
}

.alert-banner {
    display: flex;
    gap: 0.45rem;
    align-items: center;
    margin-bottom: 1rem;
    border: 1px solid #f4ccc5;
    background: var(--danger-50);
    color: var(--danger-500);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    font-size: 0.9rem;
}

.shorten-section {
    padding: 1rem;
    margin-bottom: 1.2rem;
}

.shorten-form {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.shorten-fields {
    flex: 1;
    display: grid;
    gap: 0.55rem;
    grid-template-columns: minmax(0, 1fr) 220px;
}

.url-input,
.slug-input {
    width: 100%;
    border: 1px solid var(--line-300);
    border-radius: var(--radius-sm);
    padding: 0.72rem 0.86rem;
    font: inherit;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.url-input:focus,
.slug-input:focus {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px rgba(95, 154, 97, 0.18);
}

.shorten-btn {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.1rem;
    background: var(--brand-700);
    color: var(--white);
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.15s ease;
}

.shorten-btn:hover {
    background: var(--brand-800);
    transform: translateY(-1px);
}

.slug-hint {
    margin-top: 0.6rem;
    color: var(--text-500);
    font-size: 0.83rem;
}

.links-section {
    margin-top: 1.1rem;
}

.link-count {
    display: inline-flex;
    min-width: 24px;
    height: 24px;
    margin-left: 0.35rem;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--brand-100);
    color: var(--brand-800);
    font-size: 0.76rem;
}

.links-table-wrap {
    margin-top: 0.75rem;
    border: 1px solid var(--line-200);
    border-radius: var(--radius-md);
    background: var(--white);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.links-table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-500);
    background: var(--brand-50);
    border-bottom: 1px solid var(--line-200);
    padding: 0.72rem 0.9rem;
}

.links-table td {
    border-bottom: 1px solid #eef3ef;
    padding: 0.72rem 0.9rem;
    vertical-align: top;
    font-size: 0.9rem;
}

.links-table tbody tr:hover {
    background: #f7fbf7;
}

.short-link-group {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.short-link {
    color: var(--brand-800);
    font-weight: 600;
    text-decoration: none;
    word-break: break-word;
}

.short-link:hover {
    text-decoration: underline;
}

.copy-btn,
.delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid var(--line-200);
    color: var(--text-500);
    cursor: pointer;
    transition: all 0.15s ease;
}

.copy-btn:hover {
    color: var(--brand-800);
    border-color: var(--brand-500);
    background: var(--brand-100);
}

.copy-btn.copied {
    color: var(--brand-800);
    border-color: var(--brand-600);
}

.original-link {
    color: var(--text-700);
    text-decoration: none;
    word-break: break-all;
}

.original-link:hover {
    text-decoration: underline;
}

.owner-cell {
    min-width: 160px;
}

.owner-name {
    display: block;
    font-weight: 600;
}

.owner-email {
    display: block;
    color: var(--text-500);
    font-size: 0.8rem;
}

.clicks-cell {
    text-align: center;
}

.click-badge {
    display: inline-flex;
    min-width: 28px;
    height: 24px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--brand-100);
    color: var(--brand-900);
    font-weight: 700;
    font-size: 0.78rem;
}

.date-cell {
    color: var(--text-500);
    white-space: nowrap;
    font-size: 0.82rem;
}

.inline-form {
    display: inline;
}

.delete-btn:hover {
    color: var(--danger-500);
    border-color: #f3c4bd;
    background: var(--danger-50);
}

.empty-state {
    margin-top: 0.75rem;
    border: 1px dashed var(--line-300);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--text-500);
    padding: 2.2rem 1rem;
    display: grid;
    justify-items: center;
    gap: 0.8rem;
}

@media (max-width: 900px) {
    .shorten-form {
        flex-direction: column;
        align-items: stretch;
    }

    .shorten-fields {
        grid-template-columns: 1fr;
    }

    .shorten-btn {
        width: 100%;
    }
}

@media (max-width: 740px) {
    .user-email {
        display: none;
    }

    .links-table-wrap {
        overflow-x: auto;
    }

    .links-table {
        min-width: 760px;
    }
}

@media (max-width: 560px) {
    .app-header {
        padding: 0.75rem;
    }

    .header-title {
        font-size: 0.94rem;
    }

    .user-chip {
        padding-right: 0.35rem;
    }

    .main-content {
        padding: 1rem 0.8rem;
    }

    .login-card {
        padding: 1.35rem;
    }
}
