/* ============================================
   Atlas CRM - Stylesheet
   ============================================ */

:root {
    --atlas-primary: #1e3a5f;
    --atlas-primary-dark: #0f1d30;
    --atlas-accent: #3b82f6;
    --atlas-accent-hover: #2563eb;
    --atlas-success: #10b981;
    --atlas-warning: #f59e0b;
    --atlas-danger: #ef4444;
    --atlas-bg: #f0f4f8;
    --atlas-card: #ffffff;
    --atlas-sidebar: #0f1d30;
    --atlas-sidebar-active: rgba(59, 130, 246, 0.15);
    --atlas-text: #1e293b;
    --atlas-text-muted: #64748b;
    --atlas-border: #e2e8f0;
    --atlas-radius: 12px;
    --atlas-radius-sm: 10px;
    --atlas-shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --atlas-shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --atlas-shadow-lg: 0 8px 28px rgba(0,0,0,0.10);
    --sidebar-width: 248px;
}

* {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background: var(--atlas-bg);
    color: var(--atlas-text);
    font-size: 0.9rem;
    margin: 0;
    padding: 0;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--atlas-sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.brand {
    padding: 24px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand h4 {
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 3px;
    margin: 0;
    color: #fff;
}

.brand small {
    font-size: 0.65rem;
    color: var(--atlas-accent);
    letter-spacing: 4px;
    font-weight: 700;
}

.sidebar-nav {
    list-style: none;
    padding: 12px 10px;
    margin: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.sidebar-nav li a:hover {
    background: var(--atlas-sidebar-active);
    color: #fff;
}

.sidebar-nav li a.active {
    background: var(--atlas-sidebar-active);
    color: var(--atlas-accent);
    font-weight: 600;
}

.sidebar-nav li a i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.nav-divider {
    border-top: 1px solid rgba(255,255,255,0.08);
    margin: 8px 0 !important;
}

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 24px 28px;
    min-height: 100vh;
}

/* ── Top Bar ── */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--atlas-border);
    flex-wrap: wrap;
    gap: 12px;
}

