/* ================================
   CSS Variables & Base Styles
   ================================ */
:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --primary-light: #a3bffa;
    --secondary: #4fd1c5;
    --success: #48bb78;
    --warning: #ed8936;
    --danger: #f56565;
    --dark: #1a202c;
    --gray-900: #171923;
    --gray-800: #1a202c;
    --gray-700: #2d3748;
    --gray-600: #4a5568;
    --gray-500: #718096;
    --gray-400: #a0aec0;
    --gray-300: #cbd5e0;
    --gray-200: #e2e8f0;
    --gray-100: #edf2f7;
    --white: #ffffff;
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #4fd1c5 0%, #38b2ac 100%);
    --gradient-dark: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--gray-900);
    min-height: 100vh;
    color: var(--gray-100);
    line-height: 1.6;
    overflow-y: auto;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* Login */
.login-screen {
    min-height: calc(100vh - 50px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-bottom: 60px;
    background: var(--gradient-dark);
}

.login-container {
    width: 100%;
    max-width: 400px;
    background: rgba(45, 55, 72, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    box-shadow: var(--shadow-lg);
}

.login-logo svg {
    width: 32px;
    height: 32px;
    color: var(--white);
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--white);
    margin-bottom: 0.25rem;
}

.login-header p {
    color: var(--gray-400);
    font-size: 0.9rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-200);
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(45, 55, 72, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--white);
    font-size: 0.95rem;
    font-family: inherit;
    transition: var(--transition);
}

.form-input::placeholder {
    color: var(--gray-500);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(45, 55, 72, 0.8);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.checkbox-group label {
    color: var(--gray-200);
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.5rem 0.875rem;
    font-size: 0.85rem;
}

.btn-sm svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--gray-200);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--gray-200);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

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

.btn-danger:hover {
    background: #c53030;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Icon Buttons (for table actions) */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--gray-400);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

.btn-icon.danger {
    border-color: rgba(245, 101, 101, 0.3);
    color: var(--danger);
}

.btn-icon.danger:hover {
    background: rgba(245, 101, 101, 0.2);
}

.btn-icon.warning {
    border-color: rgba(237, 137, 54, 0.3);
    color: var(--warning);
}

.btn-icon.warning:hover {
    background: rgba(237, 137, 54, 0.2);
}

.btn-icon.success {
    border-color: rgba(72, 187, 120, 0.3);
    color: var(--success);
}

.btn-icon.success:hover {
    background: rgba(72, 187, 120, 0.2);
}

.btn-icon.info {
    border-color: rgba(102, 126, 234, 0.3);
    color: var(--primary);
}

.btn-icon.info:hover {
    background: rgba(102, 126, 234, 0.2);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--gray-300);
}

.badge-success {
    background: rgba(72, 187, 120, 0.2);
    color: var(--success);
}

