/* ============================================================
   Faramir CRM — Slate Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
    --bg:           #0D1117;
    --surface:      #161B22;
    --surface2:     #1C2128;
    --surface3:     #21262D;
    --border:       #30363D;
    --border-soft:  #21262D;
    --text:         #E6EDF3;
    --text-muted:   #7D8590;
    --text-subtle:  #484F58;
    --accent:       #2F81F7;
    --accent-soft:  rgba(47,129,247,0.12);
    --accent-hover: #388BFD;
    --success:      #3FB950;
    --success-soft: rgba(63,185,80,0.12);
    --warning:      #D29922;
    --warning-soft: rgba(210,153,34,0.12);
    --danger:       #F85149;
    --danger-soft:  rgba(248,81,73,0.12);
    --radius:       6px;
    --radius-lg:    8px;
}

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

body {
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 0.875rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Navbar ── */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 60px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
}
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    margin-right: 1rem;
    flex-shrink: 0;
}
.navbar-brand img {
    height: 40px;
    width: auto;
    object-fit: contain;
}
.navbar-brand-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.navbar-nav {
    display: flex;
    align-items: center;
    gap: 0.1rem;
    list-style: none;
    flex: 1;
}
.navbar-nav .nav-link {
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius);
    font-size: 0.825rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
}
.navbar-nav .nav-link:hover { color: var(--text); background: var(--surface2); }
.navbar-nav .nav-link.active { color: var(--text); background: var(--surface2); }
.navbar-toggler {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
}

/* Dropdowns */
.dropdown-menu {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    padding: 0.35rem;
    min-width: 180px;
}
.dropdown-item {
    color: var(--text-muted);
    font-size: 0.825rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    transition: all 0.12s;
}
.dropdown-item:hover { color: var(--text); background: var(--surface3); }
.dropdown-item.text-danger { color: var(--danger) !important; }
.dropdown-divider { border-color: var(--border); margin: 0.25rem 0; }
.dropdown-toggle::after { border-top-color: var(--text-muted); }

/* User badge */
.badge-role {
    font-size: 0.6rem;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: 'IBM Plex Mono', monospace;
    vertical-align: middle;
    margin-left: 4px;
}

/* ── Main content ── */
main.container-fluid { padding: 1.75rem 2rem; }

/* ── Headings ── */
h1.h3 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: none;
}
.card-body { padding: 1.25rem; }
.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.01em;
}

/* ── Stat cards ── */
.stat-card .card-body { padding: 1.1rem 1.25rem; }
.stat-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    margin-bottom: 0.4rem;
}
.stat-value {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1;
}
.stat-link {
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
    display: block;
    margin-top: 0.4rem;
    transition: color 0.15s;
}
.stat-link:hover { color: var(--accent-hover); }

/* ── Tables ── */
.table {
    color: var(--text);
    font-size: 0.825rem;
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-hover-bg: var(--surface2);
    --bs-table-border-color: var(--border);
}
.table thead th {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 0.75rem;
}
.table td {
    padding: 0.65rem 0.75rem;
    border-color: var(--border);
    vertical-align: middle;
    color: var(--text);
}
.table-hover tbody tr:hover td { background: var(--surface2); }
.table-responsive { border-radius: var(--radius-lg); }

/* ── Buttons ── */
.btn {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: var(--radius);
    transition: all 0.15s;
    letter-spacing: 0;
}
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline-secondary {
    border-color: var(--border);
    color: var(--text-muted);
    background: transparent;
}
.btn-outline-secondary:hover { border-color: var(--text-muted); color: var(--text); background: var(--surface2); }
.btn-outline-danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-outline-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-outline-primary { border-color: var(--accent); color: var(--accent); background: transparent; }
.btn-outline-primary:hover { background: var(--accent-soft); }
.btn-outline-warning { border-color: var(--warning); color: var(--warning); background: transparent; }
.btn-outline-warning:hover { background: var(--warning-soft); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-xs {
    padding: 0.18rem 0.55rem;
    font-size: 0.75rem;
    border-radius: 4px;
}

/* ── Forms ── */
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.3rem; }
.form-control, .form-select {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: 'IBM Plex Sans', sans-serif;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    background: var(--surface2);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 3px rgba(47,129,247,0.15);
}
.form-control::placeholder { color: var(--text-subtle); }
.form-select option { background: var(--surface2); color: var(--text); }
.form-text { font-size: 0.75rem; color: var(--text-muted); }
.input-group-text {
    background: var(--surface3);
    border-color: var(--border);
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.825rem;
}
textarea.form-control { resize: vertical; }

