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

:root {
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-text-hover: #ffffff;
    --main-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #3b82f6;
    --border-color: #e2e8f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: var(--main-bg);
    color: var(--text-primary);
}

#app-container {
    display: flex;
    height: 100vh;
}

.container {
    display: flex;
    width: 100%;
    flex: 1;
}

.sidebar {
    width: 250px;
    min-height: 100vh;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.logo {
    font-size: 1.5rem;
    text-align: center;
    font-weight: bold;
    margin-bottom: 2rem;
    text-align: center;
}

.sidebar nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar nav a {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--sidebar-text);
    transition: background-color 0.2s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background-color: #334155;
    color: var(--sidebar-text-hover);
}

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #334155;
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.view {
    display: none;
}

.view.active-view {
    display: block;
}

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

.main-header h2 {
    margin: 0;
    font-size: 1.8rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.main-header h3 {
    margin: 0;
    font-size: 1.6rem;
}


button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    gap: 1.5rem;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.analytics-card {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    text-align: center;
}

.analytics-card .value {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.analytics-card .label {
    font-size: 1rem;
    color: var(--text-secondary);
}

.table-container {
    background-color: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow-x: auto;
}

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

table th, table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

table th {
    font-weight: 600;
    background-color: #f8fafc;
}

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

table tbody tr.event-row:hover {
    background-color: #f1f5f9;
    cursor: pointer;
}

.card {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 1.5rem;
}

.rule-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
}

.rule-form button {
    grid-column: 1 / -1; /* Make button span full width */
    justify-self: start;
}

.payload-details td {
    background-color: #f8fafc;
    padding: 1.5rem;
}

.payload-details pre, .card pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: monospace;
    font-size: 0.875rem;
    color: var(--text-primary);
    background-color: #f1f5f9;
    padding: 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

.card h4 {
    margin-top: 2rem;
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.card p {
    margin-top: 0;
    line-height: 1.6;
}

.chart-container {
    position: relative;
    height: 400px;
}

/* Login View Styles */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
}

#login-form, #register-form {
    width: 100%;
    max-width: 360px;
    padding: 2rem;
    background-color: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

#login-form h2 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

#login-form .form-group {
    margin-bottom: 1rem;
}

#login-form button {
    width: 100%;
    margin-top: 0.5rem;
}

.error-message {
    color: #ef4444; /* Red-500 */
    font-size: 0.875rem;
    text-align: center;
    min-height: 1.25rem; /* Reserve space to prevent layout shift */
    margin-bottom: 1rem;
}

.success-message {
    color: #10b981; /* Green-500 */
    font-size: 0.875rem;
    text-align: center;
    min-height: 1.25rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: #d1fae5; /* Green-100 */
    border-radius: 0.375rem;
    border: 1px solid #10b981;
}

.switch-form-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 1.5rem;
}

.switch-form-text a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.switch-form-text a:hover {
    text-decoration: underline;
}

.website-selector-container {
    margin-bottom: 2rem;
}

#website-selector {
    width: 100%;
    padding: 0.75rem;
    background-color: #334155;
    color: var(--sidebar-text);
    border: 1px solid #475569;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

#website-selector:focus {
    outline: none;
    border-color: var(--accent-color);
}

.event-details-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.5rem 1rem;
    align-items: start;
}

.event-details-grid pre {
    margin: 0;
    grid-column: 2;
}

.custom-date-range-container { 
    margin-bottom: 2rem;
}

#apply-custom-range {
    margin-top: 0.5rem;
}

.hamburger-menu {
    display: none; /* Hidden by default */
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px; /* Hidden by default on mobile */
        top: 0;
        height: 100%;
        z-index: 1000;
        transition: left 0.3s ease-in-out;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
        overflow-y: auto;
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        padding: 1rem;
    }

    .hamburger-menu {
        display: block; /* Show on mobile */
    }

    .main-header h2 {
        flex-grow: 1;
        text-align: center;
    }
}

#calcRuleFormula { width: 500px; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    grid-column: 1 / -1;
}

.test-rule-result {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Modal Styles */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: rgba(0,0,0,0.4);
    padding: 20px 0;
}

.modal-content {
    background-color: #fefefe;
    margin: 40px auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 8px;
    position: relative;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Accordion styles for rules */
.rules-accordion {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.accordion-item {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    cursor: pointer;
    background: white;
    transition: background-color 0.2s;
}

.accordion-header:hover {
    background: #f8fafc;
}

.accordion-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.accordion-toggle {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.accordion-item.active .accordion-toggle {
    transform: rotate(180deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    border-top: 1px solid var(--border-color);
}

.accordion-item.active .accordion-content {
    max-height: 500px;
    transition: max-height 0.3s ease-in;
}

.rule-details {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.detail-row {
    display: flex;
    gap: 0.5rem;
}

.detail-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 120px;
}

.detail-value {
    color: var(--text-primary);
}

.rule-actions {
    padding: 0 1.25rem 1.25rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

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

.badge-inactive {
    background: #f1f5f9;
    color: #64748b;
}

.detail-value code {
    background: #f1f5f9;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 0.875rem;
    color: #1e293b;
}

/* Audience Segments Styling */
.audience-segments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.audience-segment-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 1.5rem;
    color: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.audience-segment-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.15);
}

.audience-segment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.audience-segment-header h4 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
}

.audience-reach-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.audience-segment-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.audience-segment-stats .stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.audience-segment-stats .stat-value {
    font-size: 1.75rem;
    font-weight: bold;
    color: white;
    margin-bottom: 0.25rem;
}

.audience-segment-stats .stat-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Vary gradient colors for different cards */
.audience-segment-card:nth-child(2) {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.audience-segment-card:nth-child(3) {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.audience-segment-card:nth-child(4) {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.audience-segment-card:nth-child(5) {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.audience-segment-card:nth-child(6) {
    background: linear-gradient(135deg, #30cfd0 0%, #330867 100%);
}

.audience-segment-card:nth-child(7) {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.audience-segment-card:nth-child(8) {
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
}

.audience-segment-card:nth-child(9) {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
}

.audience-segment-card:nth-child(10) {
    background: linear-gradient(135deg, #ff6e7f 0%, #bfe9ff 100%);
}

.audience-segment-card:nth-child(n+11) {
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
}

/* Profile Extraction Styling */
#interest-selector label:hover {
    background: #e8e8e8 !important;
}

#extracted-profiles-table tr:hover {
    background-color: #f9f9f9;
}

#extracted-profiles-table th {
    font-weight: 600;
    color: #333;
}

#extracted-profiles-table td {
    color: #555;
}