/* ============================================================
   HL-TopMix TradeForce — Dark Theme
   Aesthetic: Industrial-luxe dashboard with amber accents
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* === CSS Variables === */
:root {
    /* Backgrounds */
    --bg-deepest:    #0a0b0f;
    --bg-deep:       #0f1117;
    --bg-surface:    #151721;
    --bg-elevated:   #1c1f2e;
    --bg-hover:      #242738;
    --bg-active:     #2a2d42;

    /* Borders */
    --border-subtle: #1e2133;
    --border-default:#2a2d42;
    --border-strong: #3a3d52;

    /* Text */
    --text-primary:   #e8e9ed;
    --text-secondary: #9295a5;
    --text-muted:     #5d6072;
    --text-inverse:   #0a0b0f;

    /* Accent: warm amber */
    --accent:         #f59e0b;
    --accent-hover:   #fbbf24;
    --accent-subtle:  rgba(245, 158, 11, 0.12);
    --accent-glow:    rgba(245, 158, 11, 0.25);

    /* Status colors */
    --success:    #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --warning:    #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --danger:     #ef4444;
    --danger-bg:  rgba(239, 68, 68, 0.12);
    --info:       #3b82f6;
    --info-bg:    rgba(59, 130, 246, 0.12);

    /* Chart colors */
    --chart-1: #f97316;
    --chart-2: #3b82f6;
    --chart-3: #eab308;
    --chart-4: #22c55e;
    --chart-5: #a855f7;
    --chart-6: #ef4444;

    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  16px;
    --radius-xl:  20px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition: 0.25s var(--ease-out);
}

/* === Light Theme Overrides === */
[data-theme="light"] {
    /* Backgrounds */
    --bg-deepest:    #f0f2f5;
    --bg-deep:       #ffffff;
    --bg-surface:    #ffffff;
    --bg-elevated:   #f5f6f8;
    --bg-hover:      #ebedf0;
    --bg-active:     #dfe1e6;

    /* Borders */
    --border-subtle: #e3e5e8;
    --border-default:#d0d3d9;
    --border-strong: #b8bcc5;

    /* Text */
    --text-primary:   #1a1d26;
    --text-secondary: #4a4f5e;
    --text-muted:     #7a7f8e;
    --text-inverse:   #ffffff;

    /* Accent: warm amber (slightly deeper for contrast on light bg) */
    --accent:         #d97706;
    --accent-hover:   #b45309;
    --accent-subtle:  rgba(217, 119, 6, 0.10);
    --accent-glow:    rgba(217, 119, 6, 0.20);

    /* Status colors (slightly deeper for light bg contrast) */
    --success:    #16a34a;
    --success-bg: rgba(22, 163, 74, 0.10);
    --warning:    #d97706;
    --warning-bg: rgba(217, 119, 6, 0.10);
    --danger:     #dc2626;
    --danger-bg:  rgba(220, 38, 38, 0.10);
    --info:       #2563eb;
    --info-bg:    rgba(37, 99, 235, 0.10);
}

/* Light theme scrollbar */
[data-theme="light"] ::-webkit-scrollbar-track { background: #f0f2f5; }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c4c8d0; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #a0a5b0; }

/* Light theme auth wrapper gradient */
[data-theme="light"] .auth-wrapper {
    background:
        radial-gradient(ellipse at 20% 50%, rgba(217, 119, 6, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(37, 99, 235, 0.04) 0%, transparent 50%),
        var(--bg-deepest);
}

/* Light theme auth card shadow */
[data-theme="light"] .auth-card {
    box-shadow: 0 25px 60px rgba(0,0,0,0.08);
}

/* Light theme stat card hover */
[data-theme="light"] .stat-card:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
}

/* Light theme modal */
[data-theme="light"] .modal-overlay {
    background: rgba(0,0,0,0.3);
}
[data-theme="light"] .modal {
    box-shadow: 0 30px 80px rgba(0,0,0,0.15);
}

/* Light theme sidebar mobile */
[data-theme="light"] .sidebar.open {
    box-shadow: 10px 0 40px rgba(0,0,0,0.15);
}

/* Light theme Leaflet controls */
[data-theme="light"] .leaflet-control-zoom a {
    background: #ffffff !important;
    color: #1a1d26 !important;
    border-color: #d0d3d9 !important;
}
[data-theme="light"] .leaflet-control-zoom a:hover {
    background: #f5f6f8 !important;
}

/* Light theme Leaflet popup */
[data-theme="light"] .dark-popup .leaflet-popup-content-wrapper {
    background: #ffffff;
    color: #1a1d26;
    border: 1px solid #d0d3d9;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
[data-theme="light"] .dark-popup .leaflet-popup-tip {
    background: #ffffff;
    border: 1px solid #d0d3d9;
}

/* Light theme region tooltip */
[data-theme="light"] .region-tooltip {
    background: #ffffff;
    border: 1px solid #d0d3d9;
    box-shadow: 0 8px 20px rgba(0,0,0,0.10);
}

/* Light theme marker pin */
[data-theme="light"] .client-marker-pin {
    border-color: #ffffff;
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.3);
}

/* Light theme map SVG paths */
[data-theme="light"] .bulgaria-map .region-path {
    fill: #e8ebf0;
    stroke: #c4c8d0;
}
[data-theme="light"] .bulgaria-map .region-path:hover {
    fill: rgba(217, 119, 6, 0.15);
    stroke: var(--accent);
}

/* Smooth theme transition */
[data-theme] body,
[data-theme] .sidebar,
[data-theme] .main-content,
[data-theme] .page-header,
[data-theme] .card,
[data-theme] .stat-card,
[data-theme] .data-table thead,
[data-theme] .modal,
[data-theme] .auth-card,
[data-theme] .region-tooltip {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-deepest);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Auth Pages Layout === */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(245, 158, 11, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.04) 0%, transparent 50%),
        var(--bg-deepest);
    padding: 2rem;
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 3rem;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.4);
    animation: authSlideUp 0.6s var(--ease-out);
}

@keyframes authSlideUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* === Dashboard Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-deep);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.sidebar-brand span {
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-nav {
    padding: 1rem 0.75rem;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 1rem 0.75rem 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 450;
    transition: all var(--transition);
    margin-bottom: 2px;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.nav-item svg, .nav-item .nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active svg, .nav-item.active .nav-icon {
    opacity: 1;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-subtle);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-subtle);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    overflow: hidden;
}

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;   /* a wide table scrolls inside its card instead of widening the page */
    min-height: 100vh;
}

.page-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-deep);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 900;
    backdrop-filter: blur(12px);
}

.page-title {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.page-body {
    padding: 2rem;
}

/* === Cards === */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition);
}

.card:hover {
    border-color: var(--border-default);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.card-body {
    padding: 1.5rem;
}

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-default);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-top: 0.25rem;
    font-family: 'JetBrains Mono', monospace;
}

.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.info { color: var(--info); }
.stat-value.danger { color: var(--danger); }

