/* ─── Admin Dashboard ─────────────────────────────────────── */
/* Matches the editor design system: Inter font, slate palette,
   glassmorphism panels, smooth transitions.                   */

:root {
    --primary: #3b82f6;
    --primary-light: rgba(59, 130, 246, 0.12);
    --bg: #f8fafc;
    --surface: rgba(255, 255, 255, 0.97);
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --field-bg: #f1f5f9;
    --field-border: #cbd5e1;
    --green: #10b981;
    --green-light: rgba(16, 185, 129, 0.10);
    --amber: #f59e0b;
    --amber-light: rgba(245, 158, 11, 0.10);
    --red: #ef4444;
    --red-light: rgba(239, 68, 68, 0.10);
    --violet: #8b5cf6;
    --violet-light: rgba(139, 92, 246, 0.10);
    --header-height: 56px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ─── Auth Overlay ──────────────────────────────────────────── */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(248, 250, 252, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1.5rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.auth-overlay.hidden { display: none; }
.auth-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem;
    text-align: center;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.auth-card h2 {
    color: var(--text);
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}
.auth-card p {
    color: var(--text-muted);
    margin: 0 0 1.5rem;
    font-size: 0.9rem;
    line-height: 1.5;
}
.auth-error {
    color: var(--red);
    margin-top: 1rem;
    font-size: 0.85rem;
}
.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: #94a3b8;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}
.apple-sign-in-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 300px;
    height: 44px;
    background: #000;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.apple-sign-in-btn:hover { background: #1d1d1f; }
.apple-sign-in-btn svg { flex-shrink: 0; }

/* ─── App Header ────────────────────────────────────────────── */
.app-header {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0 1.5rem;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.06);
    position: sticky;
    top: 0;
    z-index: 100;
    overflow: hidden;
}

/* ─── Header Brand (SVG logo + "Map" label) ─────────────────── */
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
    flex-shrink: 1;
}
.brand-logo {
    height: 28px;
    width: auto;
    flex-shrink: 0;
}
.brand-map-label {
    font-family: 'Georgia', 'Times New Roman', 'Garamond', serif;
    font-size: 1.3rem;
    font-weight: 400;
    color: #1B2A4A;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.app-header .badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--violet-light);
    color: var(--violet);
    padding: 2px 8px;
    border-radius: 6px;
    flex-shrink: 0;
}
.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s;
    white-space: nowrap;
}
.nav-link:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ─── User Badge ────────────────────────────────────────────── */
.user-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 4px 12px;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 20px;
    font-size: 0.75rem;
    color: #16a34a;
    white-space: nowrap;
}
.user-badge img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}
.sign-out-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 6px;
    transition: color 0.15s;
}
.sign-out-btn:hover { color: var(--red); }

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

/* ─── Stats Cards ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card:nth-child(1)::before { background: var(--primary); }
.stat-card:nth-child(2)::before { background: var(--green); }
.stat-card:nth-child(3)::before { background: var(--amber); }
.stat-card:nth-child(4)::before { background: var(--violet); }
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.10);
}
.stat-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
    line-height: 1;
    margin-bottom: 0.25rem;
}
.stat-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ─── Table Section ─────────────────────────────────────────── */
.table-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.75rem;
}
.table-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.table-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ─── Filter / Search Inputs ────────────────────────────────── */
.filter-input,
.filter-select {
    padding: 7px 12px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.filter-input::placeholder {
    color: var(--text-muted);
}
.filter-select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
}
.btn-refresh {
    padding: 7px 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.btn-refresh:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* ─── Data Table ────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}
