:root {
    --primary: #5bb1bf;
    --primary-light: #8dcad4;
    --primary-dark: #3a8a97;
    --accent: #5bb1bf;
    --bg-gradient: linear-gradient(165deg, #f8fafc 0%, #f1f5f9 100%);
    --surface: rgba(255, 255, 255, 0.7);
    --surface-solid: #ffffff;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border: rgba(226, 232, 240, 0.8);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.04);
    --card-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
    --header-height: 80px;
    --sidebar-width: 320px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-gradient);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Nav Sidebar */
.nav-sidebar {
    width: 260px;
    background: #0f172a;
    color: white;
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex-shrink: 0;
}

.nav-brand {
    padding: 2rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-logo {
    height: 32px;
}

.nav-brand span {
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

nav {
    flex: 1;
    padding: 1rem 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.5rem;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: white;
    background: var(--primary);
    position: relative;
}

.nav-item.active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: white;
}

.nav-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.persona-summary label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #64748b;
    font-weight: 700;
    display: block;
    margin-bottom: 0.5rem;
}

#active-persona-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

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

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.625rem;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91, 177, 191, 0.15);
}

/* Main Content Area */
.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    background: #f8fafc;
    position: relative;
}

.page {
    display: none;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

/* Header Adjustments */
.header-content {
    background: white;
    border-radius: 1.25rem;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.drop-zone-mini {
    border: 2px dashed var(--border);
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.drop-zone-mini:hover {
    border-color: var(--primary);
    background: #f0f9fb;
}

/* Dashboard Layout Overrides */
.dashboard-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    background: white;
    border-radius: 1.5rem;
    height: 75vh;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.persona-selector-inline {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.persona-selector-inline select {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

/* Research View Styles */
.research-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 2rem;
}

.control-card {
    background: var(--surface-solid);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    margin-bottom: 2rem;
    border: 1px solid var(--border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.control-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.control-card h3 {
    margin-top: 0;
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.control-card p {
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.form-group-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.form-group-grid .form-group {
    margin-bottom: 0;
}

.research-results {
    background: white;
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    min-height: 500px;
}

.research-card {
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition: all 0.2s;
}

.research-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.research-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.research-card-header h4 {
    font-size: 1.25rem;
    margin: 0;
}

.score-tag {
    background: #f1f5f9;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--primary-dark);
}

.research-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.research-card-footer {
    display: flex;
    justify-content: flex-end;
}

/* Loader */
.status-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 4rem;
    color: var(--text-muted);
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sidebar {
    width: 100%;
    border-right: 1px solid var(--border);
    background: #fcfcfd;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

#company-list {
    flex: 1;
    overflow-y: auto;
}

.company-item {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.4);
    cursor: pointer;
}

.company-item.active {
    background: white;
    border-left: 4px solid var(--primary);
}

.company-item.contacted {
    opacity: 0.6;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 2.5rem;
    background: white;
}

.company-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.company-info p {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 0.75rem;
}

.primary-btn,
.success-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.primary-btn {
    background: #0f172a;
    color: white;
}

.primary-btn:hover {
    background: #1e293b;
    transform: translateY(-1px);
}

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

/* Email Editor Aesthetics */
#email-editor {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    animation: fadeIn 0.4s ease-out;
}

#email-editor h3 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--text-dark);
}

#email-editor .form-group {
    margin-bottom: 1.5rem;
}

#email-editor label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: block;
}

#email-editor input,
#email-editor textarea {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    font-size: 0.95rem;
    background: #fdfdfd;
    transition: all 0.2s;
}

#email-editor textarea {
    line-height: 1.6;
    resize: vertical;
    font-family: inherit;
    min-height: 250px;
}

#email-editor input:focus,
#email-editor textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(91, 177, 191, 0.1);
}

/* Stage Override & Metadata */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.stage-override {
    text-align: right;
    background: #f8fafc;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
}

.stage-override label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    display: block;
    margin-bottom: 0.25rem;
}

.stage-override select {
    background: transparent;
    border: none;
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}

/* Sidebar Filters */
.filter-group {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.filter-group label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    display: block;
}

.filter-group select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: white;
}

/* Company Item Improvements */
.company-item {
    position: relative;
    padding: 1.25rem 1.5rem !important;
}