.stat-change {
    font-size: 0.75rem;
    margin-top: 0.25rem;
    font-weight: 500;
}
.stat-comparison {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.35rem;
    font-size: 0.78rem;
    font-family: 'Outfit', sans-serif;
}
.stat-prev {
    color: var(--text-muted);
    font-weight: 400;
}
.stat-pct {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-weight: 600;
    font-size: 0.74rem;
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
}
.stat-pct.up {
    color: var(--success);
    background: var(--success-bg);
}
.stat-pct.down {
    color: var(--danger);
    background: var(--danger-bg);
}
.stat-pct.neutral {
    color: var(--text-muted);
    background: var(--bg-active);
}
.stat-pct svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}
.stat-divider {
    text-align: center;
    margin: 0.15rem 0 1rem;
}
.stat-divider-label {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted);
    white-space: nowrap;
}

/* === Month Picker === */
.month-picker {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 0.15rem 0 1rem;
}
.month-picker-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
}
.month-picker-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}
.month-picker-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.month-picker-btn svg {
    width: 16px;
    height: 16px;
}
.month-picker-label {
    text-align: center;
    min-width: 180px;
}
.month-picker-month {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}
.month-picker-range {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}
.month-picker-workdays {
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 500;
    margin-top: 0.15rem;
}

/* === Enhanced Stat Card with Goal === */
.stat-card-goal {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.stat-card-goal:hover {
    border-color: var(--border-default);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

/* Card title */
.stat-card-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
}

/* Hero row: "49%( 4 910 € )" */
.stat-hero-row {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
}
.stat-goal-hero-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.6rem;
    font-weight: 700;
}
.stat-goal-hero-inline.up { color: var(--success); }
.stat-goal-hero-inline.down { color: var(--danger); }
.stat-goal-hero-inline.neutral { color: var(--text-muted); }
.stat-hero-amount {
    font-size: 0.9rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    font-weight: 500;
}

/* Row labels: "оборот / цел", "оборот / мин. месец" */
.stat-row-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: lowercase;
    margin-top: 0.35rem;
    margin-bottom: 0.1rem;
}

/* Row values */
.stat-row-values {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
    font-weight: 600;
}
.goal-fraction {
    font-weight: 600;
}
.prev-fraction {
    font-weight: 500;
    color: var(--text-secondary);
}
.stat-muted {
    color: var(--text-muted);
    font-weight: 400;
}

/* Previous month indicator */
.stat-prev-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.1rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-sm);
}
.stat-prev-indicator.up { color: var(--success); background: var(--success-bg); }
.stat-prev-indicator.down { color: var(--danger); background: var(--danger-bg); }
.stat-prev-indicator.neutral { color: var(--text-muted); }

/* Goal row: "Цел: 10 000 €" with pencil */
.stat-goal-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.25rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border-subtle);
}
.goal-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    flex: 1;
}
.stat-goal-edit-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}
.stat-goal-edit-btn:hover { color: var(--accent); }
.stat-goal-edit-btn svg { width: 14px; height: 14px; }

/* Inline goal input */
.stat-goal-input {
    width: 100px;
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    outline: none;
}
.stat-goal-input:focus {
    box-shadow: 0 0 0 2px var(--accent-bg);
}

/* Forecast row */
.stat-forecast-row {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding-top: 0.3rem;
    border-top: 1px dashed var(--border-subtle);
    margin-top: 0.15rem;
    font-family: 'JetBrains Mono', monospace;
}
.stat-forecast-label {
    font-family: 'Outfit', sans-serif;
    font-weight: 400;
}
.stat-forecast-value {
    font-weight: 600;
}
.stat-forecast-value.forecast-good {
    color: var(--success);
}
.stat-forecast-value.forecast-bad {
    color: var(--danger);
}

/* Leaderboard comparison row */
.stat-leaderboard-row {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding-top: 0.35rem;
    border-top: 1px dashed var(--border-subtle);
    margin-top: 0.2rem;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.5;
}
.stat-leaderboard-row .lb-header {
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-bottom: 0.1rem;
    letter-spacing: 0.02em;
}
.stat-leaderboard-row .lb-line {
    word-break: break-word;
}
.stat-leaderboard-row .lb-rank {
    color: var(--accent);
    font-weight: 600;
}

/* === Action Panel === */
.action-panel {
    margin-bottom: 1.5rem;
}
.action-panel .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.action-panel-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}
.action-panel-body {
    padding: 0;
}
.action-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition);
}
.action-row.has-items {
    cursor: pointer;
}
.action-row.has-items:hover {
    background: var(--bg-hover);
}
.action-row.expanded {
    background: var(--bg-hover);
}
.action-row.empty {
    opacity: 0.45;
}
.action-row:last-child {
    border-bottom: none;
}
.action-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
}
.action-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
}
.action-label {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
}
.action-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}
.action-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 0.5rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--badge-color, var(--text-primary));
    background: color-mix(in srgb, var(--badge-color, var(--text-muted)) 12%, transparent);
}

/* Expanded detail */
.action-detail {
    padding: 0.25rem 1.25rem 0.75rem 3.5rem;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-subtle);
}
.action-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.action-detail-table td {
    padding: 0.3rem 0.5rem 0.3rem 0;
    color: var(--text-secondary);
}
.action-detail-table tr:not(:last-child) td {
    border-bottom: 1px solid var(--border-subtle);
}
.action-client-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.action-client-link:hover {
    text-decoration: underline;
}
.action-city {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: 0.3rem;
}
.action-detail-meta {
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* === Combined Suggestion Engine === */
.suggestion-engine {
    margin-bottom: 1.5rem;
}
.suggestion-engine-body {
    padding: 0;
}
.se-client {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background var(--transition);
}
.se-client:last-child {
    border-bottom: none;
}
.se-client:hover {
    background: var(--bg-hover);
}
.se-client-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.45rem;
}
.se-client-info {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    min-width: 0;
}
.se-client-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.se-client-city {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.se-client-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.se-animals {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 1px 6px;
    background: var(--bg-active);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}
.se-signal-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--danger);
    background: var(--danger-bg);
    padding: 2px 6px;
    border-radius: 999px;
}
.se-recommendations {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.se-rec {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.se-rec-icon {
    flex-shrink: 0;
    font-size: 0.82rem;
    width: 1.2rem;
    text-align: center;
}
.se-rec-text {
    flex: 1;
}

/* === Collapsible Sections === */
.collapsible-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.collapse-chevron {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: transform 0.25s ease;
    flex-shrink: 0;
}
.collapsible-section.collapsed .collapse-chevron {
    transform: rotate(-90deg);
}
.collapsible-body {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    max-height: 2000px;
    opacity: 1;
}
.collapsible-section.collapsed .collapsible-body {
    max-height: 0;
    opacity: 0;
}

/* === Risk Score Section === */
.risk-score-section {
    margin-bottom: 1.5rem;
}
.rs-body {
    padding: 0;
}
.rs-client {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background var(--transition);
}
.rs-client:last-child {
    border-bottom: none;
}
.rs-client:hover {
    background: var(--bg-hover);
}
.rs-client-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.rs-client-info {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    min-width: 0;
}
.rs-client-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rs-client-city {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Score badge */
.rs-score-badge {
    display: flex;
    align-items: baseline;
    gap: 3px;
    padding: 3px 8px;
    border-radius: 999px;
    flex-shrink: 0;
}
.rs-score-badge.medium {
    background: var(--warning-bg);
    color: var(--warning);
}
.rs-score-badge.high {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
}
.rs-score-badge.critical {
    background: var(--danger-bg);
    color: var(--danger);
}
.rs-score-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 700;
}
.rs-score-label {
    font-size: 0.62rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.8;
}

/* Factor bars */
.rs-factors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}
.rs-factor {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.rs-factor-bar {
    height: 4px;
    background: var(--bg-active);
    border-radius: 2px;
    overflow: hidden;
}
.rs-factor-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease;
    min-width: 1px;
}
.rs-factor-label {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-align: center;
}

/* Config panel */
.rs-config-btn {
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 3px 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all var(--transition);
}
.rs-config-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.rs-config-panel {
    padding: 0.85rem 1.25rem;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-default);
}
.rs-config-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.rs-config-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}
.rs-config-item label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
.rs-weight-input {
    width: 100%;
    padding: 0.3rem 0.4rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    text-align: center;
}
.rs-weight-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}
.rs-config-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.rs-config-sum {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    flex: 1;
}
.rs-config-sum.invalid {
    color: var(--danger);
    font-weight: 600;
}
.btn-ghost {
    background: none;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}
