/* ============================================
   TerritoryApp — Base Styles
   ============================================ */

:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-border: #e2e8f0;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-success: #16a34a;
    --color-success-hover: #15803d;
    --color-warning: #d97706;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* === Reset === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* === Base typography === */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    font-weight: 600;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    display: block;
}

/* === Layout === */
main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* === Utility === */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.text-muted {
    color: var(--color-text-secondary);
}

/* ============================================
   Admin Panel Styles
   ============================================ */

/* Header */
.admin-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
}

.admin-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56px;
}

.admin-logo {
    font-size: 18px;
    font-weight: 700;
}

.admin-logo span {
    color: var(--color-primary);
    font-weight: 500;
}

/* Navigation */
.admin-nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
}

.admin-nav .nav-link {
    display: inline-block;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.admin-nav .nav-link:hover {
    color: var(--color-text);
    text-decoration: none;
}

.admin-nav .nav-link.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* Logout sits in the admin-nav, identical in style to regular nav links —
   just pushed to the right edge and with a button reset so it behaves as
   a regular <button> tag. All other visuals (padding, font, underline,
   hover) come straight from `.admin-nav .nav-link`. */
.admin-nav .nav-link-logout {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

/* admin-nav is a flex row so margin-left:auto on logout works */
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

/* Main content */
.admin-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 1.5rem;
}

/* Filters */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.filters input,
.filters select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--color-surface);
    color: var(--color-text);
}

.filters input {
    min-width: 220px;
}

.filters input:focus,
.filters select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Table */
.table-responsive {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.admin-table th {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.admin-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
    font-size: 14px;
}

.admin-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.02);
}

.admin-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

.admin-table th.sortable:hover {
    color: var(--color-primary);
}

.sort-arrow {
    display: inline-block;
    margin-left: 4px;
    font-size: 11px;
    color: var(--color-primary);
}

.sort-arrow.inactive {
    color: var(--color-text-secondary);
    opacity: 0.4;
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

.actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 6px;
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-active {
    background: #d1fae5;
    color: #065f46;
}

.badge-inactive {
    background: #fee2e2;
    color: #991b1b;
}

/* Buttons */
.btn {
    padding: 6px 14px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: opacity 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    opacity: 0.85;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

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

.btn-ghost {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-ghost:hover {
    background: var(--color-bg);
}

/* Modal */
/* Ensure hidden attribute always works even with display:flex/grid */
[hidden] {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 28px;
    max-width: 520px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-text);
}

/* Detail grid in modal */
.detail-grid {
    display: grid;
    gap: 8px;
}

.detail-row {
    font-size: 14px;
    padding: 6px 0;
    border-bottom: 1px solid var(--color-border);
}

.detail-row strong {
    display: inline-block;
    min-width: 120px;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.detail-list {
    list-style: none;
    padding: 0;
}

.detail-list li {
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--color-border);
}

.detail-list li:last-child {
    border-bottom: none;
}

/* Skeleton loader */
.skeleton {
    background: linear-gradient(90deg,
        var(--color-border) 25%,
        #f1f5f9 50%,
        var(--color-border) 75%);
    background-size: 200% 100%;
    animation: skeleton-wave 1.4s ease infinite;
    border-radius: 4px;
    height: 16px;
}

@keyframes skeleton-wave {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Pagination */
.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
}

.page-btn {
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    font-size: 14px;
}

.page-btn:hover {
    background: var(--color-bg);
}

.page-btn.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    z-index: 200;
    animation: toast-in 0.2s ease;
}

.toast-success {
    background: #059669;
}

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

@keyframes toast-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--color-text-secondary);
    font-size: 15px;
}

/* ============================================
   Territory Import Styles
   ============================================ */

/* Import card */
.import-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 32px;
}

.import-card h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* Drag-and-drop zone */
.drop-zone {
    border: 2px dashed var(--color-border);
    border-radius: 12px;
    padding: 48px 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    color: var(--color-text-secondary);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.03);
    color: var(--color-text);
}

