:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --radius: 0.5rem;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    padding-bottom: 70px;
    /* Space for bottom nav */
}

/* Environment Banner */
#env-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 1000;
    position: relative;
}

.env-text {
    flex-grow: 1;
    text-align: center;
}

#env-banner .close-banner {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0 0.5rem;
    color: inherit;
    opacity: 0.5;
    transition: opacity 0.2s;
    line-height: 1;
}

#env-banner.localdev {
    background: #fef9c3;
    color: #854d0e;
}

#env-banner.remotedev {
    background: #dcfce7;
    color: #166534;
}

header {
    background: var(--surface);
    padding: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    /* Increased from 800px */
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

/* Status Indicators */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.online .indicator-dot {
    background: #10b981;
}

.status-indicator.offline .indicator-dot {
    background: #ef4444;
}

.indicator-dot.forced-offline {
    box-shadow: 0 0 0 2px white, 0 0 0 4px #ef4444;
}

/* Repeater Styles */
.repeater-container {
    background: #fdfdfd;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 0.5rem;
}

.repeater-header h3 {
    margin: 0 0 1rem 0;
    font-size: 0.9rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.repeater-rows {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
}

.repeater-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    table-layout: fixed;
    /* Match Admin View */
}

.repeater-table th {
    text-align: left;
    padding: 0.5rem;
    color: var(--text-light);
    border-bottom: 2px solid var(--bg);
    white-space: nowrap;
    /* Prevent header wrapping */
}

/* Item Name */
.repeater-table th:first-child,
.repeater-table td:first-child {
    width: 45%;
    min-width: 150px;
}

/* # Srv */
.repeater-table th:nth-child(2),
.repeater-table td:nth-child(2) {
    width: 60px;
    min-width: 60px;
    text-align: center;
}

/* Srv Size */
.repeater-table th:nth-child(3),
.repeater-table td:nth-child(3) {
    width: 80px;
    min-width: 80px;
}

/* Menu Date */
.repeater-table th:nth-child(4),
.repeater-table td:nth-child(4) {
    width: 120px;
    min-width: 120px;
}

/* Status/Accepted Column */
.repeater-table th:nth-child(5),
.repeater-table td:nth-child(5) {
    width: 110px;
    min-width: 110px;
    text-align: center;
}

.repeater-table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--bg);
}

.repeater-table input {
    padding: 0.4rem;
    font-size: 0.85rem;
}

.btn-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #ef4444;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-delete:hover {
    opacity: 1;
}

.checkbox-mini {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    width: max-content;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.checkbox-mini input {
    width: 14px;
    height: 14px;
    margin: 0;
}

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

@media (max-width: 600px) {

    /* Hide Srv Size (3) and Menu Date (4) */
    .repeater-table th:nth-child(3),
    .repeater-table td:nth-child(3),
    .repeater-table th:nth-child(4),
    .repeater-table td:nth-child(4) {
        display: none;
    }

    /* # Srv Column: Narrower on mobile */
    .repeater-table th:nth-child(2),
    .repeater-table td:nth-child(2) {
        width: 50px;
        min-width: 50px;
    }

    /* Column 5: Hide header text and label text, keep checkbox */
    .repeater-table th:nth-child(5) .th-text {
        display: none;
    }

    /* Add Green Checkmark to Header */
    .repeater-table th:nth-child(5)::after {
        content: "✅";
        display: block;
        font-size: 1.2rem;
    }

    .repeater-table td:nth-child(5) .cb-label {
        display: none;
    }

    /* Adjust checkbox column width since text is gone */
    .repeater-table th:nth-child(5),
    .repeater-table td:nth-child(5) {
        width: 40px;
        min-width: 40px;
        text-align: center;
    }

    /* Expand first column to take up new space */
    .repeater-table th:first-child,
    .repeater-table td:first-child {
        width: auto;
    }
}



main {
    max-width: 1200px;
    /* Increased from 800px */
    margin: 1rem auto;
    padding: 0 1rem;
}

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

h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}

/* Grid and Cards */
.grid-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Three-level tree structure */
.top-level-group {
    margin-bottom: 1rem;
}

.top-level-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
}

.top-level-header:hover {
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
    transform: translateY(-1px);
}

