:root {
    --bg-body: #eef2f7;
    --bg-container: #ffffff;
    --text-main: #333333;
    --text-muted: #555555;
    --primary: #007bff;
    --primary-dark: #0056b3;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --bg-chatbox: #f9f9f9;
    --border-color: #eeeeee;
    --bg-bot-msg: #eef2f7;
    --border-bot-msg: #d1d9e6;
    --bg-input: #ffffff;
    --border-input: #cccccc;
    --bg-timeline: #f1f5ff;
    --border-timeline: #e1e8f5;
    --timeline-line: #d1d9e6;
    --circle-bg: #d1d9e6;
}

body.dark-mode {
    --bg-body: #121212;
    --bg-container: #1e1e1e;
    --text-main: #f1f1f1;
    --text-muted: #bbbbbb;
    --primary: #339af0;
    --primary-dark: #228be6;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --bg-chatbox: #25262b;
    --border-color: #373a40;
    --bg-bot-msg: #2c2e33;
    --border-bot-msg: #495057;
    --bg-input: #2c2e33;
    --border-input: #495057;
    --bg-timeline: #25262b;
    --border-timeline: #373a40;
    --timeline-line: #495057;
    --circle-bg: #373a40;
}

body {
    font-family: Arial, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    transition: background 0.3s, color 0.3s;
}

/* Screen Reader Only - Visually hidden but accessible to assistive technologies */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.container {
    width: 80%;
    max-width: 900px;
    margin: 20px auto;
    /* Background and padding moved to .page-section to create distinct blocks */
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px; /* 8px gap between sections */
}

/* Theme Toggle Header */
.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.header-wrapper h1 {
    margin: 0;
    font-size: 1.8em;
}

.header-actions {
    display: flex;
    gap: 15px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
    padding: 0;
}

.icon-btn:hover {
    transform: scale(1.1);
}

.buttons button {
    margin: 0 5px 10px;
    padding: 8px 15px;
    font-size: 14px;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.buttons button:hover {
    background: var(--primary);
    color: white;
}

#chatbox {
    background: var(--bg-chatbox);
    padding: 20px;
    height: 200px;
    border-radius: 10px;
    margin: 10px 0 15px;
    overflow-y: auto;
    text-align: left;
    font-size: 15px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: background 0.3s, border 0.3s;
}

.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-in-out;
}

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

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

.user-msg {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.bot-msg {
    background: var(--bg-bot-msg);
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-bot-msg);
    transition: background 0.3s, color 0.3s, border 0.3s;
}

.msg-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--border-timeline);
    justify-content: flex-end;
}

.msg-action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    opacity: 0.6;
    transition: all 0.2s;
    padding: 2px 4px;
}

.msg-action-btn:hover {
    opacity: 1;
    transform: translateY(-2px) scale(1.1);
}

.chat-controls {
    text-align: left;
    margin-bottom: 12px;
    margin-top: -5px;
}

.clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s;
    font-weight: 500;
}

.clear-btn:hover {
    color: var(--primary);
}

.input-area {
    display: flex;
    gap: 10px;
}

.input-area input {
    flex: 1;
    padding: 0 15px;
    font-size: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-input);
    background: var(--bg-input);
    color: var(--text-main);
    box-sizing: border-box;
    height: 48px;
    outline: none;
    transition: border-color 0.2s, background 0.3s, color 0.3s;
}

.input-area input:focus {
    border-color: var(--primary);
}

.input-area button {
    padding: 0 25px;
    font-size: 16px;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
    transition: 0.2s;
    box-sizing: border-box;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-area button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.quick-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
}

.suggestion-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.suggestion-btn:hover {
    background: var(--bg-bot-msg);
    color: var(--primary);
    border-color: var(--primary);
    transform: scale(1.05);
}

h2 {
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.3em;
}

#timeline {
    display: flex;
    justify-content: space-between;
    background: var(--bg-timeline);
    padding: 20px 10px;
    border-radius: 10px;
    position: relative;
    border: 1px solid var(--border-timeline);
    transition: background 0.3s, border 0.3s;
}

.step {
    flex: 1;
    text-align: center;
    position: relative;
}

.step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 15px;
    left: 50%;
    width: 100%;
    height: 3px;
    background: var(--timeline-line);
    z-index: 1;
    transition: background 0.3s;
}

.step.completed:not(:last-child)::after {
    background: #28a745;
}

.circle {
    width: 32px;
    height: 32px;
    background: var(--circle-bg);
    color: var(--text-muted);
    border-radius: 50%;
    line-height: 32px;
    margin: 0 auto 8px;
    position: relative;
    z-index: 2;
    font-weight: bold;
    font-size: 14px;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out, background 0.3s, color 0.3s;
}

