/**
 * Timeless Fence Designer - Simple Version
 * Clean, minimal styles for customer-facing tool
 */

/* Hide Google Places built-in dropdown - we use our own */
.pac-container {
    display: none !important;
}

/* ==========================================================================
   Variables
   ========================================================================== */
:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --success: #22C55E;
    --danger: #EF4444;
    --text: #1F2937;
    --text-light: #6B7280;
    --border: #E5E7EB;
    --bg: #F9FAFB;
    --white: #FFFFFF;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;

    /* Line colors */
    --color-blue: #3B82F6;
    --color-green: #22C55E;
    --color-orange: #F97316;
    --color-purple: #8B5CF6;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg);
}

.btn-icon {
    padding: 8px;
    background: var(--white);
    border: 1px solid var(--border);
    color: var(--text-light);
}

.btn-icon:hover:not(:disabled) {
    background: var(--bg);
    color: var(--text);
}

.btn-undo {
    background: #FBBF24;
    color: #1F2937;
    font-weight: 600;
    padding: 8px 16px;
    font-size: 14px;
}

.btn-undo:hover:not(:disabled) {
    background: #F59E0B;
}

.btn-clear {
    background: #EF4444;
    color: #FFFFFF;
    font-weight: 600;
    padding: 8px 16px;
    font-size: 14px;
}

.btn-clear:hover:not(:disabled) {
    background: #DC2626;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 14px;
    text-decoration: underline;
    padding: 8px;
}

.btn-link:hover {
    color: var(--text);
}

.btn-large {
    padding: 14px 32px;
    font-size: 17px;
}

/* ==========================================================================
   Form Elements
   ========================================================================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.address-suggestions {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--white);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
}

.address-suggestion {
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.address-suggestion:last-child {
    border-bottom: none;
}

.address-suggestion:hover {
    background: #f0f4ff;
}

.checkbox-group {
    margin-bottom: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-welcome {
    max-width: 480px;
    text-align: center;
}

.modal-welcome .form-group {
    margin-bottom: 80px;
}

.modal-finish {
    max-width: 600px;
}

.modal-confirm {
    max-width: 400px;
    text-align: center;
}

.modal-header {
    padding: 32px 32px 0;
    position: relative;
}

.modal-header h1,
.modal-header h2 {
    margin-bottom: 8px;
    color: var(--text);
}

.modal-header .subtitle {
    color: var(--text-light);
    margin-bottom: 0;
}

.modal-body {
    padding: 24px 32px 32px;
}

.modal-footer {
    padding: 16px 32px 24px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.logo {
    max-width: 200px;
    max-height: 60px;
    margin-bottom: 16px;
}

/* Welcome Modal */
.modal-welcome .btn-primary {
    width: 100%;
    margin-bottom: 12px;
}

/* Confirmation Modal */
.success-icon {
    width: 80px;
    height: 80px;
    background: var(--success);
    color: var(--white);
    font-size: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.ref-number {
    background: var(--bg);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 18px;
    margin: 20px 0;
}

.confirm-message {
    color: var(--text-light);
    margin-bottom: 24px;
}

/* ==========================================================================
   App Container & Toolbar
   ========================================================================== */
#app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    gap: 16px;
    z-index: 500;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-label {
    font-size: 14px;
    color: var(--text-light);
    margin-right: 4px;
}

/* Color Selector */
.color-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    padding: 0;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: var(--text);
    transform: scale(1.15);
}

/* Gate Selector */
.gate-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid var(--border);
}

.gate-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
}

.gate-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.gate-btn.active:hover {
    background: var(--primary-hover);
}

/* Length Display */
.length-display {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 8px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    flex-wrap: wrap;
    justify-content: center;
}

.length-total {
    font-size: 22px;
    font-weight: 600;
    color: var(--primary);
}