.top-level-header.collapsed {
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

.group-icon {
    font-size: 1.25rem;
}

.group-label {
    flex: 1;
    font-size: 1rem;
}

.dates-container {
    padding: 0.75rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-top: none;
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
    max-height: 3000px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.dates-container.collapsed {
    max-height: 0;
    padding: 0 0.75rem;
    opacity: 0;
    border: none;
}

/* Date-grouped tree structure (second level) */
.date-group {
    margin-bottom: 0.5rem;
}

.date-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    color: var(--text);
    transition: all 0.2s ease;
    user-select: none;
}

.date-header:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.date-header.collapsed {
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

.toggle-icon {
    font-size: 0.75rem;
    color: var(--text-light);
    transition: transform 0.2s ease;
    width: 12px;
    display: inline-block;
}

.top-level-header .toggle-icon {
    color: white;
    font-size: 0.875rem;
}

.date-label {
    flex: 1;
    font-size: 0.95rem;
}

.ticket-count {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 500;
    background: var(--bg);
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
}

.top-level-header .ticket-count {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.date-tickets {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: none;
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.date-tickets.collapsed {
    max-height: 0;
    padding: 0 0.75rem;
    opacity: 0;
    border: none;
}

.form-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 5px solid #e5e7eb;
}

.form-card.stop-card {
    border-left-color: #84cc16;
}

.form-card:hover {
    border-color: var(--primary);
    transform: translateX(2px);
}

.stop-info h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
}

.template-name {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 500;
    margin: 0;
}

.stop-info .description {
    margin: 0.25rem 0 0 0;
    color: var(--text-light);
    font-size: 0.875rem;
}

.stop-status {
    background: #f0fdf4;
    color: #166534;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Handled / Delivered Styles */
.form-card.handled {
    opacity: 0.8 !important;
    background: #fffbeb !important;
    /* Slight yellow tint */
    border-left-color: #f59e0b !important;
    /* Orange/Amber */
    cursor: default !important;
}

.stop-status.delivered {
    background: #fef3c7 !important;
    color: #92400e !important;
}

/* Form Layout */
.form-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.form-group {
    grid-column: span 6;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group.half {
    grid-column: span 3;
}

.form-group.third {
    grid-column: span 2;
}

@media (max-width: 600px) {

    .form-group.half,
    .form-group.third {
        grid-column: span 6;
    }
}

.form-group.header {
    border-bottom: 2px solid var(--border);
    margin-top: 1rem;
    padding-bottom: 0.25rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

input,
textarea {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 1rem;
    width: 100%;
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-weight: 500;
    padding: 10px 0;
    user-select: none;
}

.checkbox-container input {
    width: auto;
}

/* Signature */
.signature-pad-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f9fafb;
    position: relative;
}

canvas {
    width: 100%;
    height: 200px;
    touch-action: none;
    cursor: crosshair;
}

.canvas-actions {
    padding: 0.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}

.btn.primary {
    background: var(--primary);
    color: white;
    width: 100%;
}

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

.btn.secondary {
    background: #e5e7eb;
    color: #374151;
}

.btn-lg {
    padding: 1.25rem 2rem;
    font-size: 1.25rem;
    border-radius: 0.5rem;
}

.btn.link {
    background: none;
    color: var(--primary);
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    background: var(--surface);
    display: flex;
    justify-content: space-around;
    padding: 10px 0;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.nav-item {
    text-decoration: none;
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item .icon {
    font-size: 1.25rem;
}

.badge {
    background: #ef4444;
    color: white;
    padding: 2px 6px;
    border-radius: 9999px;
    font-weight: 700;
    position: absolute;
    margin-left: 15px;
    margin-top: -5px;
}

.hidden {
    display: none !important;
}

.loader {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1rem;
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    z-index: 1000;
    background-color: #333;
    /* Dark background */
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 9999px;
    /* Pill shape */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 200px;
    max-width: 350px;
    opacity: 0;
    transform: translateY(20px);
    /* Initial state for animation */
    animation: slideInToast 0.3s forwards;
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: auto;
    /* Re-enable pointer events for the toast itself */
}

.toast.error {
    background-color: #dc2626;
    /* Red for error */
}

.toast.success {
    background-color: #16a34a;
    /* Green for success */
}

.toast-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.toast-message {
    flex-grow: 1;
    text-align: center;
}

.toast-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    margin-left: 0.5rem;
}

.toast-close-btn:hover {
    color: white;
}

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