:root {
    /* Brand Colors per PRD */
    --brand-bg: #fbf9ed;
    /* Creme/Off-white */
    --brand-primary: #facb02;
    /* Amarelo Dourado */
    --brand-dark: #121e2c;
    /* Azul Profundo */
    --brand-white: #ffffff;

    /* Functional Colors */
    --text-main: #121e2c;
    /* Uses Dark Blue for text on light mode */
    --text-muted: #546e7a;
    --border-light: rgba(18, 30, 44, 0.1);

    /* UI Elements */
    --card-bg: #ffffff;
    --card-shadow: 0 4px 20px rgba(18, 30, 44, 0.08);
    --btn-shadow: 0 4px 14px rgba(250, 203, 2, 0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    /* Aliases for compatibility */
    --bg-card: var(--card-bg);
    --bg-body: var(--brand-bg);
    --bg-input-disabled: #f5f5f5;
    color-scheme: light;
}

[data-theme="dark"] {
    /* Dark Mode Overrides */
    --brand-bg: #121e2c;
    /* Azul Profundo Background */
    --text-main: #fbf9ed;
    /* Creme Text */
    --text-muted: #aab2bd;
    --card-bg: #1a2634;
    /* Slightly lighter than bg */
    --border-light: rgba(251, 249, 237, 0.1);
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);

    /* Aliases for compatibility */
    --bg-card: var(--card-bg);
    --bg-body: var(--brand-bg);
    --bg-input-disabled: #2c3e50;
    color-scheme: dark;
}

/* Badge Utility */
.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--brand-bg);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    /* Fix horizontal scrollbar */
}

main.container {
    flex: 1;
}

/* Typography & Layout */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

/* ... existing code ... */

/* Icon Fixes */
button svg,
a svg {
    display: inline-block;
    vertical-align: middle;
}

.action-btn svg {
    width: 18px;
    height: 18px;
}

h1,
h2,
h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

h2 {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}

/* Header */
header {
    background: var(--brand-bg);
    /* Ensure background is solid */
    padding: 15px 0;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-light);
    width: 100%;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    /* Force full width */
    max-width: 1100px;
    /* Respect container max */
    margin: 0 auto;
    /* Center */
}

.logo {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.05em;
}

.logo span {
    color: var(--brand-primary);
}

nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

nav a {
    font-weight: 500;
    font-size: 0.95rem;
}

nav a:hover,
nav a.active {
    color: var(--brand-primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
}

.btn-primary {
    background-color: var(--brand-primary);
    color: var(--brand-dark);
    box-shadow: var(--btn-shadow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(250, 203, 2, 0.6);
}

.btn-danger {
    background-color: #ff6b6b;
    color: white;
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn-gold {
    background: linear-gradient(135deg, #ffd700 0%, #fdb931 100%);
    color: var(--brand-dark);
    border: none;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 5px rgba(253, 185, 49, 0.4);
    display: inline-block;
    margin-top: 5px;
    text-decoration: none;
}

.btn-gold:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(253, 185, 49, 0.6);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-light);
    margin-bottom: 24px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

input,
select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    color: var(--text-main);
    font-size: 1rem;
    line-height: inherit;
    transition: border-color 0.2s;
}

.input-sm,
.select-sm {
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: var(--radius-md);
}

input:disabled,
textarea:disabled {
    background: var(--bg-input-disabled);
    cursor: not-allowed;
    color: var(--text-muted);
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
}

textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    color: var(--text-main);
    font-size: 1rem;
    transition: border-color 0.2s;
    font-family: 'Inter', sans-serif;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-main);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s;
    display: inline-flex;
    /* Ensure visibility */
    align-items: center;
    justify-content: center;
}


/* Dashboard Action Buttons (Fixed & Pro) */
.action-btn {
    background: var(--bg-card);
    /* Consistent background */
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    /* Slightly softer */
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    /* Fixed square */
    height: 34px;
    /* Fixed square */
    padding: 0;
    /* Remove padding to trust flex centering */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.action-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    /* Consistent weight */
    display: block;
}

.action-btn:hover {
    background: var(--brand-primary);
    color: #fff;
    border-color: var(--brand-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(250, 203, 2, 0.3);
}

.action-btn.delete:hover {
    background: #ff6b6b;
    border-color: #ff6b6b;
    color: white;
    box-shadow: 0 4px 8px rgba(255, 107, 107, 0.3);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.stat-box {
    background: var(--card-bg);
    padding: 32px;
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--border-light);
    box-shadow: var(--card-shadow);
    transition: transform 0.2s;
}

.stat-box:hover {
    transform: translateY(-5px);
}

.stat-number {
    display: block;
    font-size: 3rem;
    font-weight: 800;
    color: var(--brand-primary);
    line-height: 1;
    margin-bottom: 8px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    text-align: left;
    padding: 16px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-light);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

tr {
    transition: all 0.2s ease;
}

tr:hover td {
    background-color: rgba(250, 203, 2, 0.03);
    /* Subtle yellow tint */
    border-bottom-color: rgba(250, 203, 2, 0.2);
}

tr:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    /* transform: scale(1.005); Removed to prevent scrollbar jitter */
    z-index: 10;
    position: relative;
    background: var(--card-bg);
}

