/* GSC Email Analytics — Dashboard Styles */
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500,600,700");

:root {
    --brand:        #1E40AF;
    --brand-light:  #3B82F6;
    --brand-pale:   #DBEAFE;
    --success:      #059669;
    --success-pale: #D1FAE5;
    --warning:      #D97706;
    --warning-pale: #FEF3C7;
    --danger:       #DC2626;
    --purple:       #7C3AED;
    --purple-pale:  #EDE9FE;
    --bg:           #F1F5F9;
    --surface:      #FFFFFF;
    --border:       #E2E8F0;
    --text:         #1E293B;
    --text-muted:   #64748B;
    --sidebar-bg:   #0F172A;
    --sidebar-text: #94A3B8;
    --radius:       10px;
    --shadow:       0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

body {
    font-family: 'Roboto', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    min-height: 100vh;
    position: fixed;
    left: 0; top: 0;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 200;
}

.main {
    margin-left: 240px;
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 20px 32px;
}

.page-header h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.page-header p {
    font-size: .875rem;
    color: var(--text-muted);
    margin: 3px 0 0;
}

.content {
    padding: 28px 32px;
    flex: 1;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    text-decoration: none;
}

.sidebar-brand img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 6px;
    background: rgba(255,255,255,.08);
    padding: 4px;
}

.sidebar-brand-text strong {
    display: block;
    font-size: .9rem;
    font-weight: 700;
    color: #F8FAFC;
    line-height: 1.2;
}

.sidebar-brand-text span {
    font-size: .7rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.sidebar-nav {
    flex: 1;
    padding: 14px 12px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 7px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    margin-bottom: 3px;
}

.sidebar-nav a i {
    width: 16px;
    text-align: center;
    font-size: .85rem;
    opacity: .8;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,.06);
    color: #F1F5F9;
}

.sidebar-nav a.active {
    background: var(--brand-light);
    color: #fff;
}

.sidebar-nav a.active i { opacity: 1; }

.sidebar-user {
    padding: 14px 18px 18px;
    border-top: 1px solid rgba(255,255,255,.07);
}

.sidebar-user .su-name {
    font-size: .8rem;
    font-weight: 600;
    color: #E2E8F0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .su-email {
    display: block;
    font-size: .72rem;
    color: #475569;
    margin: 2px 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 6px;
    color: var(--sidebar-text);
    font-size: .75rem;
    cursor: pointer;
    transition: background .15s, color .15s;
    font-family: inherit;
}

.btn-logout:hover {
    background: rgba(220,38,38,.2);
    color: #FCA5A5;
    border-color: rgba(220,38,38,.3);
}

/* ── Stats Cards ─────────────────────────────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px 22px 20px;
    box-shadow: var(--shadow);
    border-top: 3px solid var(--card-color, var(--brand-light));
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-icon {
    width: 38px; height: 38px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    margin-bottom: 6px;
}

.stat-icon.blue   { background: var(--brand-pale);   color: var(--brand); }
.stat-icon.green  { background: var(--success-pale);  color: var(--success); }
.stat-icon.purple { background: var(--purple-pale);   color: var(--purple); }
.stat-icon.amber  { background: var(--warning-pale);  color: var(--warning); }

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

.stat-label {
    font-size: .78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 500;
}

/* ── Charts ──────────────────────────────────────────────────────────────────── */

.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px 22px 16px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.chart-card:last-child { margin-bottom: 0; }

.chart-card h3 {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.chart-card h3 i { color: var(--brand-light); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h3 { margin: 0; }

.btn-link {
    font-size: .8rem;
    color: var(--brand-light);
    text-decoration: none;
    font-weight: 500;
}

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

/* ── Tables ──────────────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
    border-radius: 0 0 var(--radius) var(--radius);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

.data-table thead th {
    background: #F8FAFC;
    padding: 10px 16px;
    text-align: left;
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 11px 16px;
    border-bottom: 1px solid #F1F5F9;
    color: var(--text);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr.clickable {
    cursor: pointer;
    transition: background .1s;
}

.data-table tbody tr.clickable:hover { background: #F8FAFC; }

.data-table code {
    font-size: .78rem;
    color: var(--brand);
    background: var(--brand-pale);
    padding: 2px 6px;
    border-radius: 4px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-pale);
    color: var(--brand);
    font-weight: 700;
    font-size: .72rem;
    padding: 3px 9px;
    border-radius: 100px;
    min-width: 28px;
}

.tbl-empty, .tbl-error, .tbl-load-more {
    text-align: center;
    padding: 20px 16px !important;
    color: var(--text-muted);
    font-style: italic;
}

.tbl-error { color: var(--danger); }

.btn-load-more {
    padding: 7px 20px;
    background: var(--brand-pale);
    color: var(--brand);
    border: 1px solid #BFDBFE;
    border-radius: 6px;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s, color .15s;
}

.btn-load-more:hover {
    background: var(--brand-light);
    color: #fff;
    border-color: var(--brand-light);
}

/* htmx loading indicator */
.htmx-request .btn-load-more { opacity: .6; pointer-events: none; }

/* ── Loading Spinner ─────────────────────────────────────────────────────────── */

.tbl-loading {
    text-align: center;
    padding: 24px 16px !important;
    color: var(--text-muted);
}

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

.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--brand-light);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

/* ── Login Page ──────────────────────────────────────────────────────────────── */

.login-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, #0F172A 0%, #1E3A8A 55%, #1D4ED8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 44px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px rgba(0,0,0,.35);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 30px;
}

.login-brand img {
    width: 46px;
    height: 46px;
    object-fit: contain;
}

.login-brand-text strong {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

.login-brand-text span {
    font-size: .78rem;
    color: var(--text-muted);
}

.login-card h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 6px;
}

.login-card .login-sub {
    font-size: .85rem;
    color: var(--text-muted);
    margin: 0 0 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .9rem;
    font-family: inherit;
    color: var(--text);
    background: #FAFAFA;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
    background: #fff;
}

.btn-primary {
    width: 100%;
    padding: 11px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
    margin-top: 8px;
}

.btn-primary:hover { background: #1D4ED8; }

.login-error {
    background: #FEE2E2;
    border: 1px solid #FECACA;
    color: var(--danger);
    font-size: .82rem;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 7px;
}

/* ── Email Detail ────────────────────────────────────────────────────────────── */

.detail-meta {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.detail-meta h3 {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin: 0 0 14px;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.meta-item label {
    display: block;
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 3px;
}

.meta-item p {
    font-size: .875rem;
    color: var(--text);
    margin: 0;
    word-break: break-all;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .82rem;
    color: var(--brand-light);
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 18px;
}

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

/* ── Utility ─────────────────────────────────────────────────────────────────── */

.mb-0 { margin-bottom: 0 !important; }
.mt-4 { margin-top: 16px; }