.badge-danger {
    background: rgba(245, 101, 101, 0.2);
    color: var(--danger);
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2rem;
    background: rgba(26, 32, 44, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

@media (min-width: 1024px) {
    .header {
        padding: 2rem 4rem;
    }
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-menu {
    position: relative;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--white);
    cursor: pointer;
    transition: var(--transition);
}

.user-avatar:hover {
    transform: scale(1.05);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 200px;
    background: var(--gray-700);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
}

.user-menu:hover .user-dropdown,
.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-info {
    padding: 1rem;
}

.user-name {
    display: block;
    font-weight: 600;
    color: var(--white);
}

.user-role {
    display: block;
    font-size: 0.8rem;
    color: var(--gray-400);
}

.dropdown-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: var(--gray-300);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

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

.dropdown-item svg {
    width: 18px;
    height: 18px;
}

/* Main Content */
.main-content {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

@media (min-width: 1024px) {
    .main-content {
        padding: 2rem 4rem;
        display: grid;
        grid-template-columns: 240px 1fr;
        gap: 2rem;
        align-items: start;
    }
}

/* Tabs / Sidebar */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: rgba(45, 55, 72, 0.4);
    padding: 0.375rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
}

@media (min-width: 1024px) {
    .tabs.sidebar {
        flex-direction: column;
        margin-bottom: 0;
        position: sticky;
        top: 6rem;
        /* account for header */
        height: auto;
    }
}

.tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--gray-400);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.tab svg {
    width: 18px;
    height: 18px;
}

.tab:hover {
    color: var(--gray-200);
}

.tab.active {
    background: var(--primary);
    color: var(--white);
    box-shadow: var(--shadow-md);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.tab-content.active {
    display: block;
}

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

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

/* Section Header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--white);
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.form-card {
    background: rgba(45, 55, 72, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    transition: var(--transition);
}

.form-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

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

.form-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
}

.form-card-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

.form-card-badge.active {
    background: rgba(72, 187, 120, 0.2);
    color: var(--success);
}

.form-card-badge.inactive {
    background: rgba(245, 101, 101, 0.2);
    color: var(--danger);
}

.form-card-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.form-card-stat {
    text-align: center;
}

.form-card-stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--white);
}

.form-card-stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.form-card-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-card-actions .btn {
    flex: 1;
    min-width: 80px;
}

/* Filters */
.filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(45, 55, 72, 0.4);
    border-radius: var(--radius-md);
}

.filter-group {
    flex: 1;
    min-width: 150px;
    max-width: 200px;
}

.filter-group .form-input {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

/* Data Table */
.table-container {
    overflow-x: auto;
    background: rgba(45, 55, 72, 0.4);
    border-radius: var(--radius-md);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.data-table th {
    font-weight: 600;
    color: var(--gray-300);
    background: rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

.data-table td {
    color: var(--gray-200);
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

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

.loading-cell {
    text-align: center;
    padding: 2rem !important;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: rgba(45, 55, 72, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon.blue {
    background: rgba(102, 126, 234, 0.2);
    color: var(--primary);
}

.stat-icon.green {
    background: rgba(72, 187, 120, 0.2);
    color: var(--success);
}

.stat-icon.purple {
    background: rgba(159, 122, 234, 0.2);
    color: #b794f4;
}

.stat-icon.orange {
    background: rgba(237, 137, 54, 0.2);
    color: var(--warning);
}

.stat-icon.teal {
    background: rgba(79, 209, 197, 0.2);
    color: var(--secondary);
}

.stat-content {
    flex: 1;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--white);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--gray-400);
}

/* Metrics */
.metrics-section {
    background: rgba(45, 55, 72, 0.4);
    border-radius: var(--radius-md);
    padding: 1.5rem;
}

.metrics-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 1rem;
}

.top-forms-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.top-form-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}

.top-form-rank {
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--white);
}

.top-form-name {
    flex: 1;
    color: var(--gray-200);
}

.top-form-count {
    font-weight: 600;
    color: var(--white);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    background: var(--gray-800);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(20px);
    transition: var(--transition);
}

.modal.show .modal-container {
    transform: scale(1) translateY(0);
}

.modal-container.modal-sm {
    max-width: 450px;
}

.modal-container.modal-lg {
    max-width: 800px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--white);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.1);
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-actions {
    margin-bottom: 1rem;
}

/* Fields Section */
.fields-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

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

.fields-footer {
    margin-top: 1rem;
}

.fields-header h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-200);
}

.fields-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.field-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.field-item-content {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
    /* Space for the top-left indicator */
}

.field-item .form-group {
    margin-bottom: 0;
}