.drop-zone-icon {
    font-size: 40px;
    margin-bottom: 12px;
    display: block;
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--color-border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

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

/* Import result */
.import-result {
    display: flex;
    gap: 24px;
    padding: 16px;
    background: var(--color-bg);
    border-radius: 8px;
    margin-top: 12px;
}

.import-stat {
    font-size: 14px;
}

.import-stat strong {
    display: block;
    font-size: 22px;
    font-weight: 700;
}

.stat-created { color: #059669; }
.stat-updated { color: #2563eb; }
.stat-total   { color: var(--color-text); }

/* Territory color dot */
.territory-color-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    vertical-align: middle;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Territory status badges */
.badge-available { background: #d1fae5; color: #065f46; }
.badge-assigned  { background: #dbeafe; color: #1e40af; }

/* ============================================
   Assignment Styles
   ============================================ */

/* Assignments summary */
.assignments-summary h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-count {
    background: var(--color-primary);
    color: #fff;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
}

/* Publisher search in modal */
.search-results {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 4px;
}

.search-results:empty {
    border: none;
}

.search-result-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.1s;
}

.search-result-item:hover {
    background: rgba(37, 99, 235, 0.04);
}

.search-result-item:not(:last-child) {
    border-bottom: 1px solid var(--color-border);
}

/* Selected publisher */
#selected-publisher {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(37, 99, 235, 0.04);
    border-radius: 6px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 500;
}

/* Wide modal for history */
.modal-wide {
    max-width: 640px;
}

/* =========================================================
   Publisher modal (on /admin/index.html)
   Separate from the generic .modal-overlay pattern — uses .active toggle
   ========================================================= */
.publisher-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.publisher-modal.active {
    display: flex;
    animation: pm-fade-in 0.15s ease-out;
}

@keyframes pm-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.publisher-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.publisher-modal-dialog {
    position: relative;
    background: var(--color-surface);
    border-radius: 14px;
    width: 100%;
    max-width: 760px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: pm-pop-in 0.18s ease-out;
}

@keyframes pm-pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.publisher-modal-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.04), transparent);
}

.pm-avatar {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #1e40af);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.pm-header-main {
    flex: 1;
    min-width: 0;
}

.pm-name {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 6px 0;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pm-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    font-size: 13px;
    color: var(--color-text-secondary);
}

.pm-meta .badge {
    font-size: 11px;
}

.pm-phone {
    font-family: monospace;
    font-weight: 600;
    color: var(--color-text);
}

.pm-registered::before {
    content: '📅 ';
}

.pm-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.pm-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-text);
}

/* Tabs */
.pm-tabs {
    display: flex;
    gap: 2px;
    padding: 0 24px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.pm-tab {
    background: none;
    border: none;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.15s, border-color 0.15s;
}

.pm-tab:hover {
    color: var(--color-text);
}

.pm-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.pm-tab-count {
    background: rgba(37, 99, 235, 0.1);
    color: var(--color-primary);
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}

/* Body with tab panels */
.pm-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    min-height: 200px;
}

.pm-panel {
    display: none;
}

.pm-panel.active {
    display: block;
}

.pm-map {
    width: 100%;
    height: 280px;
    border-radius: 8px;
    background: #f3f4f6;
    border: 1px solid var(--color-border);
    overflow: hidden;
}

/* Footer */
.publisher-modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    .publisher-modal {
        padding: 0;
    }
    .publisher-modal-dialog {
        max-height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }
    .publisher-modal-header {
        padding: 16px;
        gap: 12px;
    }
    .pm-avatar {
        width: 48px;
        height: 48px;
        font-size: 17px;
    }
    .pm-name {
        font-size: 17px;
    }
    .pm-tabs {
        padding: 0 8px;
    }
    .pm-tab {
        padding: 10px 12px;
        font-size: 12px;
    }
    .pm-body {
        padding: 14px 16px;
    }
    .publisher-modal-footer {
        padding: 12px 16px;
    }
    .publisher-modal-footer .btn {
        flex: 1;
        min-width: 0;
        font-size: 12px;
    }
}

/* Publisher detail page */
.back-link {
    display: inline-block;
    font-size: 13px;
    color: var(--color-text-secondary);
    text-decoration: none;
    margin-bottom: 16px;
    transition: color 0.15s;
}

.back-link:hover {
    color: var(--color-primary);
}

.publisher-header {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    flex-wrap: wrap;
}

.publisher-header-main {
    flex: 1;
    min-width: 260px;
}

.publisher-name {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 12px 0;
}

.publisher-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
}

.publisher-meta-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.publisher-meta-row span {
    color: var(--color-text-secondary);
    min-width: 160px;
}

