:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --line: #d7dfeb;
    --line-strong: #c8d2e1;
    --text: #101828;
    --muted: #64748b;
    --blue: #2563eb;
    --green: #0f8b4c;
    --yellow: #eab308;
    --red: #dc2626;
    --cyan: #0891b2;
    --ink: #0f172a;
    --shadow: 0 18px 45px rgba(15, 23, 42, .09);
    --shadow-soft: 0 8px 24px rgba(15, 23, 42, .07);
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(rgba(37, 99, 235, .035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 139, 76, .03) 1px, transparent 1px),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 38%, #eef3f8 100%);
    background-size: 42px 42px, 42px 42px, auto;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 0 clamp(16px, 3vw, 32px);
    background: rgba(255, 255, 255, .88);
    border-bottom: 1px solid rgba(199, 210, 226, .85);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .8), 0 14px 32px rgba(15, 23, 42, .06);
    backdrop-filter: blur(14px);
}

.topbar::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--green), var(--blue), var(--cyan), var(--yellow));
    background-size: 240% 100%;
    animation: headerFlow 10s ease infinite;
}

.topbar-inner {
    display: grid;
    grid-template-columns: minmax(230px, 320px) 1fr auto;
    align-items: center;
    gap: 18px;
    min-height: 76px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    transition: transform .18s ease;
}

.brand:hover {
    transform: translateY(-1px);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--green), #12b981);
    color: #fff;
    font-weight: 800;
    box-shadow: 0 10px 24px rgba(15, 139, 76, .24);
}

.brand strong {
    display: block;
    font-size: 20px;
    line-height: 1.2;
}

.brand small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar p, .muted {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    min-width: 0;
    padding: 5px;
    border: 1px solid rgba(215, 223, 235, .82);
    border-radius: 14px;
    background: rgba(248, 250, 252, .72);
}

.nav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 15px;
    border-radius: 10px;
    color: #344054;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}

.nav-link:hover {
    background: #eef4ff;
    color: var(--text);
    transform: translateY(-1px);
}

.nav-link.active {
    background: #fff;
    color: #1455d9;
    box-shadow: var(--shadow-soft);
}

.account-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-pill {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #475467;
    font-weight: 700;
}

.logout-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0 13px;
    border-radius: 10px;
    background: #f2f4f7;
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
    transition: background .18s ease, transform .18s ease;
}

.logout-link:hover {
    background: #fee2e2;
    color: #991b1b;
    transform: translateY(-1px);
}

.container {
    width: min(1220px, calc(100% - 32px));
    margin: 26px auto 48px;
    animation: pageIn .28s ease both;
}

.page-head {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 18px;
    align-items: end;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 7px;
    color: var(--green);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.page-head h2 {
    margin: 0 0 5px;
    font-size: 28px;
    line-height: 1.15;
}

.quick-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(88px, 1fr));
    gap: 10px;
}

.stat-card {
    min-width: 88px;
    padding: 14px 16px;
    border: 1px solid rgba(215, 223, 235, .86);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .82);
    box-shadow: var(--shadow-soft);
    transition: transform .18s ease, box-shadow .18s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin-top: 4px;
    font-size: 24px;
    line-height: 1;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid rgba(215, 223, 235, .86);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .76);
    box-shadow: var(--shadow-soft);
}

.search-form {
    display: flex;
    gap: 8px;
    flex: 1;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 13px;
    font: inherit;
    background: rgba(255, 255, 255, .94);
    color: var(--text);
    transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(37, 99, 235, .55);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.search-form input { max-width: 360px; }
.search-form select { max-width: 150px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 10px 15px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .1);
    transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(15, 23, 42, .14);
    filter: brightness(1.03);
}

.btn:active {
    transform: translateY(0);
}

.primary, .open { background: linear-gradient(135deg, var(--green), #13a165); }
.secondary { background: linear-gradient(135deg, var(--blue), #3b82f6); }
.edit { background: linear-gradient(135deg, var(--yellow), #facc15); color: #3b2b00; }
.delete { background: linear-gradient(135deg, var(--red), #ef4444); }
.ghost {
    background: #eef2f7;
    color: var(--text);
}

.sheet-wrap, .panel, .auth-box {
    background: rgba(255, 255, 255, .84);
    border: 1px solid rgba(215, 223, 235, .9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}

.sheet-wrap {
    overflow-x: auto;
    animation: liftIn .34s ease both;
}

.sheet {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 940px;
}

.sheet th, .sheet td {
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 13px 14px;
    text-align: left;
    vertical-align: middle;
    background: rgba(255, 255, 255, .82);
}

.sheet th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f3f6fb;
    font-size: 13px;
    color: #344054;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.sheet tbody tr {
    transition: transform .16s ease, box-shadow .16s ease;
}

.sheet tbody tr:hover td {
    background: #f8fbff;
}

.sheet tbody tr:hover {
    transform: translateY(-1px);
    box-shadow: inset 3px 0 0 var(--blue);
}

.sheet td small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.actions {
    display: flex;
    gap: 8px;
}

.badge {
    display: inline-flex;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55);
}

.badge.gmail { background: #e8f0fe; color: #174ea6; }
.badge.zoho { background: #fef7e0; color: #7a4d00; }
.badge.config { background: #edf2f7; color: #364152; }
.badge.db { background: #e6f4ea; color: #137333; }

.panel, .auth-box {
    padding: 24px;
    max-width: 680px;
}

.wide-panel {
    max-width: none;
    margin-bottom: 14px;
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 1fr) auto;
    gap: 10px;
    margin-top: 16px;
}

.auth-box {
    margin: 56px auto;
    max-width: 420px;
}

.panel h2, .auth-box h2 {
    margin: 0 0 16px;
}

.form-grid {
    display: grid;
    gap: 14px;
}

.form-grid label span {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
}

.form-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-row input {
    width: auto;
}

.alert {
    margin-bottom: 14px;
    border-radius: 10px;
    padding: 12px 14px;
    background: #e6f4ea;
    color: #137333;
    border: 1px solid #b7dfc2;
}

.alert.danger {
    background: #fce8e6;
    color: #a50e0e;
    border-color: #f5b5ae;
}

.alert.warning {
    background: #fff7df;
    color: #7a4d00;
    border-color: #f7d88b;
}

.empty {
    color: var(--muted);
    text-align: center;
}

.danger-zone {
    border-color: #f5b5ae;
}

.setup-steps {
    display: grid;
    gap: 8px;
    margin: 18px 0;
}

.setup-steps p {
    margin: 0;
}

.download-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 18px 0;
}

.path-note {
    overflow-wrap: anywhere;
}

@media (max-width: 720px) {
    .page-head {
        grid-template-columns: 1fr;
    }

    .quick-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .toolbar, .search-form {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar {
        padding-block: 12px;
    }

    .topbar-inner {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .main-nav {
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .account-nav {
        justify-content: space-between;
    }

    .inline-form {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .search-form input, .search-form select {
        max-width: none;
    }

}

@keyframes headerFlow {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes pageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes liftIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