.step:hover .circle {
    transform: scale(1.15);
}

.step.completed .circle {
    background: #28a745;
    color: white;
}

.step.active .circle {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.2);
}

body.dark-mode .step.active .circle {
    box-shadow: 0 0 0 4px rgba(51, 154, 240, 0.2);
}

.step-title {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: bold;
    transition: color 0.3s;
}

.step.active .step-title {
    color: var(--primary);
}

/* Tooltip Base */
.step:focus {
    outline: none;
}

.tooltip {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: #6c757d;
    color: #fff;
    padding: 10px 14px;
    font-size: 12.5px;
    font-weight: normal;
    border-radius: 8px;
    width: 170px;
    text-align: center;
    box-shadow: 0 4px 10px var(--shadow-color);
    z-index: 10;
    pointer-events: none;
    line-height: 1.35;

    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #6c757d transparent transparent transparent;
}

/* Colors matching timeline points */
.step.completed .tooltip {
    background: #28a745;
}

.step.completed .tooltip::after {
    border-top-color: #28a745;
}

.step.active .tooltip {
    background: var(--primary);
}

.step.active .tooltip::after {
    border-top-color: var(--primary);
}

/* Hover & Tap (Focus) State with Delay Removed */
.step:hover .tooltip,
.step:focus .tooltip,
.step:active .tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Typing indicator animation */
.typing-dots::after {
    content: '';
    animation: typing 1.5s infinite;
}

@keyframes typing {
    0% {
        content: '';
    }

    25% {
        content: '.';
    }

    50% {
        content: '..';
    }

    75% {
        content: '...';
    }

    100% {
        content: '';
    }
}

/* --- Layout for Side Map --- */
.main-content-layout {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.chat-section {
    flex: 6;
    display: flex;
    flex-direction: column;
}

.side-map-section {
    flex: 4;
    display: flex;
    flex-direction: column;
    background: var(--bg-timeline);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--border-timeline);
}

#side-map {
    flex: 1;
    min-height: 250px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

/* --- Responsive Design (Mobile Support) --- */
@media (max-width: 768px) {
    /* Maximize screen usage on mobile */
    .container {
        width: 95%;
        margin: 10px auto;
    }

    .page-section {
        padding: 15px;
    }

    /* Header sizing */
    .header-wrapper {
        flex-direction: column;
        gap: 10px;
    }
    .header-wrapper h1 {
        font-size: 1.5em;
        text-align: center;
    }

    /* Stack inputs and buttons vertically for better tap targets */
    .input-area {
        flex-direction: column;
    }
    
    .input-area button {
        width: 100%;
        justify-content: center;
    }

    /* Make timeline vertical */
    #timeline {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
        padding: 20px;
    }

    .step {
        display: flex;
        flex-direction: row;
        align-items: center;
        text-align: left;
        width: 100%;
        gap: 15px;
    }

    .circle {
        margin: 0;
        flex-shrink: 0;
    }

    .step:not(:last-child)::after {
        top: 32px;
        left: 15px; /* Centers the vertical line under the 32px circle */
        width: 3px;
        height: calc(100% + 15px); /* Reaches down to the next circle */
    }

    /* Adjust tooltip position for vertical layout */
    .tooltip {
        bottom: auto;
        top: 120%;
        left: 0;
        transform: translateX(0) translateY(5px);
    }
    
    .step:hover .tooltip,
    .step:focus .tooltip,
    .step:active .tooltip {
        transform: translateX(0) translateY(0);
    }

    .tooltip::after {
        left: 20px;
        transform: translateX(0);
    }
}

/* --- Page Sections --- */
.page-section {
    background: var(--bg-container);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0px 5px 15px var(--shadow-color);
    transition: background 0.3s, box-shadow 0.3s;
}

.section-divider {
    display: none; /* Hidden, using flex gap instead */
}

/* --- New Features Styling --- */
.ballot-section {
    background: var(--bg-timeline);
    padding: 20px 15px 15px 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 1px solid var(--border-timeline);
    text-align: left;
}

.ballot-section h2 {
    margin-top: 0;
    text-align: center;
}

#map {
    height: 300px;
    width: 100%;
    display: none;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid var(--border-timeline);
}

.civic-info-container {
    background: var(--bg-bot-msg);
    padding: 15px;
    border-radius: 8px;
    display: none;
    border: 1px solid var(--border-bot-msg);
    font-size: 14px;
}

.civic-info-container h3 {
    margin-top: 0;
    color: var(--primary);
}

.calendar-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 5px 10px;
    background: #4285F4;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 12px;
    transition: background 0.2s;
}

.calendar-btn:hover {
    background: #3367D6;
}

/* Adjust timeline step to accommodate the button */
.step {
    display: flex;
    flex-direction: column;
    align-items: center;
}