.length-color-total {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

.length-separator {
    color: var(--text-light);
    font-size: 14px;
}

.length-grand-total {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.length-acreage {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
    white-space: nowrap;
}

.length-color-group {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.length-color-acreage {
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0.8;
}

/* Per-shape acreage label rendered at the polygon centroid */
.shape-acreage-label {
    pointer-events: none;
}
.shape-acreage-label-inner {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    transform: translate(-50%, -50%);
    display: inline-block;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Map-view control: Satellite / Map radios + previous-imagery button */
.map-view-control {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    margin-top: 8px !important;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.map-view-toggle {
    display: inline-flex;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(0, 0, 0, 0.15);
}
.map-view-toggle .mv-btn {
    appearance: none;
    border: none;
    background: #fff;
    color: #444;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
}
.map-view-toggle .mv-btn + .mv-btn {
    border-left: 1px solid rgba(0, 0, 0, 0.1);
}
.map-view-toggle .mv-btn:hover {
    background: #f3f4f6;
}
.map-view-toggle .mv-btn.active {
    background: #2271b1;
    color: #fff;
}
.map-view-control .mv-prev {
    appearance: none;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: #fff;
    color: #444;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
    text-align: center;
    white-space: nowrap;
}
.map-view-control .mv-prev:hover {
    background: #f3f4f6;
}

/* ==========================================================================
   Map
   ========================================================================== */
#map {
    flex: 1;
    width: 100%;
    background: #E5E7EB;
}

/* Custom cursors for map modes */
#map.cursor-draw {
    cursor: crosshair !important;
}

#map.cursor-gate {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23D97706' stroke-width='2'%3E%3Crect x='3' y='4' width='4' height='16' rx='1'/%3E%3Crect x='17' y='4' width='4' height='16' rx='1'/%3E%3Cpath d='M7 8h10M7 12h10M7 16h10'/%3E%3C/svg%3E") 12 12, pointer !important;
}

#map.cursor-editable {
    cursor: pointer !important;
}

/* Custom Leaflet styles */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
    border-radius: var(--radius) !important;
}

/* ==========================================================================
   Instructions
   ========================================================================== */
.instructions {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.instructions-content {
    background: var(--white);
    padding: 14px 28px;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    font-size: 15px;
    color: var(--text);
    text-align: center;
    line-height: 1.4;
    transition: all 0.3s ease;
}

.instructions-content.prominent {
    background: var(--primary);
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    padding: 18px 36px;
    box-shadow: 0 6px 24px rgba(37, 99, 235, 0.4);
    animation: instructionPulse 2s ease-in-out 1;
}

@keyframes instructionPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* ==========================================================================
   Line Configuration (Finish Modal)
   ========================================================================== */
#line-config-section {
    margin-bottom: 24px;
}

.line-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.line-config-header h3 {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.btn-expand-config {
    font-size: 13px;
    color: var(--primary);
    padding: 4px 0;
    white-space: nowrap;
}

.privacy-link {
    font-size: 12px;
    font-weight: 400;
    margin-left: 8px;
}

.privacy-link a {
    color: var(--text-light);
    text-decoration: none;
}

.privacy-link a:hover {
    text-decoration: underline;
}

#line-config-section h3,
.customer-section h3 {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.line-config-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.line-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 4px;
}

.line-config-fields {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 100px 100px;
    gap: 12px;
}

.line-config-fields .form-group {
    margin-bottom: 0;
}

.line-config-fields label {
    font-size: 12px;
    color: var(--text-light);
}

.line-config-fields input,
.line-config-fields select {
    padding: 8px 10px;
    font-size: 14px;
}

.line-length {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
    grid-column: 1 / -1;
}

/* ==========================================================================
   Loading
   ========================================================================== */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-subtext {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-light);
    max-width: 280px;
    text-align: center;
    padding: 0 16px;
    min-height: 18px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Snap Indicator
   ========================================================================== */
.snap-indicator {
    position: absolute;
    width: 24px;
    height: 24px;
    border: 3px solid var(--primary);
    border-radius: 50%;
    background: rgba(37, 99, 235, 0.2);
    transform: translate(-50%, -50%);
    pointer-events: none;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.7; }
}

/* ==========================================================================
   Gate Marker
   ========================================================================== */
.gate-marker {
    background: transparent;
    border: none;
}

.gate-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--white);
    border: 2px solid #D97706;
    border-radius: 6px;
    box-shadow: var(--shadow);
}

.gate-icon svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Edit Hint (toolbar)
   ========================================================================== */
.edit-hint {
    font-size: 11px;
    color: var(--text-light);
    font-style: italic;
    padding: 4px 8px;
    background: var(--bg);
    border-radius: 4px;
    white-space: nowrap;
    user-select: none;
}

/* ==========================================================================
   Drag Preview Labels
   ========================================================================== */