.btn-ghost:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

/* === Forms === */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: all var(--transition);
    outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-select-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.78rem;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 550;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 15px var(--accent-glow);
    color: var(--text-inverse);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-default);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-success {
    background: var(--success);
    color: var(--text-inverse);
}
.btn-success:hover { filter: brightness(1.1); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { filter: brightness(1.1); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 0.5rem 0.75rem;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.chart-period-btn.active { background: var(--accent); color: #fff; }
.chart-period-btn.active:hover { background: var(--accent); color: #fff; opacity: 0.9; }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 1.75rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* === Tables === */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
}

/* Keep the last column ("Действия" / Details) pinned to the right so it stays
   visible when the client table is wider than the viewport. */
#clientsTable th:last-child,
#clientsTable td:last-child {
    position: sticky;
    right: 0;
    z-index: 1;
    background: var(--bg-surface);
    box-shadow: -8px 0 10px -8px rgba(0, 0, 0, 0.25);
}
#clientsTable th:last-child {
    background: var(--bg-elevated);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table thead {
    background: var(--bg-elevated);
}

.data-table th {
    padding: 0.85rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
}

/* Sortable table headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.6rem;
    transition: color 0.2s;
}
.data-table th.sortable:hover {
    color: var(--text-primary);
}
.data-table th.sortable::after {
    content: '⇅';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    opacity: 0.35;
}
.data-table th.sortable.sort-asc::after {
    content: '↑';
    opacity: 1;
    color: var(--accent);
}
.data-table th.sortable.sort-desc::after {
    content: '↓';
    opacity: 1;
    color: var(--accent);
}

.data-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table .sortable {
    cursor: pointer;
    user-select: none;
}
.data-table .sortable:hover {
    color: var(--accent);
}

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 50px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-frozen  { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

/* === Alerts === */
.alert {
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: alertSlide 0.4s var(--ease-out);
}

@keyframes alertSlide {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.alert-success { background: var(--success-bg); color: var(--success); border-left: 3px solid var(--success); }
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-left: 3px solid var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-left: 3px solid var(--warning); }
.alert-info    { background: var(--info-bg);    color: var(--info);    border-left: 3px solid var(--info); }

/* === Map Container === */
.map-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
}

.bulgaria-map {
    width: 100%;
    height: auto;
    display: block;
}

.bulgaria-map .region-path {
    fill: var(--bg-elevated);
    stroke: var(--border-default);
    stroke-width: 0.5;
    cursor: pointer;
    transition: fill 0.2s ease, stroke 0.2s ease, stroke-width 0.2s ease;
}

.bulgaria-map .region-path:hover {
    fill: var(--accent-subtle);
    stroke: var(--accent);
    stroke-width: 1.5;
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.bulgaria-map .region-path.active {
    fill: var(--accent-subtle);
    stroke: var(--accent);
    stroke-width: 1.5;
}

/* === Map Legend === */
.map-legend {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.25rem 0;
    flex-wrap: wrap;
    font-size: 0.72rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
    margin-top: 0.5rem;
}
.map-legend-title {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.7rem;
}
.map-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.map-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
    flex-shrink: 0;
}

/* === Leaflet Region Map — Custom Markers & Dark Theme === */
.leaflet-client-marker {
    background: none;
    border: none;
}
.client-marker-pin {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-surface);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.5);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
}
/* approximate (settlement-level) pin — filled but faded, ringed, no pulse */
.client-marker-pin-approx {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    /* background comes from the inline color */
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.28), 0 0 6px rgba(0,0,0,0.35);
    opacity: 0.9;
}
.leaflet-client-marker-approx { filter: saturate(0.85); }
.client-marker-pulse {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.25;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: marker-pulse 2s ease-out infinite;
}
@keyframes marker-pulse {
    0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0.4; }
    100% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}

/* Leaflet popup dark theme */
.dark-popup .leaflet-popup-content-wrapper {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.dark-popup .leaflet-popup-tip {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-top: none;
    border-right: none;
}
.dark-popup .leaflet-popup-close-button {
    color: var(--text-muted);
}
.dark-popup .leaflet-popup-close-button:hover {
    color: var(--text-primary);
}

/* Leaflet controls dark theme */
.leaflet-control-zoom a {
    background: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-default) !important;
}
.leaflet-control-zoom a:hover {
    background: var(--bg-surface) !important;
}

.region-tooltip {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 200;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.2s;
}

.region-tooltip.visible {
    opacity: 1;
}

.region-tooltip-name {
    font-weight: 600;
    color: var(--text-primary);
}

.region-tooltip-stats {
    color: var(--text-muted);
    font-size: 0.72rem;
    margin-top: 0.15rem;
}

/* === Region Page Layout === */
.region-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 0;
    height: 520px;
    max-height: 520px;
}

.region-layout .map-col {
    grid-column: 1;
    min-height: 0; /* allow flexbox children to shrink */
}
.region-layout .stats-col {
    grid-column: 2;
    min-height: 0;
}
.region-table-section { grid-column: 1 / -1; }

/* Leaflet map fills its card body */
.region-layout .card-body { min-height: 0; }

/* Contain Leaflet z-index so it never overlaps sticky header */
#regionLeafletMap,
#bulgariaMapContainer {
    position: relative;
    z-index: 0;
}
.leaflet-container {
    z-index: 0;
}

/* Farm legend hover */
.farm-legend-item:hover {
    background: var(--bg-hover);
}

/* === Region Page Components === */
.region-filters-card { margin-top: 1.25rem; }
.region-filters-body { padding: 0.75rem 1rem; }

.region-filter-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.region-filter-row-border {
    border-top: 1px solid var(--border-subtle);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}
.region-filter-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    flex: 1 1 auto;
    min-width: 0;   /* allow the group to shrink so its buttons wrap instead of
                       forcing the whole page wider than the viewport */
}
.region-filter-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}
.region-filter-divider {
    width: 1px;
    height: 24px;
    background: var(--border-default);
    flex-shrink: 0;
}