.publisher-meta-row strong {
    color: var(--color-text);
    font-weight: 600;
}

.publisher-header-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 200px;
}

.publisher-header-actions .btn {
    justify-content: center;
}

.publisher-section {
    margin-bottom: 28px;
}

.publisher-section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text);
}

.publisher-map {
    width: 100%;
    height: 300px;
    border-radius: 10px;
    overflow: hidden;
    background: #f3f4f6;
    border: 1px solid var(--color-border);
}

/* Days-active row highlights */
.admin-table tr.row-warning {
    background: #fef9c3;
}

.admin-table tr.row-warning:hover {
    background: #fef08a;
}

.admin-table tr.row-danger {
    background: #fee2e2;
}

.admin-table tr.row-danger:hover {
    background: #fecaca;
}

/* Accordion */
.publisher-accordion-toggle {
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 14px 18px;
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s;
}

.publisher-accordion-toggle:hover {
    background: rgba(37, 99, 235, 0.04);
}

.publisher-accordion-toggle .badge-count {
    margin-left: 0;
}

.publisher-accordion-toggle .accordion-arrow {
    margin-left: auto;
    font-size: 18px;
    transition: transform 0.2s;
    color: var(--color-text-secondary);
}

.publisher-accordion-toggle.expanded .accordion-arrow {
    transform: rotate(180deg);
}

.publisher-accordion-body {
    margin-top: 10px;
    animation: accordion-open 0.2s ease-out;
}

@keyframes accordion-open {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
    .publisher-header {
        flex-direction: column;
        padding: 18px;
    }
    .publisher-header-actions {
        width: 100%;
        min-width: unset;
    }
    .publisher-name {
        font-size: 20px;
    }
    .publisher-meta-row span {
        min-width: 120px;
    }
}

/* Export page */
.export-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 16px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 13px;
}

.export-info-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
}

.export-info-label {
    color: var(--color-text-secondary);
}

.export-info-row strong {
    color: var(--color-text);
    text-align: right;
}

.export-status {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
}

.export-status-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.export-status-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.export-status code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.export-howto {
    margin: 0;
    padding-left: 22px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-text);
}

.export-howto li {
    margin-bottom: 4px;
}

.export-howto a {
    color: var(--color-primary);
    text-decoration: underline;
}

/* Floating action button — "Where am I?" */
.map-fab {
    position: fixed;
    right: 16px;
    bottom: 110px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    z-index: 15;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.map-fab:hover, .map-fab:active {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.25);
}

.map-fab.loading svg {
    animation: spin 1s linear infinite;
}

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

/* Bulk action bar (admin/territories.html) */
.bulk-action-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: linear-gradient(180deg, rgba(37, 99, 235, 0.08), rgba(37, 99, 235, 0.04));
    border: 1px solid rgba(37, 99, 235, 0.3);
    border-radius: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    animation: bulk-bar-in 0.2s ease-out;
}

@keyframes bulk-bar-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.bulk-action-count {
    font-size: 13px;
    color: var(--color-text);
    margin-right: auto;
}

.bulk-action-count strong {
    color: var(--color-primary);
    font-weight: 700;
}