.drag-preview-label {
    background: transparent;
    border: none;
}

.drag-preview-distance {
    background: none;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

/* ==========================================================================
   Rubber Band Distance Label
   ========================================================================== */
.rubber-band-label {
    background: transparent;
    border: none;
}

.rubber-band-distance {
    background: none;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

/* ==========================================================================
   Responsive — Tablet (<=900px)
   ========================================================================== */
@media (max-width: 900px) {
    .toolbar {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }

    .toolbar-left,
    .toolbar-center,
    .toolbar-right {
        gap: 8px;
    }

    .toolbar-label {
        display: none;
    }

    .gate-selector {
        margin-left: 8px;
        padding-left: 8px;
    }
}

/* ==========================================================================
   Responsive — Phone (<=600px)
   ========================================================================== */
@media (max-width: 600px) {
    /* Use dynamic viewport units so mobile URL bars don't clip the app */
    html, body {
        height: 100dvh;
    }

    #app-container {
        height: 100dvh;
    }

    /*
     * Mobile toolbar — two rows with a clear split of concerns:
     *   Row 1 (status + primary CTA):  [Length ..................... Finish]
     *   Row 2 (tools):                 [Colors + Gate .......... Undo Clear]
     *
     * We flatten `.toolbar-right` with `display: contents` so its children
     * (edit-hint, Undo, Clear, Finish) participate in the outer flex layout
     * directly. That lets us order Finish onto row 1 while Undo/Clear ride
     * on row 2 next to the tools, without restructuring the HTML.
     */
    .toolbar {
        padding: 6px 10px;
        padding-top: calc(6px + env(safe-area-inset-top));
        gap: 6px;
        row-gap: 10px;
        flex-wrap: wrap;
    }

    .toolbar-right {
        display: contents;
    }

    /* Row 1: length (left, flexes) + Finish (right, fixed) */
    .toolbar-center {
        order: 1;
        flex: 1 1 auto;
        min-width: 0;
    }

    #finish-btn {
        order: 2;
        flex: 0 0 auto;
        margin-left: auto;
        padding: 10px 16px;
        font-size: 14px;
        min-height: 42px;
        font-weight: 600;
    }

    /* Force a line break between row 1 and row 2 */
    .toolbar::before {
        content: "";
        display: block;
        order: 3;
        flex-basis: 100%;
        height: 0;
        margin: 0;
    }

    /* Row 2: colors + gate (left, flexes) + Undo/Clear (right) */
    .toolbar-left {
        order: 4;
        flex: 1 1 auto;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 8px;
        min-width: 0;
    }

    #undo-btn {
        order: 5;
        flex: 0 0 auto;
        margin-left: auto;
        padding: 10px 14px;
        font-size: 13px;
        min-height: 42px;
    }

    #clear-btn {
        order: 6;
        flex: 0 0 auto;
        padding: 10px 14px;
        font-size: 13px;
        min-height: 42px;
    }

    /* Bigger tap targets */
    .color-btn {
        width: 38px;
        height: 38px;
        border-width: 3px;
    }

    .color-btn.active {
        transform: scale(1.1);
    }

    .gate-selector {
        margin-left: 4px;
        padding-left: 10px;
    }

    .gate-btn {
        padding: 10px 12px;
        min-height: 42px;
    }

    .gate-btn span {
        font-size: 14px;
    }

    /* Edit hint consumes precious space — hide on phones */
    .edit-hint {
        display: none !important;
    }

    /* Length display compresses nicely */
    .length-display {
        padding: 6px 10px;
        gap: 6px;
    }

    .length-total {
        font-size: 18px;
    }

    .length-color-total {
        font-size: 13px;
    }

    .length-grand-total {
        font-size: 15px;
    }

    .length-separator {
        font-size: 12px;
    }

    .length-acreage,
    .length-color-acreage {
        font-size: 11px;
    }

    /* Instructions: sit above the bottom safe area, full-width pill */
    .instructions {
        bottom: calc(16px + env(safe-area-inset-bottom));
        left: 12px;
        right: 12px;
        transform: none;
        width: auto;
        max-width: none;
    }

    .instructions-content {
        padding: 12px 20px;
        font-size: 14px;
        line-height: 1.35;
    }

    .instructions-content.prominent {
        padding: 14px 22px;
        font-size: 15px;
    }

    /* Full-screen modals on phones */
    .modal {
        padding: 0;
        align-items: stretch;
    }

    .modal-content {
        max-width: 100%;
        max-height: 100dvh;
        min-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .modal-header {
        padding: 24px 20px 0;
        padding-top: calc(24px + env(safe-area-inset-top));
    }

    .modal-body {
        padding: 20px;
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 12px 20px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        flex-direction: column-reverse;
        gap: 10px;
        border-top: 1px solid var(--border);
        background: var(--white);
    }

    .modal-footer .btn {
        width: 100%;
        padding: 14px 20px;
        font-size: 16px;
    }

    .modal-header h1,
    .modal-header h2 {
        font-size: 22px;
    }

    .modal-close {
        top: calc(12px + env(safe-area-inset-top));
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    /* Welcome modal: reserve space for address-suggestions dropdown when keyboard opens */
    .modal-welcome .form-group {
        margin-bottom: 20px;
    }

    .modal-welcome .btn-large {
        padding: 16px 24px;
        font-size: 17px;
        width: 100%;
    }

    /* Stacked form rows */
    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .line-config-fields {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Finish modal */
    .modal-finish .line-config-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .btn-expand-config {
        padding: 6px 0;
        font-size: 14px;
    }

    .line-config-item {
        padding: 12px;
        gap: 12px;
    }

    /* Privacy link on its own line on narrow screens */
    .privacy-link {
        display: block;
        margin-left: 0;
        margin-top: 4px;
    }

    /* Inputs: 16px prevents iOS zoom-on-focus */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px;
        padding: 12px 14px;
    }

    .line-config-fields input,
    .line-config-fields select {
        padding: 10px 12px;
        font-size: 16px;
    }

    /* Confirm modal centered inside full-screen shell */
    .modal-confirm {
        justify-content: center;
        text-align: center;
        padding: 40px 24px;
        padding-top: calc(40px + env(safe-area-inset-top));
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }

    .modal-confirm .modal-body {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Toast: lift above bottom safe area */
    #toast-container {
        bottom: calc(96px + env(safe-area-inset-bottom));
        left: 12px;
        right: 12px;
        transform: none;
        width: auto;
    }

    .toast {
        padding: 12px 20px;
        font-size: 14px;
        white-space: normal;
        text-align: center;
        max-width: 100%;
    }

    /* Map-view toggle: tighten on phones */
    .map-view-toggle .mv-btn {
        padding: 8px 10px;
        font-size: 11px;
    }

    .map-view-control .mv-prev {
        padding: 6px 8px;
        font-size: 10px;
    }
}

/* ==========================================================================
   Responsive — Small phones (<=380px) — tightest layout
   ========================================================================== */
@media (max-width: 380px) {
    .toolbar {
        padding: 5px 8px;
        padding-top: calc(5px + env(safe-area-inset-top));
        gap: 4px;
        row-gap: 8px;
    }

    .color-btn {
        width: 34px;
        height: 34px;
        border-width: 2px;
    }

    .gate-selector {
        margin-left: 2px;
        padding-left: 8px;
    }

    .gate-btn {
        padding: 8px 10px;
        min-height: 38px;
    }

    /* Icon-only gate on tightest screens */
    .gate-btn span {
        display: none;
    }

    #undo-btn,
    #clear-btn {
        padding: 8px 10px;
        font-size: 12px;
        min-height: 38px;
    }

    #finish-btn {
        padding: 9px 12px;
        font-size: 13px;
        min-height: 38px;
    }

    .length-total {
        font-size: 16px;
    }
}

/* ==========================================================================
   Responsive — Landscape phones (height constraint)
   ========================================================================== */
@media (max-height: 480px) and (orientation: landscape) {
    .toolbar {
        padding: 4px 8px;
        padding-top: calc(4px + env(safe-area-inset-top));
    }

    .color-btn {
        width: 28px;
        height: 28px;
    }

    .instructions {
        bottom: 8px;
    }

    .instructions-content {
        padding: 8px 16px;
        font-size: 13px;
    }

    .modal-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
#toast-container {
    position: fixed;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #1F2937;
    color: #fff;
    padding: 16px 28px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    pointer-events: auto;
    animation: toastIn 0.3s ease forwards;
}

.toast.toast-out {
    animation: toastOut 0.4s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}