.field-item .form-label {
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.field-item .form-input {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.field-item-remove {
    background: transparent;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.field-item-remove:hover {
    color: var(--danger);
    background: rgba(245, 101, 101, 0.1);
}

.field-item-remove svg {
    width: 18px;
    height: 18px;
}

/* User Forms */
.user-forms-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.user-form-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}

.user-form-item span {
    font-size: 0.85rem;
    color: var(--gray-300);
}

.user-form-item button {
    background: transparent;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.user-form-item button:hover {
    color: var(--danger);
    background: rgba(245, 101, 101, 0.1);
}

/* Submissions */
.submissions-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.submission-item {
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

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

.submission-user {
    font-weight: 600;
    color: var(--white);
}

.submission-date {
    font-size: 0.8rem;
    color: var(--gray-400);
}

.submission-responses {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.submission-response {
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
}

.submission-response-label {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-bottom: 0.25rem;
}

.submission-response-value {
    font-size: 0.9rem;
    color: var(--gray-200);
    word-break: break-word;
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(102, 126, 234, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 1rem 1.5rem;
    background: var(--gray-700);
    color: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    animation: slideInRight 0.3s ease-out;
    max-width: 350px;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

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

.toast.error {
    background: var(--danger);
}

.toast.success {
    background: var(--success);
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
    }

    .header-left,
    .header-right {
        width: 100%;
        justify-content: center;
    }

    .filters-container {
        flex-direction: column;
    }

    .filter-group {
        max-width: 100%;
    }

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

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

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-card-actions {
        flex-direction: column;
    }

    .form-card-actions .btn {
        width: 100%;
    }
}

/* ================================
   Preview Modal
   ================================ */
.modal-container.modal-preview {
    max-width: 500px;
}

.preview-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
}

.preview-device {
    width: 320px;
    height: 568px;
    background: var(--gray-900);
    border-radius: 36px;
    padding: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(255, 255, 255, 0.1);
    position: relative;
}

.preview-device::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.preview-screen {
    width: 100%;
    height: 100%;
    background: var(--gradient-dark);
    border-radius: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
}

.preview-screen::-webkit-scrollbar {
    width: 4px;
}

.preview-screen::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Preview Form Header */
.preview-form-header {
    text-align: center;
    padding: 1rem 0 1.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.preview-form-logo {
    width: 48px;
    height: 48px;
    margin: 0 auto 0.75rem;
    border-radius: 8px;
    object-fit: cover;
}

.preview-form-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 0.5rem;
}

.preview-progress {
    margin-top: 0.75rem;
}

.preview-progress-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.preview-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.preview-progress-text {
    font-size: 0.7rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

/* Preview Fields */
.preview-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.preview-field {
    margin-bottom: 0.75rem;
}

.preview-field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-200);
    margin-bottom: 0.35rem;
}

.preview-field-label .required {
    color: var(--danger);
    margin-left: 0.25rem;
}

.preview-field-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: rgba(45, 55, 72, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--gray-400);
    font-size: 0.85rem;
}

.preview-field-input.file-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    border-style: dashed;
    border-width: 2px;
    text-align: center;
}

.preview-field-input.file-input svg {
    width: 18px;
    height: 18px;
}

/* Preview Radio Group (Multiple Choice) */
.preview-radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.preview-radio-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(45, 55, 72, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.preview-radio-option:hover {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.1);
}

.preview-radio-option input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.preview-radio-option label {
    font-size: 0.85rem;
    color: var(--gray-300);
    cursor: pointer;
}

/* Preview Checkbox Group (Multiple Choice with multiple selections) */
.preview-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.preview-checkbox-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(45, 55, 72, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.preview-checkbox-option:hover {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.1);
}

.preview-checkbox-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.preview-checkbox-option label {
    font-size: 0.85rem;
    color: var(--gray-300);
    cursor: pointer;
}

/* Preview Info Field */
.preview-field-info {
    padding: 0.75rem;
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    color: var(--gray-300);
    font-size: 0.85rem;
    line-height: 1.4;
}

/* Preview Select */
.preview-field select.preview-field-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

/* Preview Controls */
.preview-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    width: 100%;
}

.preview-page-info {
    font-size: 0.85rem;
    color: var(--gray-400);
    min-width: 100px;
    text-align: center;
}

/* Empty preview state */
.preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-400);
    text-align: center;
    padding: 2rem;
}

.preview-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.preview-empty p {
    font-size: 0.9rem;
}

/* Responsive Preview */
@media (max-width: 520px) {
    .preview-device {
        width: 280px;
        height: 500px;
    }
}