tr:last-child td {
    border-bottom: none;
}

/* Footer */
footer {
    margin-top: auto;
    padding: 60px 0 30px;
    text-align: center;
    border-top: 1px solid var(--border-light);
}

.legal-links a {
    margin: 0 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.legal-links a:hover {
    color: var(--brand-primary);
    text-decoration: underline;
}

/* Alerts */
.alert {
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    font-weight: 500;
}

.alert-error {
    background-color: rgba(255, 107, 107, 0.1);
    color: #fa5252;
    border: 1px solid rgba(255, 107, 107, 0.2);
}

.alert-success {
    background-color: rgba(64, 192, 87, 0.1);
    color: #2f9e44;
    border: 1px solid rgba(64, 192, 87, 0.2);
}

/* Dark Mode Toggle */
#theme-toggle {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
}

#theme-toggle:hover {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: var(--brand-dark);
}

/* QR Code Modal */
.qr-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.qr-modal-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-light);
    max-width: 360px;
    width: 90%;
    animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== Link Cards Grid ========== */
.links-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.view-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 3px;
}

.view-toggle button {
    background: none;
    border: none;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.view-toggle button.active {
    background: var(--brand-primary);
    color: var(--brand-dark);
    font-weight: 600;
}

.links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.link-card {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
}

.link-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.link-card.expired {
    opacity: 0.6;
}

.link-card-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.link-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    line-height: 1.4;
}

/* Link Form Grid (New Layout) */
.link-form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    align-items: flex-end;
    /* Aligns input fields even if labels vary */
}

.link-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 !important;
    /* Override inline styles if any leak */
}

/* Full Width for URL */
.link-form-group.full-width {
    grid-column: 1 / -1;
}

/* Two-thirds width utility if needed */
.link-form-group.two-thirds {
    grid-column: span 2;
}

/* Action button area */
.link-form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .link-form-grid {
        grid-template-columns: 1fr;
        /* Stack everything */
    }

    .link-form-group.two-thirds {
        grid-column: span 1;
    }

    .link-form-actions button {
        width: 100%;
    }
}

.link-badge-category {
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    transition: all 0.2s;
}

.link-badge-category:hover {
    background: var(--brand-primary);
    color: #fff;
    border-color: var(--brand-primary);
}

.link-badge-expiry {
    background: var(--brand-primary);
    color: var(--brand-dark);
}

.link-badge-expired {
    background: #ef4444;
    color: #fff;
}

.link-badge-password {
    background: #6366f1;
    color: #fff;
}

.link-card-main {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.link-card-favicon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.link-card-favicon img {
    width: 20px;
    height: 20px;
}

.link-card-info {
    flex: 1;
    min-width: 0;
}

.link-card-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-card-url {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-card-short {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    min-width: 0;
    /* Allow flex children to shrink */
}

.link-card-short a {
    color: var(--brand-primary);
    font-weight: 600;
    font-size: 0.85rem;
    text-decoration: none;

    /* Truncation magic */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 0 1 auto;
    /* Grow only as needed, shrink if needed */
    display: block;
}

.link-card-short a:hover {
    text-decoration: underline;
}

.link-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.link-card-clicks {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

.link-card-actions {
    display: flex;
    gap: 6px;
}

/* List Mode */
.links-grid.list-mode {
    grid-template-columns: 1fr;
    gap: 8px;
}

.links-grid.list-mode .link-card {
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    gap: 16px;
}

.links-grid.list-mode .link-card-badges {
    position: absolute;
    top: 8px;
    right: 12px;
}

.links-grid.list-mode .link-card-main {
    flex: 1;
    min-width: 0;
}

.links-grid.list-mode .link-card-meta {
    border-top: none;
    padding-top: 0;
    flex-shrink: 0;
    gap: 12px;
}

@media (max-width: 768px) {
    .links-grid {
        grid-template-columns: 1fr;
    }

    .links-grid.list-mode .link-card {
        flex-direction: column;
        align-items: stretch;
    }

    .links-grid.list-mode .link-card-meta {
        border-top: 1px solid var(--border-light);
        padding-top: 10px;
    }
}

/* Profile Stats */
.profile-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 20px 15px;
    text-align: center;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--brand-primary);
    margin-bottom: 4px;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}