/* ── Cards ── */
.card-atlas {
    background: var(--atlas-card);
    border-radius: var(--atlas-radius);
    border: 1px solid var(--atlas-border);
    padding: 20px;
    box-shadow: var(--atlas-shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}
.card-atlas:hover { box-shadow: var(--atlas-shadow-md); }

.border-atlas {
    border-color: var(--atlas-accent) !important;
    box-shadow: 0 0 0 1px var(--atlas-accent);
}

/* ── Stat Cards ── */
.stat-card {
    background: var(--atlas-card);
    border-radius: var(--atlas-radius);
    border: 1px solid var(--atlas-border);
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--atlas-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.2;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* ── Colors ── */
.text-atlas { color: var(--atlas-accent) !important; }
.bg-atlas { background: var(--atlas-accent) !important; }
.bg-atlas-light { background: rgba(59, 130, 246, 0.1) !important; }
.text-money { color: var(--atlas-success) !important; }

/* ── Buttons ── */
.btn-atlas {
    background: var(--atlas-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 8px 18px;
    transition: all 0.2s;
}

.btn-atlas:hover {
    background: var(--atlas-accent-hover);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-atlas-outline {
    background: transparent;
    color: var(--atlas-accent);
    border: 1.5px solid var(--atlas-accent);
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 7px 18px;
    transition: all 0.2s;
}

.btn-atlas-outline:hover {
    background: var(--atlas-accent);
    color: #fff;
}

/* ── Tables ── */
.table thead th {
    background: var(--atlas-bg);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--atlas-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--atlas-border);
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 14px;
    vertical-align: middle;
    font-size: 0.85rem;
    border-bottom: 1px solid #f1f5f9;
}

/* ── Auth pages (login / register / forgot / reset) ── */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--atlas-primary-dark) 0%, var(--atlas-primary) 100%);
}
.auth-card {
    background: #fff;
    border-radius: var(--atlas-radius);
    box-shadow: var(--atlas-shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 440px;
}
.auth-card .brand {
    text-align: center;
    margin-bottom: 32px;
    padding: 0;
    border: none;
}
.auth-card .brand h2 {
    color: var(--atlas-primary);
    font-weight: 800;
    letter-spacing: 3px;
    margin: 0;
    font-size: 2rem;
}
.auth-card .brand small {
    display: block;
    color: var(--atlas-accent);
    letter-spacing: 4px;
    font-weight: 700;
    font-size: 0.55rem;
    margin-top: 4px;
}

.table-hover tbody tr:hover {
    background: rgba(59, 130, 246, 0.03);
}

.table tbody tr {
    cursor: pointer;
}

/* ── Forms ── */
.form-control, .form-select {
    border-radius: 8px;
    border: 1.5px solid var(--atlas-border);
    padding: 10px 14px;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--atlas-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.form-label {
    font-weight: 600;
    color: var(--atlas-text);
    margin-bottom: 4px;
}

/* ── Badges ── */
.badge {
    font-weight: 600;
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0.3px;
}

.plan-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1px;
}

.plan-badge.free { background: rgba(107,114,128,0.2); color: #6b7280; }
.plan-badge.pro { background: rgba(59,130,246,0.2); color: #3b82f6; }
.plan-badge.business { background: rgba(139,92,246,0.2); color: #8b5cf6; }

/* ── Pricing ── */
.pricing-card {
    background: var(--atlas-card);
    border: 2px solid var(--atlas-border);
    border-radius: var(--atlas-radius);
    padding: 32px;
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
}
.pricing-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--atlas-shadow-lg);
}
.pricing-card.popular {
    border-color: var(--atlas-accent);
    transform: scale(1.05);
}
.pricing-card.popular:hover {
    transform: scale(1.05) translateY(-4px);
}
.pricing-card .price {
    font-size: 3rem;
    font-weight: 800;
    color: var(--atlas-primary);
}
.pricing-card .price span {
    font-size: 1rem;
    font-weight: 400;
    color: var(--atlas-text-muted);
}
.popular-badge {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--atlas-accent);
    color: #fff;
    padding: 4px 20px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--atlas-text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ── Pipeline Board ── */
.pipeline-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 20px;
    min-height: 500px;
}

.pipeline-column {
    flex: 0 0 260px;
    background: var(--atlas-bg);
    border-radius: var(--atlas-radius);
    border: 1px solid var(--atlas-border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
}

.pipeline-column-header {
    padding: 14px;
    border-bottom: 1px solid var(--atlas-border);
    background: var(--atlas-card);
    border-radius: var(--atlas-radius) var(--atlas-radius) 0 0;
}

.pipeline-cards {
    padding: 8px;
    flex: 1;
    overflow-y: auto;
    min-height: 100px;
}

.pipeline-card {
    background: var(--atlas-card);
    border-radius: 8px;
    border: 1px solid var(--atlas-border);
    padding: 12px;
    margin-bottom: 6px;
    cursor: grab;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.pipeline-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.pipeline-card.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}

.pipeline-card-title {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--atlas-text);
}

.pipeline-card-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--atlas-accent);
}

.pipeline-card-client {
    font-size: 0.75rem;
    color: var(--atlas-text-muted);
}

.pipeline-card-date {
    font-size: 0.7rem;
    color: var(--atlas-text-muted);
}

/* ── Task Cards ── */
.task-card {
    background: var(--atlas-card);
    border-radius: 8px;
    border: 1px solid var(--atlas-border);
    padding: 14px;
    margin-bottom: 8px;
    transition: all 0.2s;
}

.task-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.task-card.overdue {
    border-left: 3px solid var(--atlas-danger);
}

.task-card.today {
    border-left: 3px solid var(--atlas-warning);
}

/* ── Reminder Cards ── */
.reminder-card {
    background: var(--atlas-card);
    border-radius: var(--atlas-radius);
    border: 1px solid var(--atlas-border);
    padding: 20px;
    margin-bottom: 12px;
    transition: all 0.2s;
}

.reminder-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.reminder-card.inactive {
    opacity: 0.5;
}