/* ── Alerts ── */
.alert {
    font-size: 0.825rem;
    border-radius: var(--radius);
    border: 1px solid;
}
.alert-success { background: var(--success-soft); border-color: rgba(63,185,80,0.3); color: var(--success); }
.alert-danger { background: var(--danger-soft); border-color: rgba(248,81,73,0.3); color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: rgba(210,153,34,0.3); color: var(--warning); }
.alert-info { background: var(--accent-soft); border-color: rgba(47,129,247,0.3); color: var(--accent); }
.btn-close { filter: invert(1) opacity(0.5); }
.btn-close:hover { filter: invert(1) opacity(0.8); }

/* ── Badges ── */
.badge {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.68rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}
.bg-success { background: var(--success-soft) !important; color: var(--success) !important; }
.bg-danger  { background: var(--danger-soft) !important; color: var(--danger) !important; }
.bg-warning { background: var(--warning-soft) !important; color: var(--warning) !important; }
.bg-secondary { background: var(--surface3) !important; color: var(--text-muted) !important; }
.bg-dark { background: var(--surface3) !important; color: var(--text) !important; }
.text-dark { color: var(--text) !important; }
.text-warning { color: var(--warning) !important; }
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-muted   { color: var(--text-muted) !important; }

/* ── Pagination ── */
.page-link {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-muted);
}
.page-link:hover { background: var(--surface2); border-color: var(--border); color: var(--text); }
.page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-item.disabled .page-link { background: var(--surface); color: var(--text-subtle); }

/* ── Record count ── */
.record-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    margin-left: 0.4rem;
}

/* ── Detail list ── */
dl.detail-list { margin: 0; }
dl.detail-list dt {
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    margin-top: 0.85rem;
}
dl.detail-list dt:first-child { margin-top: 0; }
dl.detail-list dd { margin: 0.15rem 0 0; font-size: 0.875rem; color: var(--text); }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.empty-state i { font-size: 2rem; display: block; margin-bottom: 0.75rem; opacity: 0.4; }
.empty-state p { margin-bottom: 1rem; }

/* ── Notes ── */
.note-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-soft);
}
.note-item:last-child { border-bottom: none; }
.note-content {
    font-size: 0.85rem;
    margin-top: 0.3rem;
    color: var(--text);
    white-space: pre-wrap;
    line-height: 1.5;
}
.note-meta { line-height: 1.2; }

/* ── Modals ── */
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
}
.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
}
.modal-footer {
    border-top: 1px solid var(--border);
    padding: 0.75rem 1.25rem;
}
.modal-title { font-size: 0.925rem; font-weight: 600; }
.modal-backdrop { background: rgba(0,0,0,0.7); }

/* ── Low stock card border ── */
.border-warning { border-color: rgba(210,153,34,0.4) !important; }
.border-danger  { border-color: rgba(248,81,73,0.4) !important; }

/* ── Links ── */
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.fw-medium { font-weight: 500; }

/* ── Misc Bootstrap overrides ── */
.navbar-toggler-icon { filter: invert(0.7); }
.form-check-input {
    background-color: var(--surface2);
    border-color: var(--border);
}
.form-check-input:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

/* ── Order Pipeline ── */
.pipeline-track {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
}
.pipeline-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}
.pipeline-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface2);
    transition: all 0.2s;
}
.pipeline-step.done .pipeline-dot {
    background: var(--accent);
    border-color: var(--accent);
}
.pipeline-step.current .pipeline-dot {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    transform: scale(1.2);
}
.pipeline-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-family: 'IBM Plex Mono', monospace;
    white-space: nowrap;
}
.pipeline-step.done .pipeline-label,
.pipeline-step.current .pipeline-label {
    color: var(--text);
}
.pipeline-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin-bottom: 1.2rem;
    transition: background 0.2s;
}
.pipeline-line.done {
    background: var(--accent);
}