.bulk-check {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

#bulk-check-all {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

/* Optimistic update flash */
.row-just-changed {
    animation: row-flash 1.5s ease-out;
}

@keyframes row-flash {
    0% { background: rgba(34, 197, 94, 0.18); }
    100% { background: transparent; }
}

/* View toggle (Table/Map) */
.view-toggle {
    display: inline-flex;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 16px;
    gap: 2px;
}

.view-toggle-btn {
    background: transparent;
    border: none;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.view-toggle-btn:hover {
    color: var(--color-text);
}

.view-toggle-btn.active {
    background: var(--color-primary);
    color: #fff;
}

/* Admin full territories map */
.admin-map {
    width: 100%;
    height: calc(100vh - 280px);
    min-height: 480px;
    border-radius: 10px;
    background: #f3f4f6;
    border: 1px solid var(--color-border);
    overflow: hidden;
    position: relative;
}

.map-search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.map-search-bar .form-input {
    flex: 1;
    min-width: 220px;
    max-width: 420px;
}

.map-search-count {
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* Draw toolbar */
.map-draw-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.draw-status {
    font-size: 13px;
    color: var(--color-text-secondary);
    padding: 4px 10px;
    background: var(--color-bg);
    border-radius: 6px;
    border: 1px solid var(--color-border);
}

/* Map popup (territory selected) */
.map-popup {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 320px;
    max-width: calc(100vw - 32px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
    padding: 14px 16px;
    z-index: 50;
}

.map-popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.map-popup-header strong {
    flex: 1;
    font-size: 14px;
    word-break: break-word;
}

.map-popup-header .modal-close {
    position: static;
}

.map-popup-meta {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.map-popup-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.map-popup-actions .btn {
    justify-content: flex-start;
    text-align: left;
}

.map-popup-hint {
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

.map-popup-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

@media (max-width: 640px) {
    .map-popup {
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
    }
    .admin-map {
        height: 70vh;
        min-height: 360px;
    }
}

/* Territory preview modal */
.preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-bottom: 12px;
}

.preview-meta strong {
    color: var(--color-text);
    margin-left: 4px;
}

.preview-map {
    width: 100%;
    height: 60vh;
    max-height: 520px;
    min-height: 320px;
    border-radius: 8px;
    background: #f3f4f6;
    overflow: hidden;
}

.preview-map .empty-state {
    padding: 40px 16px;
    text-align: center;
    color: var(--color-text-secondary);
}

/* Active row in history */
.row-active {
    background: #f0fdf4;
}

/* Form elements inside modals */
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
    margin-top: 16px;
}

.form-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 24px;
}

.assign-territory-label {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-primary);
    margin-bottom: 4px;
}

/* ============================================
   Auth Page Styles
   ============================================ */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: 24px;
}

.auth-container {
    width: 100%;
    max-width: 360px;
}

.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

.auth-title {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-align: center;
    margin-bottom: 24px;
}

.auth-step {
    width: 100%;
}

.btn-full {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    font-size: 15px;
}

.btn-half {
    flex: 1 1 0;
    min-width: 0;
    padding: 12px;
    font-size: 15px;
    justify-content: center;
    text-align: center;
}

.form-input-lg {
    padding: 14px 16px;
    font-size: 17px;
    text-align: center;
    letter-spacing: 1px;
}

/* Name fields in registration */
.name-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.name-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-label-sm {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* PIN change form in settings */
.settings-pin-form {
    padding: 12px 20px 16px;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
}

/* Phone input with country selector */
.phone-input-row {
    display: flex;
    gap: 0;
    margin-bottom: 4px;
    border: 2px solid var(--color-border);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.15s;
}

.phone-input-row:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.country-select-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 10px 12px 14px;
    background: var(--color-bg);
    border: none;
    cursor: pointer;
    font-size: 15px;
    white-space: nowrap;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    border-right: 1px solid var(--color-border);
}

.country-select-btn:hover {
    background: rgba(0, 0, 0, 0.03);
}

.country-flag-emoji {
    font-size: 20px;
    line-height: 1;
}

/* Inline SVG flags — avoid emoji rendering problems on Windows */
.flag-svg {
    width: 22px;
    height: 15px;
    display: inline-block;
    vertical-align: middle;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.country-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    flex-shrink: 0;
}

#selected-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
}

.country-dial-code {
    font-size: 15px;
    font-weight: 500;
    color: var(--color-text);
}