/* ================================
   Link Modal
   ================================ */
.modal-description {
    color: var(--gray-400);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    text-align: center;
}

.link-box {
    position: relative;
    display: flex;
    align-items: center;
}

.copy-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--gray-400);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-btn:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.1);
}

.copy-btn svg {
    width: 20px;
    height: 20px;
}

/* Drag and Drop Styles */
.field-item {
    cursor: grab;
    position: relative;
    padding-left: 1rem;
    padding-right: 3rem;
    /* space for handle on right */
    transition: transform 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
}

.field-item.dragging {
    opacity: 1;
    border: none;
    background: var(--primary);
    height: 4px;
    padding: 0;
    overflow: hidden;
    margin: 4px 0;
    border-radius: 2px;
}

/* Hide content when dragging (bar mode) */
.field-item.dragging>* {
    display: none;
}

.field-move-controls {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 10;
}

.btn-move-up,
.btn-move-down {
    background: transparent;
    border: none;
    color: var(--gray-600);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--transition);
}

.btn-move-up:hover,
.btn-move-down:hover {
    color: var(--primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-move-up:disabled,
.btn-move-down:disabled {
    color: var(--gray-700);
    cursor: default;
    opacity: 0.5;
    background: transparent;
}

.btn-move-up svg,
.btn-move-down svg {
    width: 20px;
    height: 20px;
}

.field-item:active {
    cursor: grabbing;
}

.field-pos-indicator {
    position: absolute;
    top: 4px;
    left: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
}

/* Files Section */
.files-layout {
    display: flex;
    gap: 1.5rem;
    height: calc(100vh - 200px);
}

.files-sidebar {
    width: 250px;
    background: rgba(45, 55, 72, 0.4);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.files-sidebar h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-300);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.files-main {
    flex: 1;
    background: rgba(45, 55, 72, 0.2);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    overflow-y: auto;
}

.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

.file-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition);
}

.file-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-md);
}

.file-thumbnail {
    height: 140px;
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.file-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-thumbnail svg {
    width: 48px;
    height: 48px;
    color: var(--gray-500);
}

.file-info {
    padding: 0.75rem;
}

.file-name {
    display: block;
    font-size: 0.8rem;
    color: var(--gray-200);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.5rem;
}

.file-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-date {
    font-size: 0.7rem;
    color: var(--gray-500);
}

.file-download {
    color: var(--primary);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.file-download:hover {
    background: rgba(102, 126, 234, 0.1);
}

.files-sidebar .user-form-item {
    cursor: pointer;
}

.files-sidebar .user-form-item.active {
    background: var(--primary);
    color: white;
}

.files-sidebar .user-form-item.active span {
    color: white;
}

/* Scroll Top Button */
.btn-scroll-top {
    position: absolute;
    bottom: 80px;
    /* Above footer */
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: var(--transition);
    z-index: 10;
}

.btn-scroll-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.btn-scroll-top:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.btn-scroll-top svg {
    width: 24px;
    height: 24px;
}

/* Scroll Top Button Position Fix */
.btn-scroll-top {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
}

@media (max-width: 600px) {
    .btn-scroll-top {
        right: 1.5rem;
        /* Ensure safe distance from edge on mobile */
        bottom: 5rem;
        /* Move up slightly to avoid FAB overlap if any, or just safety */
    }
}

/* Responsive Styles */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: inline-flex;
    }

    .header-left {
        gap: 0.5rem;
    }

    .btn-icon {
        background: transparent;
        border: none;
        color: var(--white);
        cursor: pointer;
        padding: 0.5rem;
    }

    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        top: 73px;
        /* Header height approx */
        left: 0;
        bottom: 0;
        z-index: 90;
        width: 250px;
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 2rem;
    }

    .header {
        padding: 2rem;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .header h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
    }

    .table-container {
        overflow-x: auto;
    }

    .modal-container {
        width: 95%;
        max-height: 95vh;
    }

    .modal-body {
        padding: 1rem;
    }

    .fields-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .btn-scroll-top {
        bottom: 5rem;
        right: 1.5rem;
    }

    /* Overlay for sidebar */
    .sidebar-overlay {
        position: fixed;
        top: 73px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 80;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s;
    }

    .sidebar.show+.sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 768px) {
    .sidebar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding-top: 0 !important;
        background: var(--gray-900) !important;
    }

    .sidebar .tab {
        justify-content: flex-start;
        padding: 1rem;
        border-radius: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }
}