/* ============================================================
   Mobile Responsive — Internal CRM
   ============================================================ */

/* ── Reduce main padding on small screens ── */
@media (max-width: 768px) {
    main.container-fluid {
        padding: 1rem;
    }
}

/* ── Navbar mobile ── */
@media (max-width: 991px) {
    .navbar {
        height: auto;
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
    }
    /* Target both the base collapse div and when Bootstrap adds .show */
    .navbar-collapse,
    .navbar-collapse.show,
    .navbar-expand-lg .navbar-collapse,
    .navbar-expand-lg .navbar-collapse.show {
        background: #1C2128 !important;
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
        margin: 0 -1rem;
        padding: 0.5rem 1rem 0.75rem;
        box-shadow: 0 6px 16px rgba(0,0,0,0.5);
        width: calc(100% + 2rem);
    }
    .navbar-nav {
        flex-direction: column;
        gap: 0;
        align-items: flex-start;
        flex: none;
        width: 100%;
    }
    .navbar-nav .nav-link,
    .navbar-collapse .nav-link {
        width: 100%;
        padding: 0.6rem 0.75rem;
        font-size: 0.9rem;
        color: #E6EDF3 !important;
        border-radius: var(--radius);
    }
    .navbar-nav .nav-link:hover,
    .navbar-nav .nav-link.active {
        background: var(--surface3);
        color: #E6EDF3 !important;
    }
    /* Push user menu to end */
    .navbar-nav.ms-auto {
        border-top: 1px solid var(--border);
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }
    /* Dropdown menus inside collapsed nav */
    .navbar-collapse .dropdown-menu,
    .navbar-collapse .dropdown-menu.show {
        position: static !important;
        transform: none !important;
        box-shadow: none !important;
        border: none !important;
        background: #21262D !important;
        border-radius: var(--radius);
        padding: 0.25rem 0 0.25rem 0.75rem;
        margin: 0.1rem 0;
        min-width: 0;
    }
    .navbar-collapse .dropdown-item {
        color: #C9D1D9 !important;
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    .navbar-collapse .dropdown-item:hover {
        color: #E6EDF3 !important;
        background: var(--surface2) !important;
    }
}

/* ── Tables — horizontal scroll on mobile ── */
@media (max-width: 768px) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
    /* Reduce table cell padding */
    .table th,
    .table td {
        padding: 0.5rem 0.6rem;
        font-size: 0.8rem;
    }
    /* Hide less critical columns — add d-none d-md-table-cell to low-priority cols */
    .table th.hide-mobile,
    .table td.hide-mobile {
        display: none;
    }
}

/* ── Stat cards — 2 columns on mobile instead of 4 ── */
@media (max-width: 576px) {
    .row.g-3 .col-6 {
        /* already 2 per row on xs */
    }
    .stat-value {
        font-size: 1.3rem;
    }
}

/* ── Pipeline tracker — wrap labels on mobile ── */
@media (max-width: 640px) {
    .pipeline-track {
        padding: 0.5rem 0.25rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .pipeline-label {
        font-size: 0.58rem;
        max-width: 40px;
        text-align: center;
        white-space: normal;
        word-break: break-word;
    }
}

/* ── Page headings + action buttons — stack on mobile ── */
@media (max-width: 576px) {
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }
    /* Search forms */
    .d-flex.gap-2 form,
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }
}

/* ── Card padding — tighter on mobile ── */
@media (max-width: 576px) {
    .card-body {
        padding: 1rem;
    }
    .card-body.p-4 {
        padding: 1rem !important;
    }
}

/* ── Forms — full width inputs on mobile ── */
@media (max-width: 576px) {
    .col-md-6, .col-md-4, .col-md-3 {
        /* Bootstrap handles this via its own grid, but ensure inputs fill */
    }
    .input-group {
        flex-wrap: nowrap;
    }
}

/* ── Modals — full width on mobile ── */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
    }
    .modal-content {
        border-radius: var(--radius);
    }
}