.company-item .sender-tag {
    position: absolute;
    top: 1.25rem;
    right: 1rem;
    font-size: 0.6rem;
    opacity: 0.6;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
}

.company-item.stage-0 {
    border-left: 4px solid #cbd5e1 !important;
}

.company-item.stage-1 {
    border-left: 4px solid #3b82f6 !important;
}

.company-item.stage-2 {
    border-left: 4px solid #8b5cf6 !important;
}

.company-item.stage-3 {
    border-left: 4px solid #d946ef !important;
}

.company-item.stage-4 {
    border-left: 4px solid #f43f5e !important;
}

.company-item.stage-5 {
    border-left: 4px solid #ef4444 !important;
}

.company-item.stage-6 {
    border-left: 4px solid #10b981 !important;
}

.company-item.stage-7 {
    border-left: 4px solid #64748b !important;
}

.sidebar-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.count-badge {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
    border: 2px solid #f1f5f9;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.vetting-note {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Login Page Styles */
.login-body {
    background: radial-gradient(circle at top left, #1a1c2c, #0a0b14);
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    overflow: hidden;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 48px 40px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: fadeInScale 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.login-header .logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    color: var(--primary);
    font-size: 24px;
    font-weight: 700;
}

.login-header h1 {
    font-size: 28px;
    margin: 0 0 12px;
    color: white;
}

.login-header p {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 40px;
}

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: white;
    color: #1a1c2c;
    text-decoration: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.3s ease;
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
}

.google-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    background: #f8f9fa;
}

.error-banner {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    color: #ff9999;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 24px;
    font-size: 14px;
    line-height: 1.4;
}

.login-footer {
    margin-top: 40px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 24px;
}

.login-footer p {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

/* Mobile Header & Overlay */
.mobile-header {
    display: none;
    background: #0f172a;
    color: white;
    padding: 0.75rem 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.mobile-logo {
    height: 24px;
}

.mobile-brand span {
    font-weight: 700;
    font-size: 1.1rem;
}

.menu-btn {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 8px;
    width: 40px;
}

.menu-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: white;
    transition: 0.3s;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    display: none;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

/* Database Page Styles */
.database-controls {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
    border: 1px solid var(--border);
}

.filter-group-inline {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.filter-group-inline .control-item {
    flex: 1;
    min-width: 200px;
}

.db-stats {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
}

.muted-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.db-list-container {
    background: white;
    border-radius: 1rem;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.db-list-header {
    display: grid;
    grid-template-columns: 1.5fr 1fr 100px 80px;
    padding: 1rem 1.5rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.db-list-item {
    display: grid;
    grid-template-columns: 1.5fr 1fr 100px 80px;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.4);
    align-items: center;
    transition: background 0.2s;
}

.db-list-item:hover {
    background: #fcfcfd;
}

.db-main-text {
    font-weight: 600;
    color: var(--text);
    font-size: 0.95rem;
}

.db-sub-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 600px;
    border-radius: 1.5rem;
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.modal-header h2 {
    font-size: 1.5rem;
    letter-spacing: -0.02em;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 2rem;
}

.secondary-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 1.75rem;
    font-weight: 600;
    background: #f1f5f9;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: #f1f5f9;
}

/* Media Queries */
@media (max-width: 1024px) {
    .dashboard-layout {
        grid-template-columns: 280px 1fr;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        overflow-y: auto;
    }

    .mobile-header {
        display: flex;
    }

    .nav-sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 1002;
        transition: transform 0.3s ease;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
    }

    .nav-sidebar.active {
        transform: translateX(260px);
    }

    .main-content {
        padding-top: 0;
        height: auto;
        overflow: visible;
    }

    .page {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.5rem;
        padding: 1.5rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .dashboard-layout {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 80vh;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 400px;
    }

    .content-area {
        padding: 1.5rem;
    }

    .company-info {
        grid-template-columns: 1fr;
    }

    .research-grid {
        grid-template-columns: 1fr;
    }

    .control-card {
        padding: 1.25rem;
    }

    .detail-header {
        flex-direction: column;
        gap: 1rem;
    }

    .stage-override {
        text-align: left;
        width: 100%;
    }

    .filter-group {
        grid-template-columns: 1fr;
    }
}