/* ============================================================
   Raven ERP — Custom stylesheet (Bootstrap 5 overrides + app-specific)
   ============================================================ */

:root {
    --primary:      #2563EB;
    --primary-dark: #1D4ED8;
    --success:      #059669;
    --warning:      #D97706;
    --danger:       #DC2626;
    --sidebar-bg:   #0F172A;
    --sidebar-text: #94A3B8;
    --sidebar-active:#FFFFFF;
    --bg:           #F8FAFC;
    --surface:      #FFFFFF;
    --border:       #E2E8F0;
    --text:         #1E293B;
    --text-muted:   #64748B;
    --radius:       8px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --sidebar-w:    240px;
}

/* ---- GLOBAL ---- */
html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

/* ---- LAYOUT ---- */
body { display: flex; overflow: hidden; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex-shrink: 0;
    transition: width .25s ease;
    overflow-x: hidden;
}

.sidebar-header { padding: 16px; border-bottom: 1px solid rgba(255,255,255,.06); }

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
}

.sidebar-logo svg { width: 24px; height: 24px; flex-shrink: 0; color: var(--primary); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }

/* ── Accordion nav groups ── */
.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 14px 8px 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: #475569;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    transition: color .15s;
    margin-top: 6px;
}
.nav-group-header:hover { color: #94a3b8; }
.nav-group-header.open  { color: #94a3b8; }

.nav-chevron {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    transition: transform .2s ease;
    opacity: .6;
}
.nav-group-header.open .nav-chevron { transform: rotate(180deg); }

.nav-group-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease;
}
.nav-group-body.open { max-height: 600px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 6px;
    margin: 1px 6px;
    transition: all .15s;
    white-space: nowrap;
    position: relative;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #e2e8f0; }
.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.06);
}

