:root {
    --bg: #f3f5fb;
    --panel: #ffffff;
    --primary: #3b82f6;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #dfe7f1;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: linear-gradient(135deg, #eef4ff, #f8fbff);
    color: var(--text);
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 460px);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.brand-box {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 28px 24px;
    text-align: center;
}

.brand-box h1 {
    margin: 0 0 8px;
    font-size: 2rem;
}

.brand-box p {
    margin: 0;
    opacity: 0.9;
}

.auth-form,
.demo-accounts {
    padding: 24px;
}

.auth-form h2 {
    margin-top: 0;
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 18px;
    font-weight: 600;
    color: var(--text);
}

input,
select,
textarea,
button {
    width: 100%;
    font: inherit;
}

input,
select,
textarea {
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

button {
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    cursor: pointer;
    font-weight: 700;
    padding: 12px 18px;
    transition: opacity 0.2s ease;
}

button:hover {
    opacity: 0.96;
}

a.btn-download,
a.btn-small,
.btn-edit,
.btn-delete {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: background 0.2s ease;
    font-size: 0.9rem;
}

a.btn-download {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

a.btn-download:hover {
    opacity: 0.9;
}

a.btn-small {
    background: #3b82f6;
    color: white;
}

a.btn-small:hover {
    opacity: 0.9;
}

.btn-edit {
    background: #8b5cf6;
    color: white;
    border: none;
    cursor: pointer;
    margin-right: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 600;
}

.btn-edit:hover {
    opacity: 0.9;
}

.btn-delete {
    background: #ef4444;
    color: white;
    border: none;
    cursor: pointer;
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 600;
}

.btn-delete:hover {
    opacity: 0.9;
}

.demo-accounts {
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

.demo-accounts h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.demo-accounts ul {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
}

.page-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: #0f172a;
    color: white;
    padding: 22px 18px;
}

.logo-wrap {
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-wrap h2 {
    margin: 0 0 6px;
}

.role-label {
    background: rgba(59, 130, 246, 0.2);
    padding: 6px 10px;
    border-radius: 999px;
    display: inline-block;
    font-size: 0.8rem;
}

.user-card {
    margin-top: 18px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 12px;
}

.user-card strong,
.user-card span {
    display: block;
}

.user-card span {
    color: #cbd5e1;
    margin-top: 4px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 22px;
}

.nav-menu a {
    color: #dbeafe;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
    transition: background 0.2s ease;
}

.nav-menu a:hover {
    background: rgba(255, 255, 255, 0.08);
}

.nav-menu a[href="#admin-dashboard"],
.panel#admin-dashboard {
    --menu-accent: #f59e0b;
}

.nav-menu a[href="#user-management"],
.panel#user-management {
    --menu-accent: #3b82f6;
}

.nav-menu a[href="#surveyor-statistics"],
.panel#surveyor-statistics {
    --menu-accent: #0f766e;
}

.nav-menu a[href="#survey-management"],
.panel#survey-management {
    --menu-accent: #14b8a6;
}

.nav-menu a[href="#leader-overview"],
.panel#leader-overview {
    --menu-accent: #2563eb;
}

.nav-menu a[href="#leader-stats"],
.panel#leader-stats {
    --menu-accent: #16a34a;
}

.nav-menu a[href="#create-survey"],
.panel#create-survey {
    --menu-accent: #f97316;
}

.nav-menu a[href="#surveyor-management"],
.panel#surveyor-management {
    --menu-accent: #8b5cf6;
}

.nav-menu a[href="#assignments"],
.panel#assignments {
    --menu-accent: #e11d48;
}

.nav-menu a[href="#surveyor-summary"],
.panel#surveyor-summary {
    --menu-accent: #d97706;
}

.nav-menu a[href="#surveyor-overview"],
.panel#surveyor-overview {
    --menu-accent: #0ea5e9;
}

.nav-menu a[href="#assigned-surveys"],
.panel#assigned-surveys {
    --menu-accent: #10b981;
}