/* ================================
   Desktop Sidebar Layout (Enforced)
   ================================ */
@media (min-width: 1024px) {
    .main-content {
        display: grid !important;
        grid-template-columns: 240px 1fr !important;
        gap: 2rem !important;
        align-items: start !important;
        padding: 2rem 4rem !important;
    }

    /* Target .tabs.sidebar specifically */
    .tabs.sidebar {
        display: flex !important;
        flex-direction: column !important;
        position: sticky !important;
        top: 7rem !important;
        height: auto !important;
        margin-bottom: 0 !important;
        background: transparent !important;
        padding: 0 !important;
        transform: none !important;
        box-shadow: none !important;
        border-radius: var(--radius-md) !important;
        overflow: visible !important;
        width: 100% !important;
        z-index: 10 !important;
    }

    .tabs.sidebar .tab {
        width: 100% !important;
        justify-content: flex-start !important;
        padding: 0.75rem 1rem !important;
        border-radius: var(--radius-sm) !important;
        margin-bottom: 0.25rem !important;
        border: none !important;
    }

    .tabs.sidebar .tab.active {
        box-shadow: none !important;
        background: var(--primary) !important;
        color: var(--white) !important;
    }

    .tabs.sidebar .tab:hover {
        background: rgba(255, 255, 255, 0.05) !important;
    }

    .tabs.sidebar .tab.active:hover {
        background: var(--primary) !important;
    }

    /* Ensure content fills the remaining space */
    .tab-content {
        width: 100% !important;
        min-width: 0 !important;
    }
}

@media (min-width: 1024px) {

    /* Explicit Grid Placement to prevent stacking */
    .tabs.sidebar {
        grid-column: 1;
        /* Sidebar uses position: sticky to stay fixed, no need for grid-row spanning */
    }

    .tab-content {
        grid-column: 2;
        /* Ensure it starts at the top */
        grid-row: 1;
    }

    /* Hide overlay to prevent interference */
    .sidebar-overlay {
        display: none !important;
    }
}

/* ================================
   Admin Logo Upload Refinements
   ================================ */
.file-input-wrapper {
    position: relative;
    width: 100%;
    max-width: 240px;
    margin: 0 auto 1rem;
}

.file-input-wrapper .file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.file-upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    transition: var(--transition);
    text-align: center;
    color: var(--gray-400);
}

.file-upload-content:hover {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.05);
    color: var(--white);
}

.file-upload-content svg {
    width: 16px !important;
    height: 16px !important;
    margin-bottom: 0.35rem;
    color: var(--primary);
    opacity: 0.8;
}

.file-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(72, 187, 120, 0.15);
    border: 1px solid rgba(72, 187, 120, 0.3);
    border-radius: var(--radius-md);
    color: var(--success);
    font-size: 0.9rem;
}

.file-preview.hidden {
    display: none;
}

.file-preview-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 1rem;
}

.file-preview-remove {
    background: transparent;
    border: none;
    color: var(--success);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.file-preview-remove:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

.file-preview-remove svg {
    width: 18px;
    height: 18px;
}

/* ================================
   Global Footer
   ================================ */
.global-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--gray-900);
    border-top: 1px solid var(--gray-700);
    padding: 0.75rem 1rem;
    text-align: center;
    z-index: 100;
}

.global-footer p {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin: 0;
}

.global-footer strong {
    color: var(--primary);
    font-weight: 600;
}

/* Adjust main content to not be hidden behind footer */
.main-content {
    padding-bottom: 80px;
}

/* Also ensure tab-content sections have enough margin */
.tab-content {
    margin-bottom: 20px;
}