.country-chevron {
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.phone-number-input {
    flex: 1;
    border: none !important;
    border-radius: 0 !important;
    padding: 14px 14px;
    font-size: 17px;
    letter-spacing: 0.5px;
    min-width: 0;
    box-shadow: none !important;
}

.phone-number-input:focus {
    outline: none;
    box-shadow: none !important;
}

/* Country dropdown */
.country-dropdown {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    margin-bottom: 8px;
    overflow: hidden;
    z-index: 50;
}

.country-search-wrap {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
}

.country-search-input {
    font-size: 14px !important;
    padding: 8px 12px !important;
}

.country-list {
    max-height: 240px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.country-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s;
}

.country-item:hover,
.country-item:active {
    background: rgba(37, 99, 235, 0.04);
}

.country-item-active {
    background: rgba(37, 99, 235, 0.08);
    font-weight: 500;
}

.country-item:not(:last-child) {
    border-bottom: 1px solid var(--color-border);
}

.country-item-name {
    flex: 1;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.country-item-dial {
    color: var(--color-text-secondary);
    font-size: 13px;
    font-weight: 500;
    flex-shrink: 0;
}

/* ============================================
   Language Selector
   ============================================ */

.lang-selector-fixed {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
}

/* Admin header variant — anchored inline next to the logout button.
   Dropdown opens DOWNWARDS (anchor sits at top of page). */
.admin-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.lang-selector-header {
    position: relative;
}

.lang-selector-header .lang-toggle-btn {
    color: var(--color-text-secondary);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    gap: 6px;
}

.lang-selector-header .lang-toggle-btn:hover,
.lang-selector-header .lang-toggle-btn:focus-visible {
    color: var(--color-text);
    background: rgba(0, 0, 0, 0.04);
    outline: none;
}

.lang-selector-header .lang-globe-icon {
    width: 16px;
    height: 16px;
}

/* Override the default upward-opening dropdown for the header variant */
.lang-selector-header .lang-dropdown {
    bottom: auto;
    top: 100%;
    left: auto;
    right: 0;
    transform: none;
    margin-bottom: 0;
    margin-top: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* Icon-only logout button used in admin header (was a text "Вийти" button) */
.btn-icon-header {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--color-text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    transition: background-color .12s ease, color .12s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon-header:hover,
.btn-icon-header:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-text);
    outline: none;
}

.btn-icon-header:active {
    background: rgba(0, 0, 0, 0.10);
}

.btn-icon-header svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
}

/* On narrow screens collapse the language NAME but keep the globe */
@media (max-width: 600px) {
    .lang-selector-header .lang-current-name {
        display: none;
    }
}

.lang-toggle-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: transparent;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    color: #9ca3af;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
    font-family: inherit;
}

.lang-toggle-btn:hover {
    color: #6b7280;
}

.lang-globe-icon {
    flex-shrink: 0;
}

.lang-current-name {
    white-space: nowrap;
}

.lang-dropdown {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-width: 180px;
    z-index: 50;
}

.lang-option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 9px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    font-family: inherit;
    color: var(--color-text-secondary);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s;
}

.lang-option:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--color-text);
}

.lang-option-active {
    color: var(--color-text);
    font-weight: 500;
}

.lang-option:not(:last-child) {
    border-bottom: 1px solid var(--color-border);
}

.lang-option-name {
    flex: 1;
}

/* OTP inputs */
.otp-inputs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.otp-digit {
    width: 44px;
    height: 52px;
    text-align: center;
    font-size: 22px;
    font-weight: 600;
    border: 2px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
    transition: border-color 0.15s;
}

.otp-digit:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* PIN dots */
.pin-dots {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin: 24px 0;
}

.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    background: transparent;
    transition: background 0.15s, border-color 0.15s;
}

.pin-dot.filled {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

/* PIN keyboard */
.pin-keyboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 0 auto;
    max-width: 280px;
}

.pin-key {
    height: 60px;
    font-size: 22px;
    font-weight: 500;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    cursor: pointer;
    color: var(--color-text);
    transition: background 0.1s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.pin-key:active {
    background: var(--color-border);
    transform: scale(0.95);
}

.pin-key-del, .pin-key-empty {
    font-size: 14px;
    color: var(--color-text-secondary);
}

.pin-key-empty {
    visibility: hidden;
}

/* Auth loader */
.auth-loader {
    display: flex;
    justify-content: center;
    padding: 16px;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.error-text {
    color: var(--color-danger);
    font-size: 13px;
    text-align: center;
    margin-top: 12px;
}

/* ============================================
   Dashboard (Publisher) Styles
   ============================================ */

.app-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    min-height: 56px;
    gap: 12px;
}

.app-header-title {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--color-text);
    display: flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.04);
}

.dashboard-main {
    padding: 20px 16px;
    overflow-y: auto;
}

.dashboard-subtitle {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
}

.territories-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.territory-card {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    gap: 12px;
    -webkit-tap-highlight-color: transparent;
}

.territory-card:hover,
.territory-card:active {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.02);
}

.territory-card-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.territory-color-bar {
    width: 4px;
    height: 40px;
    border-radius: 2px;
    flex-shrink: 0;
}

.territory-card-info {
    min-width: 0;
}