.data-table thead {
    background: var(--field-bg);
    position: sticky;
    top: 0;
    z-index: 1;
}
.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
    white-space: nowrap;
}
.data-table th:hover {
    color: var(--primary);
}
.data-table th .sort-indicator {
    margin-left: 4px;
    opacity: 0.4;
    font-size: 0.65rem;
}
.data-table th.sorted .sort-indicator {
    opacity: 1;
    color: var(--primary);
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}
.data-table tbody tr {
    transition: background 0.1s;
}
.data-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.04);
}
.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ─── User Cell ─────────────────────────────────────────────── */
.user-cell {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.user-cell img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--border);
    object-fit: cover;
    flex-shrink: 0;
}
.user-cell .user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.user-cell .user-name {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-cell .user-email {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Action Badge ──────────────────────────────────────────── */
.action-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.action-badge.post {
    background: var(--green-light);
    color: #059669;
}
.action-badge.get {
    background: var(--primary-light);
    color: var(--primary);
}
.action-badge.put {
    background: var(--amber-light);
    color: #d97706;
}
.action-badge.delete {
    background: var(--red-light);
    color: var(--red);
}
.action-badge.auth {
    background: var(--violet-light);
    color: var(--violet);
}

/* ─── Endpoint Pill ─────────────────────────────────────────── */
.endpoint-pill {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--field-bg);
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

/* ─── Timestamp ─────────────────────────────────────────────── */
.timestamp {
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.82rem;
}
.timestamp .date {
    color: var(--text);
    font-weight: 500;
}

/* ─── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}
.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}
.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}
.empty-state p {
    font-size: 0.85rem;
}

/* ─── Pagination ────────────────────────────────────────────── */
.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
}
.page-btn {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.page-btn:hover:not(:disabled) {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}
.page-btn:disabled {
    opacity: 0.4;
    cursor: default;
}
.page-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ─── Loading Spinner ───────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Fade-in animation ─────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in {
    animation: fadeInUp 0.35s ease-out both;
}
.stats-grid .stat-card:nth-child(1) { animation-delay: 0s; }
.stats-grid .stat-card:nth-child(2) { animation-delay: 0.05s; }
.stats-grid .stat-card:nth-child(3) { animation-delay: 0.10s; }
.stats-grid .stat-card:nth-child(4) { animation-delay: 0.15s; }

/* ─── Users Summary Section ─────────────────────────────────── */
.users-summary {
    margin-bottom: 1.5rem;
}
.users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    padding: 1rem 1.25rem;
}
.user-summary-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--field-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all 0.2s;
    cursor: pointer;
}
.user-summary-card:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: translateY(-1px);
}
.user-summary-card img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border);
    object-fit: cover;
    flex-shrink: 0;
}
.user-summary-info {
    flex: 1;
    min-width: 0;
}
.user-summary-info .name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-summary-info .email {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-summary-stats {
    text-align: right;
    flex-shrink: 0;
}
.user-summary-stats .count {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}
.user-summary-stats .label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ─── Mobile Responsive ─────────────────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: 48px;
    }
    .app-header {
        padding: 0 0.75rem;
    }
    .brand-logo {
        height: 22px;
    }
    .brand-map-label {
        font-size: 1.05rem;
    }
    .app-header .badge {
        display: none;
    }
    .header-actions {
        gap: 4px;
    }
    .nav-link span {
        display: none;
    }
    .user-badge span {
        display: none;
    }
    .admin-content {
        padding: 1rem;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    .stat-value {
        font-size: 1.5rem;
    }
    .table-header {
        flex-direction: column;
        align-items: stretch;
    }
    .table-controls {
        flex-wrap: wrap;
    }
    .filter-input,
    .filter-select {
        flex: 1;
        min-width: 120px;
    }
    .data-table {
        font-size: 0.78rem;
    }
    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }
    .user-cell img {
        width: 24px;
        height: 24px;
    }
}

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

/* ─── Provider Badges ──────────────────────────────────────── */
.provider-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.provider-badge svg {
    flex-shrink: 0;
}
.provider-google {
    background: #e8f0fe;
    color: #1a73e8;
}
.provider-apple {
    background: #1d1d1f;
    color: #fff;
}
.provider-legacy {
    color: var(--text-muted, #94a3b8);
    font-size: 0.8rem;
}

/* ─── Tab Navigation ───────────────────────────────────────── */
.admin-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
}
.admin-tab {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.admin-tab:hover {
    color: var(--text);
    background: rgba(59, 130, 246, 0.04);
}
.admin-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.admin-tab .tab-count {
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--field-bg);
    color: var(--text-muted);
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}
.admin-tab.active .tab-count {
    background: var(--primary-light);
    color: var(--primary);
}
.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
}

/* ─── Activity Action Badges ────────────────────────────────── */
.action-badge.zone_click {
    background: var(--primary-light);
    color: #2563eb;
}
.action-badge.asset_click {
    background: rgba(6, 182, 212, 0.10);
    color: #0891b2;
}
.action-badge.layer_toggle {
    background: var(--amber-light);
    color: #d97706;
}
.action-badge.search {
    background: var(--violet-light);
    color: var(--violet);
}
.action-badge.satellite_toggle {
    background: rgba(16, 185, 129, 0.10);
    color: #059669;
}
.action-badge.locate {
    background: rgba(244, 63, 94, 0.10);
    color: #e11d48;
}

/* ─── Activity Chart ────────────────────────────────────────── */
.chart-container {
    padding: 1rem 1.25rem;
    height: 300px;
    position: relative;
}

/* ─── Activity Target Pill ──────────────────────────────────── */
.target-pill {
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 500;
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
}
.target-metadata {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}