.region-chart-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
}
.region-chart-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.region-legend {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.region-legend-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}
.region-legend-row:hover {
    background: var(--bg-hover);
}
.region-legend-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.region-legend-name {
    font-size: 0.82rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.region-legend-value {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
.region-legend-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.region-legend-pct {
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 36px;
    text-align: right;
}

.region-assigned {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
}
.region-assigned-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.region-assigned-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
}
.region-assigned-name {
    font-size: 0.82rem;
    color: var(--text-primary);
    font-weight: 500;
}
.region-assigned-phone {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.region-sales-total {
    text-align: center;
    margin-bottom: 1rem;
}
.region-sales-total-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.region-sales-total-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
}

.region-sort-select {
    width: auto;
    min-width: 150px;
    font-size: 0.82rem;
}

.region-empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* === Search & Filter Bar === */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-input-wrapper svg {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.search-input-wrapper input {
    padding-left: 2.5rem;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0,0,0,0.5);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s var(--ease-out);
    position: relative;
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.3rem;
    line-height: 1;
    transition: color var(--transition);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border-subtle);
    padding: 0.75rem 1.5rem;
    background: var(--bg-surface);
}

/* === Animations === */
.fade-in {
    animation: fadeIn 0.5s var(--ease-out);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.5s var(--ease-out);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.stagger > * {
    animation: slideUp 0.5s var(--ease-out) backwards;
}
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.1s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.25s; }

/* === Responsive helper classes === */

/* Dashboard grid: map + charts row (50/50 split) */
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
.dash-grid > .card {
    min-width: 0; /* prevent grid blowout */
}

/* Dashboard segmented tabs (local trader stats panel) */
.dash-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-subtle);
    margin-bottom: 0.5rem;
}
.dash-tab {
    padding: 0.5rem 1rem;
    font-size: 0.82rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
}
.dash-tab:hover {
    color: var(--text-primary);
}
.dash-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.dash-tab-content {
    display: none;
}
.dash-tab-content.active {
    display: block;
}

/* Period pill selector */
.period-pills {
    display: inline-flex;
    background: var(--bg-active);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 1px;
}
.period-pill {
    padding: 0.25rem 0.55rem;
    font-size: 0.7rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-radius: calc(var(--radius-sm) - 1px);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    line-height: 1.3;
}
.period-pill:hover {
    color: var(--text-primary);
}
.period-pill.active {
    color: var(--accent);
    background: var(--bg-elevated);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Region toggle chips */
.region-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.6rem 0 0.4rem;
    align-items: center;
}
.region-toggle-actions {
    display: flex;
    gap: 0.25rem;
    margin-right: 0.4rem;
}
.region-toggle-action {
    padding: 0.2rem 0.5rem;
    font-size: 0.68rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-active);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    line-height: 1.3;
}
.region-toggle-action:hover {
    color: var(--text-primary);
    border-color: var(--border-default);
}
.region-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.55rem;
    font-size: 0.72rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-active);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    line-height: 1.3;
    user-select: none;
}
.region-chip:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
}
.region-chip.active {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--bg-elevated);
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.region-chip .chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: opacity 0.2s ease;
}
.region-chip:not(.active) .chip-dot {
    opacity: 0.35;
}

/* Contact rows (compact expandable) */
.contact-rows {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 1rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.contact-row {
    border-bottom: 1px solid var(--border-subtle);
}
.contact-row:last-child {
    border-bottom: none;
}

.contact-row-main {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
    min-height: 40px;
}
.contact-row-main:hover {
    background: var(--bg-hover);
}

.contact-row-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 90px;
    flex-shrink: 0;
}

.contact-row-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-row-phone {
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s, color 0.15s;
}
.contact-row-phone:hover {
    background: var(--accent-subtle);
    color: var(--accent-hover);
}
.contact-row-phone.contact-row-empty {
    color: var(--text-muted);
    font-family: 'Outfit', sans-serif;
}

.contact-row-chevron {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}
.contact-row-chevron.open {
    transform: rotate(180deg);
}

.contact-row-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
    background: var(--bg-elevated);
    padding: 0 0.85rem;
}
.contact-row-details.open {
    max-height: 120px;
    padding: 0.5rem 0.85rem 0.65rem;
}

.contact-row-detail {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.contact-row-detail-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 500;
    color: var(--text-muted);
    min-width: 50px;
}
.contact-row-detail-value {
    font-size: 0.82rem;
    text-decoration: none;
}

/* Modal info grid (JS-generated) */
.modal-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem 1.5rem;
    margin-bottom: 1.25rem;
}

/* Section headers (JS-generated) */
.modal-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1.25rem 0 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 2px solid var(--border-default);
}
.modal-section-title {
    font-size: 0.78rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}
.modal-section-right {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Financial row (JS-generated) */
.modal-finance-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.modal-finance-row > div { flex: 1; }
.modal-finance-box {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-subtle);
}
.modal-finance-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}
.modal-finance-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    margin-top: 0.15rem;
}

/* Footer row */
.modal-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.modal-footer-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.modal-footer-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}
.modal-footer-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    text-decoration: none;
}
.modal-status-badge {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.modal-status-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 500;
}
.modal-status-value {
    font-size: 0.78rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
}

/* Farm type rows */
.farm-type-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border-subtle);
}
.farm-type-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 1.3rem;
    text-align: center;
}
.legend-icon {
    font-size: 1rem;
    margin-right: 2px;
}
.farm-type-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.farm-type-name {
    flex: 1;
    font-size: 0.88rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.farm-type-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    color: var(--accent);
    font-weight: 600;
    min-width: 45px;
    text-align: right;
}
.farm-type-bar {
    width: 70px;
    height: 6px;
    background: var(--bg-active);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}
.farm-type-bar-fill {
    height: 100%;
    border-radius: 3px;
}
.farm-type-pct {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
}

/* Farm type edit rows */
.farm-type-edit-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-subtle);
}
.farm-type-edit-name {
    flex: 1;
    font-size: 0.85rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}
.farm-type-edit-count {
    width: 75px !important;
    flex: none !important;
}
.farm-type-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    opacity: 0.5;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}
.farm-type-edit-row:hover .farm-type-remove-btn { opacity: 1; }
.farm-type-remove-btn:hover {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}
.farm-type-add-btn {
    margin-top: 0.5rem;
    width: 100%;
    text-align: center;
    border: 1px dashed var(--border-default) !important;
    color: var(--text-muted);
}
.farm-type-add-btn:hover {
    border-color: var(--accent) !important;
    color: var(--accent);
}
.farm-type-add-panel {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    padding: 0.6rem;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
}
.farm-type-add-panel select {
    flex: 1;
    min-width: 120px;
}
.farm-type-new-panel {
    margin-top: 0.5rem;
    padding: 0.5rem 0.6rem;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
}
.farm-type-color-swatches {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.4rem;
    flex-wrap: wrap;
}
.farm-type-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s;
}
.farm-type-color-swatch:hover { transform: scale(1.15); }
.farm-type-color-swatch.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-surface);
}

/* ── Order Status Select ────────────────────── */
.order-status-select {
    padding: 0.15rem 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
}