.nav-menu a[href^="#"] {
    border-left: 4px solid var(--menu-accent, #64748b);
    background: color-mix(in srgb, var(--menu-accent, #64748b) 16%, transparent);
}

.nav-menu a[href^="#"]:hover {
    background: color-mix(in srgb, var(--menu-accent, #64748b) 28%, transparent);
}

.panel[id] {
    border-left: 5px solid var(--menu-accent, var(--primary));
    scroll-margin-top: 20px;
}

.content {
    flex: 1;
    padding: 28px;
    min-width: 0;
    overflow-x: hidden;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 22px;
    overflow-x: auto;
}

.panel h1,
.panel h2,
.panel h3 {
    margin-top: 0;
}

.table-actions {
    display: flex;
    justify-content: flex-end;
    margin: 14px 0;
}

.surveyor-section-header {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: -24px -24px 20px;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.surveyor-section-header h1 {
    margin: 0;
}

.header-response-button {
    width: auto;
    white-space: nowrap;
    background: linear-gradient(135deg, #10b981, #047857);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 18px;
    margin-top: 16px;
}

.stat-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 18px;
}

.stat-box span {
    display: block;
    color: var(--muted);
}

.stat-box strong {
    display: block;
    margin-top: 10px;
    font-size: 2rem;
    color: var(--primary-dark);
}

.inline-form {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: end;
}

.inline-form > * {
    flex: 1 1 150px;
}

.stack-form {
    display: grid;
    gap: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 18px;
}

.panel table {
    display: table;
    max-width: none;
    table-layout: auto;
}

.results-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.results-table {
    display: table !important;
    width: max-content !important;
    min-width: 100% !important;
    table-layout: fixed !important;
    margin-top: 0;
}

.results-table thead,
.results-table tbody {
    display: table-header-group;
    width: auto;
    min-width: 0;
}

.results-table tbody {
    display: table-row-group;
}

.results-table th,
.results-table td {
    min-width: 220px;
    max-width: 320px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.45;
}

.results-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #eaf2ff;
    color: #1e3a8a;
    vertical-align: bottom;
}

.results-table .results-col-name,
.results-table .results-cell-name {
    width: 190px;
    min-width: 190px;
}

.results-table .results-col-username,
.results-table .results-cell-username {
    width: 160px;
    min-width: 160px;
}

.results-table .results-col-date,
.results-table .results-cell-date {
    width: 150px;
    min-width: 150px;
    white-space: nowrap;
}

.results-table .results-col-answer,
.results-table .results-cell-answer {
    width: 240px;
    min-width: 240px;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    background: #f8fafc;
}

.role-badge,
.tag {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    background: #dbeafe;
    color: #1d4ed8;
}

.role-badge.leader,
.tag {
    background: #ddd6fe;
    color: #6d28d9;
}

.role-badge.surveyor {
    background: #dcfce7;
    color: #166534;
}

.role-badge.admin {
    background: #fef3c7;
    color: #92400e;
}

.survey-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    margin-top: 18px;
    background: #fafcff;
}

.assignment-box {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.flash {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 18px;
    font-weight: 600;
}

.flash.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.flash.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

@media (max-width: 840px) {
    .page-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .content {
        padding: 18px;
    }

    .panel {
        padding: 18px;
        border-radius: 14px;
    }

    .surveyor-section-header {
        margin: -18px -18px 18px;
        padding: 14px 18px;
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .header-response-button {
        width: 100%;
    }

    .inline-form {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .inline-form > * {
        min-width: 0;
    }

    th,
    td {
        padding: 10px 8px;
    }
}

/* Question Builder Styles */
.question-builder {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.question-input-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 18px;
}

.question-input-box label {
    margin-bottom: 12px;
}

.question-input-box button {
    margin-top: 12px;
}

.questions-list {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.question-item {
    background: #fafcff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.question-item > div {
    flex: 1;
}

.type-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1d4ed8;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: 8px;
}

.question-options {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.option-tag {
    background: #ecfdf5;
    color: #065f46;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
}

.question-item button {
    padding: 8px 12px;
    font-size: 0.9rem;
}

/* Question rendering styles */
.question-field {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
    background: #fafcff;
}

.question-field legend {
    padding: 0 8px;
    font-weight: 700;
    color: var(--text);
}

.choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.choice-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.choice-label:hover {
    background: #f8fafc;
}

.choice-label input[type="radio"] {
    width: auto;
    margin: 0;
}

.question-field select {
    margin-top: 12px;
}

/* Question Management Page Styles */
.questions-management {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.question-management-item {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    background: #fafcff;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.question-content {
    flex: 1;
}

.question-content strong {
    display: block;
    margin-bottom: 8px;
    font-size: 1rem;
}

.question-actions {
    display: flex;
    gap: 8px;
    white-space: nowrap;
}

.btn-edit-small,
.btn-delete-small {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: opacity 0.2s ease;
}

.btn-edit-small {
    background: #8b5cf6;
    color: white;
}

.btn-edit-small:hover {
    opacity: 0.9;
}

.btn-delete-small {
    background: #ef4444;
    color: white;
}

.btn-delete-small:hover {
    opacity: 0.9;
}

.btn-cancel,
.btn-back {
    padding: 10px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    display: inline-block;
    transition: background 0.2s ease;
}

.btn-cancel {
    background: #e5e7eb;
    color: #1f2937;
}

.btn-cancel:hover {
    background: #d1d5db;
}

.btn-back {
    background: #3b82f6;
    color: white;
}

.btn-back:hover {
    opacity: 0.9;
}

/* Collected Responses Styles */
.collected-responses {
    margin-bottom: 20px;
}

.collected-responses h4 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--text);
}

.response-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: white;
    margin-bottom: 10px;
}

.response-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.response-header strong {
    color: #1f2937;
    font-size: 0.95rem;
}

.response-preview {
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    max-height: 120px;
    overflow-y: auto;
    font-size: 0.9rem;
}

.response-actions {
    display: flex;
    gap: 8px;
}

.btn-add-response {
    background: #10b981;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.btn-add-response:hover {
    opacity: 0.9;
}

.btn-cancel-response {
    background: #e5e7eb;
    color: #1f2937;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    font-weight: 600;
    cursor: pointer;
}

.btn-cancel-response:hover {
    background: #d1d5db;
}

.btn-small-edit,
.btn-small-delete {
    padding: 6px 10px;
    border-radius: 6px;
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.btn-small-edit {
    background: #8b5cf6;
    color: white;
}

.btn-small-edit:hover {
    opacity: 0.9;
}

.btn-small-delete {
    background: #ef4444;
    color: white;
}

.btn-small-delete:hover {
    opacity: 0.9;
}

/* Edit User Button */
.btn-edit-user {
    background: #8b5cf6;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.btn-edit-user:hover {
    opacity: 0.9;
}

/* Modal Base Styles */
.btn-cancel {
    background: #e5e7eb;
    color: #1f2937;
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-cancel:hover {
    background: #d1d5db;
}