.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name { color: #e2e8f0; font-weight: 600; font-size: 13px; }
.user-role { color: #64748b; font-size: 11px; text-transform: capitalize; }
.logout-btn {
    display: block;
    text-align: center;
    padding: 6px;
    border-radius: 6px;
    background: rgba(255,255,255,.06);
    color: #94a3b8;
    text-decoration: none;
    font-size: 12px;
    transition: all .15s;
}
.logout-btn:hover { background: rgba(220,38,38,.2); color: #fca5a5; }

/* ---- MAIN ---- */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    flex-shrink: 0;
}

.sidebar-toggle {
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--text-muted); display: flex; align-items: center;
}
.sidebar-toggle svg { width: 20px; height: 20px; }
.page-title { font-weight: 700; font-size: 16px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content-body { flex: 1; overflow-y: auto; padding: 24px; }

/* ---- TABLE PADDING ---- */
/* table-sm cuts padding to 0.25rem; restore comfortable horizontal spacing */
.table > :not(caption) > * > * {
    padding-left:  0.875rem;
    padding-right: 0.875rem;
}

/* ---- CARD OVERRIDES ---- */
.card {
    border-color: var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    margin-bottom: 0;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 14px;
    border-color: var(--border);
    background: var(--surface);
    padding: 16px 20px;
}
.card-body { padding: 20px; }

/* ---- KPI GRID ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }


/* ---- CHART CONTAINER ---- */
.chart-wrap { position: relative; height: 280px; }

/* ---- GRID UTILITIES ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }

/* ---- TAG PILL ---- */
.tag-pill {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11px; font-weight: 500;
    background: var(--tag-bg, #EFF6FF);
    color: var(--tag-text, #2563EB);
    border: 1px solid var(--tag-border, #BFDBFE);
    white-space: nowrap;
}

/* ---- PERIOD SELECTOR ---- */
.period-selector { display: flex; gap: 4px; }
.period-btn {
    padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--surface); font-size: 12px; font-weight: 600; cursor: pointer;
    color: var(--text-muted); text-decoration: none; transition: all .15s;
}
.period-btn:hover, .period-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- STATUS PILLS (PO statuses used as badge modifiers) ---- */
.badge.status-received  { background: #D1FAE5 !important; color: #065F46 !important; }
.badge.status-draft     { background: #F1F5F9 !important; color: #475569 !important; }
.badge.status-sent      { background: #DBEAFE !important; color: #1E40AF !important; }
.badge.status-partial   { background: #FEF3C7 !important; color: #92400E !important; }
.badge.status-cancelled { background: #FEE2E2 !important; color: #991B1B !important; }
/* standalone (used without .badge on some PO status spans) */
.status-approved { background: #D1FAE5; color: #065F46; }

/* ---- VEEQO SYNC STATUS ---- */
.sync-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.sync-dot.stale { background: var(--warning); }
.sync-dot.error { background: var(--danger); }

/* ---- ORDER VIEW: META BAR ---- */
.order-meta-body { display: flex; padding: 0; }
.order-meta-field {
    display: flex; flex-direction: column; gap: 4px;
    padding: 14px 20px;
    border-right: 1px solid var(--border);
    flex: 1; min-width: 0;
}
.order-meta-field:last-child { border-right: none; }
.omf-label {
    font-size: 11px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .05em;
    font-weight: 600; white-space: nowrap;
}
.omf-value { font-weight: 500; }
.omf-total .omf-value { font-size: 17px; font-weight: 700; }

/* ---- ORDER VIEW: TABS ---- */
.order-tabs-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.order-tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto; scrollbar-width: none;
}
.order-tab-nav::-webkit-scrollbar { display: none; }
.tab-btn {
    padding: 12px 20px;
    background: none; border: none;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    cursor: pointer; font-family: inherit;
    font-weight: 500; font-size: 13.5px; white-space: nowrap;
    color: var(--text-muted);
    display: flex; align-items: center; gap: 6px;
    transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* Inside tabs: strip outer card chrome — wrapper provides the box */
.order-tabs-wrap .tab-pane > .card { border: none; box-shadow: none; border-radius: 0; }
.order-tabs-wrap .tab-pane > .card > .card-header { display: none; }

/* ---- LOGIN ---- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--sidebar-bg);
}
.login-card { width: 380px; background: var(--surface); border-radius: 12px; padding: 36px; box-shadow: var(--shadow-md); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; font-weight: 800; margin-top: 8px; }

/* ---- MISC UTILS ---- */
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }

/* ---- FILTER CHIPS (orders settings panel) ---- */
.sf-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    user-select: none;
    white-space: nowrap;
    transition: border-color .15s, background .15s, color .15s;
}
.sf-chip:hover  { border-color: var(--primary); color: var(--primary); }
.sf-chip.sf-chip-on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---- TOAST NOTIFICATIONS ---- */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    pointer-events: none;
    align-items: center;
}
.raven-toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 280px;
    max-width: 440px;
    padding: 13px 16px;
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    font-size: 13px;
    line-height: 1.45;
    pointer-events: auto;
    animation: toast-in .2s ease;
    background: var(--surface);
    border-left: 4px solid var(--text-muted);
    color: var(--text);
}
.raven-toast.toast-error  { border-color: var(--danger); }
.raven-toast.toast-success { border-color: var(--success); }
.raven-toast.toast-warning { border-color: var(--warning); }
.raven-toast .toast-msg   { flex: 1; }
.raven-toast .toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    padding: 0;
    margin-top: 1px;
    flex-shrink: 0;
}
.raven-toast .toast-close:hover { color: var(--text); }
.raven-toast.toast-hiding {
    animation: toast-out .2s ease forwards;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(12px); }
}

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) {
    .sidebar { position: fixed; z-index: 100; height: 100vh; transform: translateX(-100%); transition: transform .25s ease; }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.35); }
    .main-content { margin-left: 0 !important; }

    .content-body { padding: 12px; }
    .topbar { padding: 0 12px; gap: 8px; }

    .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
    .grid-cols-3 { grid-template-columns: 1fr !important; }

    .card-body { padding: 14px; }
    .card-header { padding: 12px 16px; font-size: 13px; }

    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }

    .filter-form { flex-direction: column !important; }
    .filter-form .mb-3 { min-width: unset !important; width: 100%; }
    .filter-form > div:last-child { width: 100%; }
    .filter-form > div:last-child .btn { flex: 1; justify-content: center; }

    .page-header-row { flex-wrap: wrap; gap: 8px; }

    .login-card { width: calc(100% - 32px); padding: 24px; }
    .login-wrap { align-items: flex-start; padding-top: 60px; }

    /* Order tabs mobile */
    .order-tabs-wrap { background: none; border: none; box-shadow: none; border-radius: 0; }
    .order-tab-nav { display: none; }
    .tab-pane { display: block; margin-bottom: 16px; }
    .order-tabs-wrap .tab-pane > .card {
        border: 1px solid var(--border);
        box-shadow: var(--shadow);
        border-radius: var(--radius);
    }
    .order-tabs-wrap .tab-pane > .card > .card-header { display: flex; }

    .order-meta-body { flex-direction: column; }
    .order-meta-field {
        flex-direction: row; justify-content: space-between; align-items: center;
        padding: 10px 14px; border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .order-meta-field:last-child { border-bottom: none; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .content-body { padding: 10px; }
    .topbar { height: 48px; }
    .page-title { font-size: 14px; }
}