/* ── Visit Modal ─────────────────────────────── */
.modal-edit-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
.visit-section-divider {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 1.2rem 0 0.8rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.visit-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-default);
}
.visit-product-row {
    background: var(--bg-surface-raised, #f8fafc);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    padding: 0.7rem;
    margin-bottom: 0.5rem;
}
.visit-product-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.4rem;
}
.visit-product-name {
    font-weight: 600;
    font-size: 0.9rem;
}
.visit-product-fields {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    margin-bottom: 0.4rem;
}
.visit-product-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.visit-product-field-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
}
.visit-product-qty,
.visit-product-price {
    width: 80px;
}
.visit-product-unit {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.visit-product-total {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--success);
    white-space: nowrap;
    padding: 0.35rem 0;
}
.visit-product-notes {
    font-size: 0.8rem;
    margin-top: 0.2rem;
}
@media (max-width: 480px) {
    .visit-product-fields { flex-wrap: wrap; }
    .visit-product-qty,
    .visit-product-price { width: 65px; }
}

/* Visit / Order list rows */
.modal-list-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
}
.modal-list-row-pad {
    padding: 0.5rem 0;
}
.modal-list-bordered {
    border-bottom: 1px solid var(--border-subtle);
}
.modal-list-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}
.modal-list-date {
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
}
.modal-list-badge {
    font-size: 0.72rem;
    padding: 1px 6px;
    border-radius: 4px;
    color: #fff;
    white-space: nowrap;
}
.modal-list-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40%;
    text-align: right;
}
.modal-list-amount {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    flex-shrink: 0;
}
.modal-list-note {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin: 0.1rem 0 0.3rem;
    padding-left: 0.25rem;
}
.modal-list-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 0.3rem;
}
.modal-list-tag {
    font-size: 0.72rem;
}
.modal-list-expand {
    width: 100%;
    margin-top: 0.5rem;
    font-size: 0.78rem;
}

/* Clickable date for detail toggle */
.modal-list-clickable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}
.modal-list-clickable:hover {
    color: var(--accent);
}

/* Order items vertical list */
.order-block {
    padding-bottom: 0.4rem;
}
.order-items-list {
    padding: 0.2rem 0 0.2rem 0.25rem;
}
.order-item-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.15rem 0;
    font-size: 0.8rem;
}
.order-item-desc {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    min-width: 0;
    flex: 1;
}
.order-item-name {
    font-weight: 500;
    white-space: nowrap;
}
.order-item-qty {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}
.order-item-total {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.order-item-note {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 1px;
}
.record-detail-item-note {
    width: 100%;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 1px;
}

/* Record detail panel (visits & orders) */
.record-detail {
    background: var(--bg-surface-alt, #f8f9fa);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    margin: 0.3rem 0 0.4rem;
    font-size: 0.8rem;
}
.record-detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.2rem 0.8rem;
    align-items: center;
}
.record-detail-label {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.record-detail-subtitle {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 0.5rem;
    margin-bottom: 0.25rem;
    letter-spacing: 0.02em;
}
.record-detail-items {
    border-top: 1px solid var(--border-subtle);
    padding-top: 0.25rem;
}
.record-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.15rem 0;
    font-size: 0.78rem;
}
.record-detail-item-name {
    color: var(--text-primary);
}
.record-detail-item-price {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--accent);
    white-space: nowrap;
    margin-left: 0.5rem;
}

/* Order history */
.order-history { margin-top: 0.5rem; }
.order-history-entry {
    border-left: 2px solid var(--accent);
    padding: 0.375rem 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-surface);
    border-radius: 0 0.375rem 0.375rem 0;
}
.order-history-meta { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.order-history-change { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; }

/* Order edit form */
.order-edit-form { padding: 0.75rem 0 0; }
.order-edit-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}
.order-edit-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.375rem;
}
.order-edit-item-name {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-primary);
}
.order-edit-item-fields {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}
.order-edit-field {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.order-edit-field label {
    font-size: 0.72rem;
    color: var(--text-muted);
}
.order-edit-field input {
    width: 5rem;
    padding: 0.25rem 0.375rem;
    border: 1px solid var(--border-default);
    border-radius: 0.375rem;
    font-size: 0.8rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.oe-total {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.82rem;
}
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-muted);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    line-height: 1;
}
.btn-icon:hover { color: var(--danger, #ef4444); background: rgba(239,68,68,0.08); }

/* Task add row */
.task-add-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

/* Status + nav row (legacy) */
.modal-status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

/* === Region Tabs === */
.region-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-subtle);
    margin-bottom: 0.5rem;
}
.region-tab {
    padding: 0.5rem 1rem;
    font-size: 0.82rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}
.region-tab:hover {
    color: var(--text-primary);
}
.region-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.region-tab-content {
    display: none;
}
.region-tab-content.active {
    display: block;
}

/* === Edit mode styles === */
.modal-edit-field {
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    font-family: 'Outfit', sans-serif;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    transition: border-color 0.2s;
}
.modal-edit-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.15);
}
.modal-edit-select {
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    font-family: 'Outfit', sans-serif;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
}
.modal-edit-select:focus {
    outline: none;
    border-color: var(--accent);
}
.modal-btn-row {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.btn-visited {
    background: var(--success);
    color: #fff;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-visited:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}
.btn-visited-done {
    background: var(--success) !important;
    animation: visitedPulse 0.4s ease;
}
@keyframes visitedPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}
/* Mark for Visit button */
.btn-marked {
    background: transparent;
    color: var(--accent);
    font-weight: 500;
    border: 1px solid var(--accent);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-marked:hover {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    transform: translateY(-1px);
}
.btn-marked-active {
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    border: 1px solid var(--accent);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-marked-active:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Task rows in client modal */
.task-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.25rem;
}
.task-row:hover {
    background: var(--bg-elevated);
}
.task-row.task-completed {
    opacity: 0.6;
}
.task-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.task-row:hover .task-delete-btn {
    opacity: 1;
}
.task-delete-btn:hover {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* Admin panel */
.admin-user-row:hover { background: var(--bg-hover); }
.admin-user-row.admin-user-selected { background: var(--accent-subtle); border-left: 3px solid var(--accent); }
.admin-user-row.frozen-row { opacity: 0.6; }

.admin-region-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border-subtle);
}
.admin-region-item:last-child { border-bottom: none; }
.admin-region-item:hover { background: var(--bg-elevated); }

.admin-region-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
    background: var(--bg-elevated); border: 1px solid var(--border-default);
    border-radius: var(--radius-sm); max-height: 200px; overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.admin-region-dd-item {
    padding: 0.4rem 0.7rem; font-size: 0.82rem; cursor: pointer;
    color: var(--text-primary);
}
.admin-region-dd-item:hover { background: var(--bg-hover); }

.btn-edit-mode {
    background: var(--bg-active);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-edit-mode:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-edit-inline {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 0.85em;
    padding: 0.1rem 0.3rem; border-radius: var(--radius-sm);
    vertical-align: middle; margin-left: 0.3rem;
    transition: color 0.15s;
}
.btn-edit-inline:hover { color: var(--accent); }

/* Toast notification inside modal */
.modal-toast {
    position: absolute;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    padding: 0.45rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: 'Outfit', sans-serif;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    white-space: nowrap;
}
.modal-toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.modal-toast-success {
    background: var(--success);
    color: #fff;
}
.modal-toast-error {
    background: var(--danger);
    color: #fff;
}

/* === Sales Suggestion Blocks === */
.suggestion-block {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
}
.suggestion-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.35rem;
}
.suggestion-animal {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}
.suggestion-peer-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
}
.suggestion-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
.suggestion-products {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.suggestion-product {
    display: grid;
    grid-template-columns: 1fr 40px 60px;
    align-items: center;
    gap: 0.4rem;
}
.suggestion-product-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
}
.suggestion-product-pct {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-align: right;
}
.suggestion-bar {
    height: 5px;
    background: var(--bg-active);
    border-radius: 3px;
    overflow: hidden;
}
.suggestion-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s;
}
.suggestion-action {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 500;
    margin-top: 0.5rem;
    padding-top: 0.35rem;
    border-top: 1px dashed var(--border-subtle);
}