/* ── Activity Timeline ── */
.activity-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
}

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* ── Mobile Sidebar ── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 998;
    background: var(--atlas-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Hide the toggle while the sidebar is open (modern browsers) */
body:has(.sidebar.open) .sidebar-toggle { display: none !important; }

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* ── Toast / Alerts ── */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.atlas-toast {
    background: var(--atlas-card);
    border-radius: 10px;
    padding: 12px 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    border-left: 4px solid var(--atlas-success);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
    margin-bottom: 8px;
}

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

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Nav pills override ── */
.nav-pills .nav-link {
    color: var(--atlas-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: 8px;
    padding: 8px 16px;
}

.nav-pills .nav-link.active {
    background: var(--atlas-accent) !important;
}

/* ── Utility ── */
.fw-600 { font-weight: 600 !important; }
.fw-700 { font-weight: 700 !important; }
.fw-800 { font-weight: 800 !important; }
.fw-900 { font-weight: 900 !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Quote view ── */
.quote-preview {
    background: var(--atlas-card);
    border: 1px solid var(--atlas-border);
    border-radius: var(--atlas-radius);
    padding: 32px;
    max-width: 800px;
}

/* ── Mobile-friendly tables ── */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* .table-cards-mobile : stacks table rows as cards on small screens.
   Each <td> needs data-label="..." to show its column name; cells without
   data-label (e.g. action buttons) render bare at the bottom of the card. */
@media (max-width: 767.98px) {
    .table-cards-mobile,
    .table-cards-mobile thead,
    .table-cards-mobile tbody,
    .table-cards-mobile tr,
    .table-cards-mobile td {
        display: block;
        width: 100%;
    }
    .table-cards-mobile thead { display: none; }
    .table-cards-mobile,
    .table-cards-mobile > tbody {
        background-color: transparent !important;
        --bs-table-bg: transparent;
        --bs-table-accent-bg: transparent;
        --bs-table-hover-bg: transparent;
        --bs-table-striped-bg: transparent;
        border: 0 !important;
    }
    .card-atlas:has(> .table-responsive > .table-cards-mobile),
    .card-atlas:has(> .table-cards-mobile) {
        background: var(--atlas-bg, #f0f4f8);
    }
    .table-cards-mobile tbody tr {
        background: #fff;
        border: 1px solid var(--atlas-border);
        border-left: 4px solid var(--atlas-accent);
        border-radius: 14px;
        padding: 16px 18px;
        margin-bottom: 14px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    .table-cards-mobile tbody tr:hover,
    .table-cards-mobile tbody tr:active {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);
    }
    .table-cards-mobile tbody tr:last-child { margin-bottom: 4px; }
    .table-cards-mobile td {
        padding: 8px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
    }
    .table-cards-mobile td[data-label] + td[data-label] {
        border-top: 1px dashed #f1f5f9;
    }
    .table-cards-mobile td[data-label]::before {
        content: attr(data-label);
        font-weight: 700;
        color: #9ca3af;
        font-size: 0.68rem;
        text-transform: uppercase;
        letter-spacing: 0.6px;
        text-align: left;
        flex-shrink: 0;
    }
    .table-cards-mobile td:not([data-label]) {
        justify-content: flex-end;
        padding-top: 14px;
        margin-top: 10px;
        border-top: 1px solid var(--atlas-border);
    }
    .table-cards-mobile td.d-none,
    .table-cards-mobile th.d-none {
        display: none !important;
    }
}

/* ── Responsive ── */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-toggle {
        display: block;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 70px 16px 24px;
    }

    .pipeline-board {
        flex-direction: column;
        overflow-x: visible;
        min-height: 0;
        padding-bottom: 8px;
    }

    .pipeline-column {
        flex: 1 1 auto;
        width: 100%;
        max-height: none;
    }

    .pipeline-cards {
        overflow-y: visible;
        max-height: none;
    }

    .top-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Prevent iOS auto-zoom on input focus (needs >= 16px) */
    .form-control, .form-select, .form-control-color, textarea, select, input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="number"], input[type="date"], input[type="search"] {
        font-size: 16px;
    }

    /* Larger touch targets for primary actions */
    .btn-atlas, .btn-atlas-outline {
        padding: 11px 22px;
        font-size: 0.95rem;
    }
    .sidebar-nav li a {
        padding: 13px 14px;
        font-size: 0.95rem;
    }

    /* Tighter card padding on small screens */
    .card-atlas { padding: 16px; }

    /* Force standalone tables (not wrapped) to scroll horizontally */
    .card-atlas > .table,
    .main-content > .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
}

@media (max-width: 576px) {
    .stat-value {
        font-size: 1.2rem;
    }

    .main-content {
        padding: 64px 12px 20px;
    }

    /* Stat cards: tighter padding on phones */
    .stat-card { padding: 16px; }
}

/* ── Print ── */
@media print {
    .sidebar, .sidebar-toggle, .top-bar .btn, .sidebar-overlay {
        display: none !important;
    }
    .main-content {
        margin-left: 0;
        padding: 0;
    }
}
