/**
 * INTERCITY Admin - Global Styles
 * Subtle, professional color palette
 */

/* ============================================================================
   VARIABLES
   ============================================================================ */

:root {
    /* Subtle Colors */
    --primary: #047857;
    --primary-light: #10b981;
    --primary-muted: rgba(4, 120, 87, 0.1);
    --accent: #d97706;
    --accent-muted: rgba(217, 119, 6, 0.1);

    /* Neutrals */
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-alt: #f1f5f9;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;

    /* Text */
    --text: #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --text-inverse: #f8fafc;

    /* Status */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Borders */
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Sidebar */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;

    /* Transitions */
    --transition: 0.2s ease;
}

/* ============================================================================
   BASE
   ============================================================================ */

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ============================================================================
   LAYOUT
   ============================================================================ */

.app-container {
    display: flex;
    min-height: 100vh;
}

/* ============================================================================
   SIDEBAR
   ============================================================================ */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: width var(--transition);
}

.sidebar-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-light);
}

.logo-badge {
    font-size: 0.65rem;
    font-weight: 500;
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    color: var(--text-light);
    text-decoration: none;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: var(--text-inverse);
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

.nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: var(--spacing-md) 0;
}

/* ============================================================================
   MAIN WRAPPER
   ============================================================================ */

.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-lg);
    gap: var(--spacing-lg);
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: var(--spacing-sm);
    cursor: pointer;
    color: var(--text);
}

.menu-toggle svg {
    width: 24px;
    height: 24px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    flex: 1;
    max-width: 400px;
}

.search-box svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.search-box input {
    border: none;
    background: none;
    outline: none;
    flex: 1;
    font-size: 14px;
    color: var(--text);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-left: auto;
}

.header-btn {
    position: relative;
    width: 40px;
    height: 40px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    transition: var(--transition);
}

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

.header-btn svg {
    width: 20px;
    height: 20px;
}

.notif-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--error);
    border-radius: 50%;
}

.admin-profile {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.admin-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.admin-name {
    font-weight: 500;
    color: var(--text);
}

/* ============================================================================
   MAIN CONTENT
   ============================================================================ */

.main-content {
    flex: 1;
    padding: var(--spacing-lg);
}

/* ============================================================================
   CARDS
   ============================================================================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

/* ============================================================================
   STATS CARDS
   ============================================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--spacing-md);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon.green {
    background: var(--primary-muted);
    color: var(--primary);
}

.stat-icon.amber {
    background: var(--accent-muted);
    color: var(--accent);
}

.stat-icon.blue {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

.stat-icon.red {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.stat-info {
    flex: 1;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stat-change {
    font-size: 0.75rem;
    margin-top: var(--spacing-xs);
}

.stat-change.up {
    color: var(--success);
}

.stat-change.down {
    color: var(--error);
}

/* ============================================================================
   DATA TABLES
   ============================================================================ */

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--surface-alt);
}

.data-table tbody tr:hover {
    background: var(--surface-alt);
}

.data-table td {
    font-size: 0.875rem;
}

/* ============================================================================
   BADGES
   ============================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge.warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.badge.info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: 0 var(--spacing-md);
    /* horizontal padding only, height handles vertical */
    height: 40px;
    max-height: 40px;
    /* Force fix */
    overflow: hidden;
    /* Prevent spill */
    white-space: nowrap;
    /* Prevent text wrap */
    /* Fixed height to prevent spinner jump */
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
}

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

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

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

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

.btn svg {
    width: 16px;
    height: 16px;
}


/* Loading States */
.btn.loading {
    pointer-events: none;
    opacity: 0.8;
    position: relative;
    color: transparent !important;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-top: -8px;
    margin-left: -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

.btn-secondary.loading::after {
    border-color: rgba(0, 0, 0, 0.1);
    border-top-color: var(--text);
}

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

.spinner-small {
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    animation: spinner 0.6s linear infinite;
    vertical-align: sub;
    margin-right: 6px;
}

/* Global Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 15px;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner-large {
    width: 40px;
    height: 40px;
    border: 4px solid var(--primary-muted);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
}

.loading-text {
    font-weight: 500;
    color: var(--text);
}

/* ============================================================================
   PAGE HEADER
   ============================================================================ */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

/* ============================================================================
   MAPBOX
   ============================================================================ */

.map-container {
    width: 100%;
    height: 400px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .menu-toggle {
        display: flex;
    }

    .admin-name {
        display: none;
    }
}

@media (max-width: 768px) {
    .search-box {
        display: none;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   GLOBAL MODALS & UTILS
   ============================================================================ */

/* Global Modal System */
/* Global Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-overlay.global-modal {
    z-index: 9999;
}

.modal-dialog {
    background: white;
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-overlay.active .modal-dialog {
    transform: translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.small-dialog {
    max-width: 400px;
    text-align: center;
}

.modal-close-x {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    position: absolute;
    right: 16px;
    top: 16px;
}

.modal-header.success h3 {
    color: #10b981;
}

.modal-header.error h3 {
    color: #ef4444;
}

.modal-header.warning h3 {
    color: #f59e0b;
}

.modal-header.info h3 {
    color: #3b82f6;
}

/* SVG Icons Helper */
.icon-svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    display: inline-block;
    vertical-align: middle;
}

/* Premium Search Input */
.search-premium-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 300px;
}

.search-premium-input {
    padding: 10px 16px 10px 40px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    background-color: #ffffff;
    width: 100%;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-premium-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-premium-icon {
    position: absolute;
    left: 12px;
    color: #94a3b8;
    width: 18px;
    height: 18px;
    pointer-events: none;
}

/* ============================================================================
   FORM ELEMENTS & UTILITIES
   ============================================================================ */

.form-section {
    margin-bottom: 20px;
}

.form-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
}

.form-input,
.form-select {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    color: var(--text);
    background-color: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-divider {
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin: 24px 0 16px;
    font-size: 1rem;
}

/* ============================================================================
   SCROLLBAR
   ============================================================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

/* ============================================================================
   FILTERS & TABS
   ============================================================================ */

.filters-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    gap: 10px;
    background: white;
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.filter-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

.filter-tab:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.filter-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10000;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    padding: 16px;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    min-width: 300px;
    max-width: 400px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: slideInRight 0.3s ease forwards;
    opacity: 0;
    transform: translateX(100%);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--error);
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
    color: var(--text);
}

.toast-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-light);
    padding: 0;
    line-height: 1;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ============================================================================
   AGENCY SELECTOR
   ============================================================================ */

.agency-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    margin-right: var(--spacing-md);
}

.agency-selector-wrapper label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.agency-selector-wrapper label svg {
    color: var(--primary);
}

.agency-selector {
    min-width: 200px;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    font-size: 0.875rem;
}

.agency-selector:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-muted);
}

.agency-filter-container {
    display: inline-flex;
}

/* Small filter tab variant */
.filter-tab.small {
    padding: 4px 10px;
    font-size: 0.8rem;
}

/* Channel badges */
.channel-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
}

.channel-badge.online {
    background: rgba(34, 197, 94, 0.15);
    color: #16a34a;
}

.channel-badge.counter {
    background: rgba(59, 130, 246, 0.15);
    color: #2563eb;
}

.channel-badge.phone {
    background: rgba(168, 85, 247, 0.15);
    color: #9333ea;
}