/* === Mobile toggle === */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1.3rem;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 950;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.mobile-toggle:hover { background: var(--bg-hover); }

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* === Tablet: <=1024px === */
@media (max-width: 1024px) {
    .region-layout {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
    }
    .region-layout .map-col { grid-column: 1; }
    .region-layout .stats-col { grid-column: 1; }
    .region-layout .map-col .card-body > div { min-height: 350px; }

    .dash-grid {
        grid-template-columns: 1fr;
    }
}

/* === Mobile: <=768px === */
@media (max-width: 768px) {
    /* Sidebar off-canvas */
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 40px rgba(0,0,0,0.5);
    }

    .mobile-toggle { display: flex; }

    .main-content { margin-left: 0; }

    /* Page header — room for hamburger */
    .page-header {
        padding: 0.85rem 1rem 0.85rem 3.5rem;
        gap: 0.5rem;
    }
    .page-title { font-size: 1.15rem; }
    .page-subtitle { font-size: 0.78rem; }

    .page-body { padding: 1rem; }

    /* Stat cards: 2-col grid */
    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.5rem; }
    .stat-label { font-size: 0.7rem; }

    /* Cards compact */
    .card-header {
        padding: 0.85rem 1rem;
        flex-wrap: wrap;
    }
    .card-title { font-size: 0.9rem; }
    .card-body { padding: 1rem; }

    /* Dashboard grid → single column */
    .dash-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Tables tighter */
    .data-table th,
    .data-table td {
        padding: 0.6rem 0.5rem;
        font-size: 0.78rem;
    }
    .data-table th { font-size: 0.68rem; }

    /* Filter bar */
    .filter-bar { gap: 0.5rem; }

    /* Modal: near full-screen */
    .modal {
        width: 96%;
        max-width: 96%;
        max-height: 92vh;
        border-radius: var(--radius-lg);
    }
    .modal-header { padding: 0.6rem 1rem; }
    .modal-body { padding: 0.6rem 0.85rem; }
    .modal-footer { padding: 0.5rem 0.85rem; }
    .modal-title { font-size: 0.95rem; }
    .modal-close { font-size: 1.1rem; }

    /* Footer: icon-only buttons, compact layout */
    .modal-footer .btn-label { display: none; }
    .modal-footer-row { gap: 0.4rem; }
    .modal-footer-status { gap: 0.5rem; }
    .modal-footer-actions { gap: 0.3rem; }
    .modal-footer-btn { padding: 0.3rem 0.6rem; }
    .modal-status-label { font-size: 0.65rem; }
    .modal-status-value { font-size: 0.72rem; padding: 1px 6px; }

    /* Contact rows: compact */
    .contact-row-main {
        flex-wrap: wrap;
        gap: 0.25rem 0.4rem;
        padding: 0.45rem 0.65rem;
        min-height: 36px;
    }
    .contact-row-label { min-width: 70px; font-size: 0.65rem; }
    .contact-row-name { font-size: 0.8rem; }
    .contact-row-phone { font-size: 0.75rem; padding: 0.1rem 0.35rem; }
    .contact-row-details.open { padding: 0.35rem 0.65rem 0.5rem; }

    /* Grids → single column */
    .modal-info-grid {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
    .modal-finance-row {
        flex-direction: row;
        gap: 0.5rem;
    }
    .modal-finance-box { padding: 0.5rem 0.65rem; }
    .modal-finance-label { font-size: 0.6rem; }
    .modal-finance-value { font-size: 0.88rem; }

    /* Section headers */
    .modal-section-header { margin: 0.85rem 0 0.35rem; padding-bottom: 0.25rem; }
    .modal-section-title { font-size: 0.7rem; }
    .modal-section-right { font-size: 0.68rem; }

    /* Farm types compact */
    .farm-type-row { gap: 0.35rem; padding: 0.35rem 0; }
    .farm-type-name { font-size: 0.78rem; }
    .farm-type-count { font-size: 0.75rem; min-width: 38px; }
    .farm-type-bar { width: 45px; height: 5px; }
    .farm-type-pct { font-size: 0.68rem; min-width: 32px; }

    /* Visit/Order list */
    .modal-list-date { font-size: 0.75rem; }
    .modal-list-badge { font-size: 0.65rem; padding: 1px 5px; }
    .modal-list-meta { font-size: 0.72rem; max-width: 35%; }
    .modal-list-amount { font-size: 0.78rem; }
    .modal-list-note { font-size: 0.72rem; }
    .modal-list-tag { font-size: 0.65rem; }

    /* Tasks */
    .task-add-row { gap: 0.35rem; }
    .task-row { padding: 0.3rem 0.35rem; }

    /* Suggestions compact */
    .suggestion-block { padding: 0.5rem; margin-bottom: 0.5rem; }
    .suggestion-header { gap: 0.3rem; }
    .suggestion-animal { font-size: 0.78rem; }
    .suggestion-text { font-size: 0.72rem; }
    .suggestion-product-name { font-size: 0.72rem; }
    .suggestion-action { font-size: 0.68rem; }

    /* Region layout */
    .region-layout {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
        gap: 1rem;
    }
    #regionLeafletMap { min-height: 300px !important; }

    /* Region filters compact */
    .region-filters-card { margin-top: 0.75rem; }
    .region-filters-body { padding: 0.5rem 0.75rem; }
    .region-filter-row { gap: 0.35rem; }
    .region-filter-group { gap: 0.25rem; }
    .region-filter-label { font-size: 0.72rem; }
    .region-filter-row .btn-sm { padding: 0.25rem 0.45rem; font-size: 0.7rem; }

    /* Region chart/legend compact */
    .region-chart-wrap canvas { max-height: 180px; }
    .region-chart-hint { font-size: 0.68rem; margin-bottom: 0.5rem; }
    .region-legend-row { padding: 0.25rem 0.35rem; }
    .region-legend-name { font-size: 0.78rem; }
    .region-legend-value { font-size: 0.78rem; }
    .region-legend-pct { font-size: 0.68rem; }
    .region-sales-total-value { font-size: 1.25rem; }
    .region-sort-select { min-width: 120px; font-size: 0.78rem; }

    /* Region assigned compact */
    .region-assigned { margin-top: 0.75rem; padding-top: 0.5rem; }
    .region-assigned-name { font-size: 0.78rem; }
    .region-assigned-phone { font-size: 0.72rem; }

    /* Period selector compact */
    .chart-period-btn {
        padding: 0.35rem 0.6rem !important;
        font-size: 0.72rem !important;
    }

    /* Auth */
    .auth-card { padding: 2rem 1.5rem; }

    /* Hide optional columns */
    .hide-mobile { display: none !important; }
}

