/* ==================== CSS VARIABLES ==================== */
:root {
    --transcend-blue: #2c5aa0;
    --transcend-blue-dark: #1e4278;
    --transcend-light: #e8f0f8;
    --metric-green: #27ae60;
    --danger-red: #dc2626;
    --warning-amber: #f59e0b;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --bg-primary: #f9fafb;
    --bg-card: #ffffff;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
}

/* ==================== RESET & BASE ==================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
}

/* ==================== LAYOUT ==================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ==================== HEADER ==================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border-color);
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-section a {
    display: flex;
    align-items: center;
}

.logo-section img {
    height: 32px;
    width: auto;
}

.logo-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
}

.logo-subtitle {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s ease;
}

.logo-subtitle:hover {
    color: var(--transcend-blue);
}

.logo-subtitle.active {
    color: var(--transcend-blue);
    font-weight: 600;
}

.nav-link {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s ease;
}

.nav-link:hover {
    color: var(--transcend-blue);
}

.nav-link.active {
    color: var(--transcend-blue);
    font-weight: 600;
}

.auth-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-photo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--transcend-blue);
    color: white;
}

.btn-primary:hover {
    background: var(--transcend-blue-dark);
}

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

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

/* ==================== BACK LINK ==================== */
.back-link {
    display: inline-block;
    color: var(--transcend-blue);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 16px;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--transcend-blue-dark);
    text-decoration: underline;
}

/* ==================== TOOL BRIEF ==================== */
.tool-brief {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.tool-brief > div {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
    min-width: 0;
}

.brief-label {
    display: block;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.7px;
    text-transform: uppercase;
    color: var(--transcend-blue);
    margin-bottom: 5px;
}

.tool-brief strong {
    display: block;
    font-size: 0.82rem;
    line-height: 1.35;
}

/* ==================== STATES ==================== */
#loadingState, #authRequired, #accessDenied {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    padding: 40px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--transcend-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-copy {
    margin-top: 16px;
    color: var(--text-secondary);
}

.state-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.state-title {
    margin-bottom: 12px;
}

.state-copy {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* ==================== STATS GRID ==================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.load-error {
    background: #fef3c7;
    border: 1px solid var(--warning-amber);
    border-radius: var(--radius-md);
    color: #92400e;
    font-size: 0.9rem;
    margin-bottom: 20px;
    padding: 12px 16px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-value.green { color: var(--metric-green); }
.stat-value.amber { color: var(--warning-amber); }
.stat-value.red { color: var(--danger-red); }

.stat-subtext {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ==================== CAMPAIGNS TABLE ==================== */
.section-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.table-container {
    overflow-x: auto;
}

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

th, td {
    padding: 14px 16px;
    text-align: left;
}

th {
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

td {
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

tr:hover {
    background: var(--bg-primary);
}

.subject-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.metric-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.metric-badge.green {
    background: #dcfce7;
    color: #166534;
}

.metric-badge.amber {
    background: #fef3c7;
    color: #92400e;
}

.metric-badge.red {
    background: #fee2e2;
    color: #991b1b;
}

.metric-badge.neutral {
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.date-cell {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state-title {
    margin-bottom: 8px;
}

.empty-state-code-wrap {
    margin-top: 16px;
    font-size: 0.9rem;
}

.empty-state-code {
    background: var(--bg-primary);
    padding: 4px 8px;
    border-radius: 4px;
}

.section-note {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ==================== EVENTS TABLE ==================== */
.event-type {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.event-type.open {
    background: #e0f2fe;
    color: #0369a1;
}

.event-type.click {
    background: #dcfce7;
    color: #166534;
}

.link-url {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ==================== FOOTER ==================== */
footer {
    text-align: center;
    padding: 40px 20px;
    border-top: 1px solid var(--border-color);
    margin-top: 40px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.footer-note {
    margin-top: 8px;
}

/* ==================== REFRESH BUTTON ==================== */
.refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--transcend-light);
    color: var(--transcend-blue);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    background: var(--transcend-blue);
    color: white;
}

.refresh-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .logo-section {
        flex-wrap: wrap;
        justify-content: center;
    }

    .tool-brief {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .section-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .tool-brief {
        grid-template-columns: 1fr;
    }
}