.territory-card-name {
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.territory-card-meta {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.territory-card-arrow {
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

/* Dashboard v2: enhanced territory card with countdown and progress */
.territory-card-v2 {
    flex-direction: column;
    align-items: stretch;
    cursor: default;
    gap: 12px;
}

.territory-card-v2 .territory-card-head {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.territory-card-v2 .territory-card-info {
    flex: 1;
    min-width: 0;
}

.territory-progress-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.territory-progress {
    width: 100%;
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}

.territory-progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.35s ease;
}

.territory-progress-fill.progress-ok      { background: linear-gradient(90deg, #22c55e, #16a34a); }
.territory-progress-fill.progress-warning { background: linear-gradient(90deg, #f59e0b, #d97706); }
.territory-progress-fill.progress-danger  { background: linear-gradient(90deg, #ef4444, #b91c1c); }

.territory-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--color-text);
}

.territory-progress-label .text-muted {
    color: var(--color-text-secondary);
}

.text-danger {
    color: #dc2626;
    font-weight: 600;
}

.territory-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.territory-card-actions .btn {
    flex: 1;
    min-width: 140px;
    justify-content: center;
    gap: 6px;
}

.app-header-greeting {
    flex: 1;
    min-width: 0;
}

.app-header-subtitle {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

@media (max-width: 480px) {
    .territory-card-actions .btn {
        min-width: 0;
        font-size: 12px;
    }
}

.skeleton-card {
    padding: 18px 16px;
    cursor: default;
}

.skeleton-card:hover {
    border-color: var(--color-border);
    background: var(--color-surface);
}

.empty-state svg {
    margin: 0 auto 16px;
    display: block;
}

.empty-state-sub {
    font-size: 13px;
    margin-top: 8px;
}

/* ============================================
   Map Page Styles
   ============================================ */

.app-header-map {
    padding: 8px 12px;
    min-height: 48px;
}

.map-legend {
    position: fixed;
    bottom: 80px;
    left: 12px;
    right: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 11px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 5;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    color: var(--color-text-secondary);
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* legend-territory gets its background assigned from JS based on the actual
   territory color (falls back to --color-primary if JS hasn't run yet). */
.legend-territory { background: var(--color-primary); }
.legend-flag { background: #dc2626; }
.legend-you { background: #2563eb; }

/* Territory switcher (quick switch between user's territories) */
.territory-switcher {
    position: fixed;
    top: 60px;
    left: 8px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.territory-switch-btn {
    display: block;
    padding: 6px 10px;
    background: var(--color-surface);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-tap-highlight-color: transparent;
}

.territory-switch-btn:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.map-hint {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
    animation: hint-fadeout 3s ease forwards;
    animation-delay: 3s;
}

@keyframes hint-fadeout {
    from { opacity: 1; }
    to { opacity: 0; }
}

.info-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-radius: 16px 16px 0 0;
    padding: 8px 20px 32px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
    z-index: 10;
    max-height: 60vh;
    overflow-y: auto;
}

.info-panel-handle {
    width: 36px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
}

.info-label {
    color: var(--color-text-secondary);
}

.info-value {
    font-weight: 600;
}

/* ============================================
   Bottom Sheet & Flag Dialog Styles
   ============================================ */

.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 20;
    animation: overlay-in 0.2s ease;
}

@keyframes overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-radius: 20px 20px 0 0;
    padding: 8px 20px 40px;
    z-index: 30;
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.bottom-sheet.visible {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    margin: 0 auto 20px;
}

.bottom-sheet-title {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 6px;
}

.bottom-sheet-subtitle {
    font-size: 14px;
    color: var(--color-text-secondary);
    text-align: center;
    margin-bottom: 8px;
}

.bottom-sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.bottom-sheet-actions.bottom-sheet-actions-row {
    flex-direction: row;
    gap: 10px;
}

.flag-dialog-icon {
    font-size: 36px;
    text-align: center;
    margin-bottom: 8px;
}

.flag-coords-text {
    font-size: 12px;
    color: var(--color-text-secondary);
    text-align: center;
    font-family: monospace;
    margin-bottom: 4px;
    background: var(--color-bg);
    padding: 6px 12px;
    border-radius: 6px;
}

.toast-info {
    background: #2563eb;
}

/* ============================================
   Settings Page Styles
   ============================================ */

.settings-main {
    padding: 0;
    overflow-y: auto;
    padding-bottom: 32px;
}

.settings-section {
    margin-bottom: 8px;
}

.settings-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
    padding: 20px 20px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-item {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    gap: 12px;
    width: 100%;
    text-align: left;
}

.settings-item:last-child {
    border-bottom: 1px solid var(--color-border);
}

.settings-item-btn {
    cursor: pointer;
    transition: background 0.1s;
    border: none;
    font-family: inherit;
    font-size: inherit;
}

.settings-item-btn:hover,
.settings-item-btn:active {
    background: rgba(0, 0, 0, 0.02);
}

.settings-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-item-label {
    font-size: 15px;
    color: var(--color-text);
}

.settings-item-value {
    font-size: 13px;
}

.settings-item-value.muted {
    color: var(--color-text-secondary);
}

.danger-label { color: var(--color-danger); }
.danger-title { color: var(--color-danger); }

.gdpr-badge {
    font-size: 10px;
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.settings-info-block {
    margin: 8px 20px;
    padding: 16px;
    background: var(--color-bg);
    border-radius: 10px;
    border: 1px solid var(--color-border);
}

.settings-info-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
}

.settings-info-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-info-list li {
    font-size: 13px;
    color: var(--color-text-secondary);
}

.settings-info-footnote {
    margin: 12px 0 0;
    padding-top: 10px;
    border-top: 1px solid var(--color-border);
    font-size: 11px;
    line-height: 1.45;
    color: var(--color-text-secondary);
    font-style: italic;
}

/* Sub-heading for the second list inside the same info-block ("NOT stored"). */
.settings-info-title-no {
    margin-top: 14px;
}

.delete-modal-icon {
    font-size: 40px;
    text-align: center;
    margin-bottom: 12px;
}

.delete-modal-title {
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 12px;
    color: var(--color-danger);
}

.delete-modal-text {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

.delete-modal-list {
    font-size: 14px;
    padding-left: 20px;
    margin-bottom: 16px;
    line-height: 1.8;
}

.log-list {
    max-height: 60vh;
    overflow-y: auto;
    padding: 0 4px;
}

.log-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
}

.log-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.log-item-icon { font-size: 12px; }
.log-item-action { font-size: 14px; font-weight: 500; }
.log-item-date { font-size: 12px; color: var(--color-text-secondary); padding-left: 20px; }
.log-item-warn .log-item-icon { color: #d97706; }
.log-item-critical .log-item-icon { color: var(--color-danger); }
.log-item-info .log-item-icon { color: var(--color-primary); }

.modal-fullscreen {
    max-width: 560px;
    max-height: 80vh;
    overflow-y: auto;
}

/* ============================================
   Security Page Styles
   ============================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 6px;
}

.stat-label {
    font-size: 13px;
    color: var(--color-text-secondary);
}

.security-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.security-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.security-card h2 {
    font-size: 15px;
    font-weight: 600;
}

.badge-threat-high { background: #fee2e2; color: #991b1b; }
.badge-threat-medium { background: #fef3c7; color: #92400e; }
.badge-threat-low { background: #f0fdf4; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }

.font-mono {
    font-family: monospace;
    font-size: 13px;
}

.endpoint-badge {
    background: var(--color-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
}

.empty-text {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 24px;
    font-size: 14px;
}

/* Header check */
.header-check-row {
    display: grid;
    grid-template-columns: 240px 100px 1fr;
    gap: 12px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 13px;
}

.header-check-name {
    font-family: monospace;
}

.header-check-status {
    font-weight: 600;
    text-align: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.status-ok { background: #d1fae5; color: #065f46; }
.status-fail { background: #fee2e2; color: #991b1b; }

.header-check-value {
    color: var(--color-text-secondary);
    font-family: monospace;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.check-overall {
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 600;
    margin-bottom: 16px;
    font-size: 14px;
}

.check-overall-ok { background: #d1fae5; color: #065f46; }
.check-overall-fail { background: #fee2e2; color: #991b1b; }

/* ============================================
   Admin Settings Page Styles
   ============================================ */

.settings-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}

.settings-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.settings-card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.settings-card-desc {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}

.settings-card-desc a { color: var(--color-primary); }

.settings-field-row { margin-bottom: 20px; }
.settings-field-row:last-child { margin-bottom: 0; }

.settings-field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
    display: block;
}

.settings-field-value {
    font-size: 15px;
    font-weight: 500;
}

.settings-field-edit {
    display: flex;
    gap: 8px;
    align-items: center;
}

.form-input-inline {
    flex: 1;
    max-width: 300px;
}

.settings-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.settings-input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.settings-input-group .form-input {
    flex: 1;
    padding-right: 40px;
}

.btn-toggle-visible {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--color-text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    transition: background-color .12s ease, color .12s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-toggle-visible:hover,
.btn-toggle-visible:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-text);
    outline: none;
}

.btn-toggle-visible:active {
    background: rgba(0, 0, 0, 0.10);
}

.btn-toggle-visible svg {
    width: 18px;
    height: 18px;
    pointer-events: none;
    display: block;
}

/* Default state: aria-pressed="false" → input is type=password (hidden).
   Show the crossed-out eye to signal "currently hidden — click to reveal". */
.btn-toggle-visible .icon-eye      { display: none; }
.btn-toggle-visible .icon-eye-off  { display: block; }

/* Pressed state: aria-pressed="true" → input is type=text (visible).
   Show the open eye to signal "currently visible — click to hide". */
.btn-toggle-visible[aria-pressed="true"] .icon-eye      { display: block; }
.btn-toggle-visible[aria-pressed="true"] .icon-eye-off  { display: none; }

.settings-hint {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 4px;
}

.dot-ok { color: #059669; }
.dot-fail { color: #dc2626; }
.dot-unknown { color: #9ca3af; }

.status-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
}

.badge-ok { background: #d1fae5; color: #065f46; }
.badge-fail { background: #fee2e2; color: #991b1b; }

.test-result {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
}

.test-ok { background: #d1fae5; color: #065f46; }
.test-fail { background: #fee2e2; color: #991b1b; }

.change-pin-form {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 16px;
    margin-top: 12px;
    background: var(--color-bg);
}

.pin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.pin-form-actions {
    display: flex;
    gap: 10px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
}

.toggle-checkbox { display: none; }

.toggle-track {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--color-border);
    border-radius: 11px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-checkbox:checked + .toggle-track {
    background: var(--color-primary);
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-checkbox:checked + .toggle-track .toggle-thumb {
    transform: translateX(18px);
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-warn {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-main {
        padding: 16px 12px;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filters input {
        min-width: unset;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .actions-cell {
        flex-direction: column;
        gap: 4px;
    }
}

/* ============================================
   Publisher header v2 (dashboard/territory/settings)
   Layout: [left-btn] [brand + user-name] [right-btn]
   ============================================ */
.app-header-v2 {
    gap: 10px;
    flex-wrap: nowrap;   /* never let actions drop under brand on mobile */
}

.app-header-v2 .app-header-actions {
    flex-shrink: 0;      /* lang selector stays in the header row */
    flex-wrap: nowrap;
}

.app-header-brand {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.15;
    overflow: hidden;    /* long "TerritoryApp + name" wrap is ellipsised */
}

.app-header-logo {
    font-size: 15px;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: 0.2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.app-header-user {
    font-size: 12px;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.app-header-page-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin: 0;
    padding-left: 8px;
    border-left: 1px solid var(--color-border);
}

/* ============================================
   Flag note textarea + counter (bottom sheets)
   ============================================ */
.flag-note-field {
    margin: 10px 0 4px;
    text-align: left;
}

.form-textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text);
    resize: vertical;
    min-height: 72px;
    max-height: 200px;
    box-sizing: border-box;
    -webkit-appearance: none;
}

.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.flag-note-counter {
    text-align: right;
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.flag-note-view {
    margin: 8px 0 12px;
    padding: 10px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-primary);
    border-radius: 6px;
    text-align: left;
}

.flag-note-text {
    font-size: 13px;
    line-height: 1.45;
    color: var(--color-text);
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 180px;
    overflow-y: auto;
}

/* ============================================
   Publisher activity log (full page)
   ============================================ */
.activity-main {
    max-width: 760px;
    margin: 0 auto;
    padding: 16px;
}

.activity-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.activity-summary {
    margin: 0;
    font-size: 13px;
}

.activity-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--color-text-secondary);
}

.activity-filter select {
    padding: 4px 8px;
    font-size: 13px;
    height: auto;
    min-width: 120px;
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.page-ellipsis {
    padding: 6px 4px;
    color: var(--color-text-secondary);
    font-size: 13px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-top: 16px;
}