/* === Small phone: <=480px === */
@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .stat-card { padding: 0.75rem; }
    .stat-value { font-size: 1.25rem; }

    .page-header { padding: 0.75rem 0.75rem 0.75rem 3rem; }
    .page-body { padding: 0.75rem; }
    .page-title { font-size: 1rem; }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.35rem;
        font-size: 0.72rem;
    }

    .btn-sm { padding: 0.3rem 0.55rem; font-size: 0.72rem; }

    /* Modal → bottom sheet style */
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 96vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        margin: 0;
        align-self: flex-end;
    }
    .modal-overlay { align-items: flex-end; }
    .modal-header { padding: 0.5rem 0.75rem; }
    .modal-body { padding: 0.5rem 0.75rem; }
    .modal-footer { padding: 0.4rem 0.75rem; }
    .modal-title { font-size: 0.88rem; }
    .modal-close { font-size: 1rem; padding: 0.15rem; }
    .modal-footer .btn-label { display: none; }

    /* Footer even tighter */
    .modal-footer-row { gap: 0.3rem; }
    .modal-footer-status { gap: 0.35rem; }
    .modal-status-label { font-size: 0.6rem; }
    .modal-status-value { font-size: 0.68rem; padding: 1px 5px; }
    .modal-footer-btn { padding: 0.25rem 0.5rem; font-size: 0.72rem; }

    /* Contact compact */
    .contact-row-main { padding: 0.35rem 0.5rem; min-height: 32px; }
    .contact-row-label { min-width: 55px; font-size: 0.6rem; }
    .contact-row-name { font-size: 0.75rem; }
    .contact-row-phone { font-size: 0.7rem; }

    /* Finance side-by-side but smaller */
    .modal-finance-box { padding: 0.4rem 0.5rem; }
    .modal-finance-label { font-size: 0.55rem; }
    .modal-finance-value { font-size: 0.82rem; }

    /* Section headers */
    .modal-section-header { margin: 0.65rem 0 0.3rem; }
    .modal-section-title { font-size: 0.65rem; }

    /* Farm types */
    .farm-type-name { font-size: 0.72rem; }
    .farm-type-count { font-size: 0.7rem; min-width: 32px; }
    .farm-type-bar { width: 35px; }
    .farm-type-pct { font-size: 0.62rem; min-width: 28px; }

    /* Farm type edit */
    .farm-type-add-panel { flex-direction: column; align-items: stretch; }
    .farm-type-add-panel select { width: 100%; }
    .farm-type-edit-count { width: 60px !important; }
    .farm-type-edit-name { font-size: 0.78rem; }

    /* Lists */
    .modal-list-row { padding: 0.3rem 0; }
    .modal-list-date { font-size: 0.72rem; }
    .modal-list-amount { font-size: 0.72rem; }
    .modal-list-meta { font-size: 0.68rem; }

    /* Region page: extra compact */
    .region-filters-body { padding: 0.4rem 0.6rem; }
    .region-filter-label { font-size: 0.68rem; }
    .region-filter-row .btn-sm { padding: 0.2rem 0.35rem; font-size: 0.65rem; }
    .region-chart-wrap canvas { max-height: 150px; }
    .region-legend-name { font-size: 0.72rem; }
    .region-legend-value { font-size: 0.72rem; }
    .region-sales-total-value { font-size: 1.1rem; }
    .region-sort-select { min-width: 100px; font-size: 0.72rem; }
    .region-assigned-name { font-size: 0.72rem; }
    .region-assigned-phone { font-size: 0.68rem; }
    .region-empty-state { padding: 1rem 0.5rem; font-size: 0.78rem; }
}

/* === Utility === */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.mb-3  { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.flex  { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-col     { display: flex; flex-direction: column; }
.hidden { display: none; }

/* === Theme Toggle === */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
}

.theme-toggle-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

.theme-toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-active);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition);
    border: 1px solid var(--border-default);
    flex-shrink: 0;
}

.theme-toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.theme-toggle-switch.active::after {
    transform: translateX(20px);
}

/* Sun/Moon icons inside toggle */
.theme-toggle-switch .theme-icon-dark,
.theme-toggle-switch .theme-icon-light {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    line-height: 1;
    pointer-events: none;
    z-index: 1;
}
.theme-toggle-switch .theme-icon-dark {
    right: 5px;
}
.theme-toggle-switch .theme-icon-light {
    left: 5px;
}

/* ============================================================
   Route planner layout (desktop base) + mobile enhancements.
   Desktop rules stay outside media queries and are unchanged.
   ============================================================ */
.route-planner-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 1rem;
    align-items: start;
}

/* Tablet & down: stack route planner (map under the controls) */
@media (max-width: 900px) {
    .route-planner-grid { grid-template-columns: 1fr; }
    .route-planner-grid .card:last-child { position: static !important; }
    #routeMap { height: 50vh !important; min-height: 320px; }
}

/* ── Mobile polish for the newer features (<=768px) ── */
@media (max-width: 768px) {
    /* ERP finance: 2×2 grid instead of a cramped single row */
    .modal-finance-row { flex-wrap: wrap; }
    .modal-finance-box { flex: 1 1 44%; min-width: 0; }

    /* Any wide table inside a modal scrolls horizontally, never overflows */
    .modal-body table { min-width: 0; }
    .modal-body .erp-scroll,
    .modal-body [style*="overflow"] { -webkit-overflow-scrolling: touch; }

    /* Route planner controls: bigger touch targets, full-width buttons row */
    .route-planner-grid .btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
    #stopsList .btn-ghost.btn-sm { padding: 0.35rem 0.5rem; }

    /* Client standalone page card: full width */
    .page-body > .card[style*="max-width"] { max-width: 100% !important; }

    /* Settings form fields stack */
    .settings-form-grid { grid-template-columns: 1fr !important; }

    /* Bigger tap targets for icon buttons in tables */
    .data-table .btn-sm { padding: 0.35rem 0.55rem; }

    /* ERP period date inputs (two side by side) don't overflow — only those;
       the visit form's date fields stay full width */
    input[type="date"][id^="erpFrom"], input[type="date"][id^="erpTo"] { max-width: 46%; }
}

/* ── Small phones (<=430px) ── */
@media (max-width: 430px) {
    .modal-finance-box { flex: 1 1 46%; }
    .modal-finance-value { font-size: 0.82rem; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .page-title { font-size: 1.05rem; }
    /* Route: start controls stack cleanly */
    .route-planner-grid input[type="text"] { min-width: 0; }
}

/* ============================================================
   .btn-accent was referenced by the client modal and the route
   planner but never defined — those buttons rendered as bare text.
   ============================================================ */
.btn-accent {
    background: var(--accent);
    color: var(--text-inverse, #fff);
    border-color: var(--accent);
}
.btn-accent:hover {
    background: var(--accent-hover, var(--accent));
    color: var(--text-inverse, #fff);
}

/* ============================================================
   MOBILE PASS — appended last on purpose: an earlier max-width:768
   block sits after the max-width:480 one, so only rules declared
   here are guaranteed to win without !important.
   Desktop is untouched: everything below is inside a media query.
   ============================================================ */
@media (max-width: 768px) {

    /* ── Drawer must sit above the sticky header, and stay on screen
          when iOS shows its URL bar (footer holds Изход) ── */
    .sidebar         { z-index: 940; height: 100vh; height: 100dvh; }
    .sidebar-overlay { z-index: 930; }
    .sidebar-nav     { overscroll-behavior: contain; }

    /* ── Metric tabs were clipped by .card{overflow:hidden}: eight
          nowrap tabs need ~700px, so Визити / Нови клиенти vanished ── */
    .dash-tabs, .region-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
    }
    .dash-tabs::-webkit-scrollbar,
    .region-tabs::-webkit-scrollbar { display: none; }
    .dash-tab, .region-tab {
        flex: 0 0 auto;
        padding: 0.6rem 0.85rem;
        font-size: 0.8rem;
        min-height: 44px;
    }
    /* the -2px underline is eaten by the scroll container — draw it inside */
    .dash-tab.active, .region-tab.active {
        border-bottom-color: transparent;
        box-shadow: inset 0 -2px 0 var(--accent);
    }
    .dash-tab-content canvas { max-height: 280px; }

    /* ── Modal: the only way out was a 20px ✕ ── */
    .modal-close {
        width: 44px; height: 44px; padding: 0;
        font-size: 1.4rem;
        display: flex; align-items: center; justify-content: center;
        margin: -0.4rem -0.5rem -0.4rem 0;
    }
    /* two header buttons (↗ + ✕): only the outer one bleeds into the edge */
    .modal-close:not(:last-child) { margin: -0.4rem 0; }
    .modal-footer-row     { flex-wrap: wrap; row-gap: 0.45rem; }
    .modal-footer-actions { gap: 0.5rem; width: 100%; }
    .modal-footer-btn {
        flex: 1 1 0;
        min-height: 44px;
        padding: 0 0.7rem;
        font-size: 1.05rem;
        justify-content: center;
    }
    .modal-body { overscroll-behavior: contain; }

    /* ── 2×2 finance grid: `.modal-finance-row > div{flex:1}` outranked
          the existing single-class rule, so all four stayed in one row ── */
    .modal-finance-row > .modal-finance-box { flex: 1 1 44%; min-width: 0; }

    /* ── iOS zooms any focused field under 16px and never zooms back ── */
    .form-input, .form-select, .form-textarea,
    .modal-edit-field, .modal-edit-select,
    .settings-form-field input,
    .settings-form-field select,
    .settings-form-field textarea,
    input[type="text"], input[type="email"], input[type="tel"],
    input[type="password"], input[type="number"], input[type="search"],
    input[type="date"], select, textarea { font-size: 16px; }
    /* these carry an inline font-size */
    .modal-body input[id^="erpFrom_"],
    .modal-body input[id^="erpTo_"],
    #clientsSearchInput, .data-table select,
    #adminUserSearch, #startManual, #stopSearch { font-size: 16px !important; }

    /* ── Region status filters: 13 pills at ~21px tall ── */
    .region-filter-row .btn-sm {
        display: inline-flex; align-items: center;
        min-height: 40px;
        padding: 0.5rem 0.7rem;
        font-size: 0.78rem;
    }
    .region-filter-group { gap: 0.4rem; }
    .region-filters-body { padding: 0.75rem; }
    .region-legend-row   { padding: 0.55rem 0.5rem; min-height: 44px; }

    /* ── Route planner reorder/remove (inline padding → needs !important) ── */
    #stopsList .btn-ghost.btn-sm {
        padding: 0.55rem 0.7rem !important;
        min-width: 44px; min-height: 44px;
        font-size: 1rem;
    }

    /* ── ERP period row in the client modal (all inline-styled) ── */
    .modal-body input[id^="erpFrom_"],
    .modal-body input[id^="erpTo_"] {
        flex: 1 1 45%; max-width: 48%;
        min-height: 40px;
        padding: 6px 8px !important;
    }
    .modal-body button[onclick^="clientErpPeriod"],
    .modal-body [id^="erpInvBtn_"],
    .modal-body [id^="erpRefreshBtn_"] {
        min-height: 40px;
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
    }
    .modal-body input[id^="erpOverdueOnly_"] { width: 22px; height: 22px; }
    .modal-section-header { flex-wrap: wrap; row-gap: 0.35rem; }

    /* ── Invoice table: 7 columns in ~337px wrapped into a wall ── */
    [id^="erpInvoices_"] table { min-width: 560px; }
    [id^="erpInvoices_"] > div[style*="overflow"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ── Hover-only controls have no touch equivalent ── */
    .task-row { min-height: 44px; padding: 0.5rem 0.35rem; }
    .task-row input[type="checkbox"] { width: 22px !important; height: 22px !important; }
    .task-delete-btn { opacity: 1; font-size: 0.9rem; padding: 0.5rem 0.65rem; }
    .farm-type-edit-row   { min-height: 44px; }
    .farm-type-remove-btn { opacity: 1; padding: 0.5rem 0.65rem; font-size: 1.3rem; }
    .farm-type-edit-count { width: 72px !important; min-height: 40px; }
    .farm-type-color-swatch { width: 36px; height: 36px; }

    /* ── Calling the farm is the highest-value tap in the app ── */
    .contact-row-main  { min-height: 48px; gap: 0.5rem; }
    .contact-row-phone {
        display: inline-flex; align-items: center;
        min-height: 40px;
        padding: 0.35rem 0.65rem;
        font-size: 0.82rem;
    }

    /* ── Headers and long unbroken strings (ЕИК, emails, coords) ── */
    .page-header { flex-wrap: wrap; row-gap: 0.5rem; }
    .page-header > :first-child { min-width: 0; flex: 1 1 100%; }
    .page-title, .page-subtitle { overflow-wrap: anywhere; }
    /* break-word (not anywhere): long strings still wrap, but columns keep
       their natural width so wide tables scroll instead of breaking dates */
    .data-table td { overflow-wrap: break-word; }
    .modal-info-grid,
    .contact-row-detail-value,
    .settings-item-meta { overflow-wrap: anywhere; }

    /* ── Table controls ── */
    .data-table .btn-sm { min-height: 40px; padding: 0.45rem 0.7rem; }
    .data-table select,
    .order-status-select { min-height: 40px; padding: 0.4rem 0.5rem !important; }
    .period-pill { min-height: 36px; padding: 0.4rem 0.7rem !important; }

    /* ── Settings ── */
    .settings-icon-btn { width: 44px; height: 44px; }
    .settings-item     { min-height: 56px; }
    .color-picker-row input[type="color"] { width: 56px; height: 44px; }

    /* ── Admin: a trapped inner scroll region on a phone ── */
    .admin-grid > .card { max-height: none; }
    .admin-grid > .card > .table-wrapper,
    .admin-grid > .card > .card-body { overflow-y: visible; }
}

@media (max-width: 480px) {
    /* the wrapper kept 2rem of padding on a 360px screen */
    .auth-wrapper { padding: 1rem 0.75rem; }
    .auth-card    { padding: 1.5rem 1.1rem; }
}
