/* =========================================================================
   Stockly — design-system overrides on top of AdminLTE 3
   Architecture:
     1. Custom properties (:root)
     2. Base resets & typography
     3. Layout (sidebar, content, navbar)
     4. Components (cards, badges, buttons, tables, forms)
     5. Page-specific
     6. Utilities
     7. Animations & keyframes
     8. Media queries (mobile-first)
   ========================================================================= */

/* 1. ---- Custom properties ------------------------------------------------ */
:root {
    /* Colour system */
    --navy: #1A1A2E;
    --accent: #4F8CFF;
    --success: #1A7A4A;
    --danger: #C0392B;
    --warning: #B8860B;
    --bg: #F4F6F9;
    --surface: #FFFFFF;
    --border: #E8E8E8;
    --muted: #888888;
    --text: #333333;

    /* Radius & shadow scale */
    --radius: 8px;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-modal: 0 4px 16px rgba(0, 0, 0, 0.15);

    /* Spacing (horizontal page padding — overridden per breakpoint) */
    --pad-x: 16px;

    /* Motion */
    --t-fast: 150ms;
    --t-mid: 200ms;
    --t-slow: 250ms;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in: cubic-bezier(0.4, 0, 1, 1);

    /* Icon sizes */
    --icon-nav: 18px;
    --icon-action: 14px;
    --icon-stat: 24px;
}

/* 2. ---- Base & typography ------------------------------------------------ */
* { box-sizing: border-box; }

body,
.wrapper {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    background-color: var(--bg);
}

h1, .h1 { font-size: 24px; font-weight: 700; color: var(--navy); }
h2, .h2 { font-size: 18px; font-weight: 600; color: var(--navy); }
h3, .h3 { font-size: 16px; font-weight: 600; color: var(--navy); }

a { color: var(--accent); }
a:hover { color: #3a78ec; }

.text-muted, .muted { color: var(--muted) !important; }
small, .small { font-size: 12px; }

/* Focus-visible outline on every interactive element */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
label.upload-dropzone:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--accent) !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
}

/* Skip-to-content link */
.skip-link {
    position: absolute;
    left: 8px;
    top: -56px;
    z-index: 3000;
    background: var(--navy);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius);
    transition: top var(--t-fast) var(--ease-out);
}
.skip-link:focus { top: 8px; color: #fff; }

/* 3. ---- Layout ----------------------------------------------------------- */
.main-header.navbar {
    background-color: var(--navy);
    border-bottom: none;
}
.main-header .nav-link,
.main-header .navbar-brand-text { color: #fff !important; }

.main-sidebar,
.sidebar-dark-primary {
    background-color: var(--navy);
    transition: margin-left var(--t-slow) var(--ease-out);
}
.brand-link {
    background-color: var(--navy) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Make the sidebar a full-height column so logout can sit at the bottom */
.main-sidebar .sidebar { display: flex; flex-direction: column; }
.main-sidebar .sidebar > nav { flex: 1 1 auto; display: flex; }
.nav-sidebar { flex: 1 1 auto; display: flex; flex-direction: column; }

.sidebar .nav-sidebar .nav-link {
    color: #c7c9d9;
    border-left: 3px solid transparent;
    transition: background-color var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}
.sidebar .nav-sidebar .nav-link:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.06);
}
.sidebar .nav-sidebar .nav-link.active {
    background-color: rgba(79, 140, 255, 0.15) !important;
    border-left: 3px solid var(--accent);
    color: #fff !important;
    box-shadow: none;
}
.sidebar .nav-icon { font-size: var(--icon-nav); }

/* Settings + Logout pinned to the bottom, separated by a divider */
.nav-bottom {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 8px;
}
.nav-logout .nav-link { color: #ff9a9a; }
.nav-logout .nav-link:hover { background-color: rgba(255, 80, 80, 0.12); color: #fff; }

.content-wrapper { background-color: var(--bg); }
.content-wrapper .container-fluid {
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--pad-x);
    padding-right: var(--pad-x);
}
.content-header { padding-top: 14px; padding-bottom: 6px; }
.content-header h1 { font-size: 24px; font-weight: 700; }

.main-footer { background: var(--bg); color: var(--muted); font-size: 12px; }

/* 4. ---- Components ------------------------------------------------------- */
/* Cards */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}
.card-header {
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    border-bottom: 1px solid var(--border);
}
.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}
.card-header.bg-navy-brand { background-color: var(--navy); }
.card-header.bg-navy-brand .card-title { color: #fff; }

/* Brand utility backgrounds */
.bg-navy-brand { background-color: var(--navy) !important; color: #fff !important; }
.bg-danger-brand { background-color: var(--danger) !important; color: #fff !important; }
.text-navy-brand { color: var(--navy) !important; }

/* Stat / summary cards: number left, label below, icon right */
.small-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px 20px;
    margin-bottom: 16px;
    color: #fff;
}
.small-box > .inner { padding: 0; }
.small-box > .inner h3 {
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.15;
    white-space: nowrap;
}
.small-box > .inner h3.value-figure { font-size: 22px; }
.small-box > .inner p {
    font-size: 12px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.85);
    margin: 4px 0 0;
}
.small-box > .icon {
    position: static !important;
    width: auto !important;
    height: auto !important;
    top: auto !important;
    right: auto !important;
    color: rgba(255, 255, 255, 0.35);
    animation: none !important;
    transition: none !important;
}
.small-box > .icon > i {
    font-size: var(--icon-stat) !important;
    top: auto !important;
}
.small-box:hover > .icon > i { transform: none; }

/* Dashboard summary cards lift on hover */
.dash-card { transition: transform var(--t-mid) var(--ease-out), box-shadow var(--t-mid) var(--ease-out); }
.dash-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-card-hover); }

/* Badges */
.badge { font-size: 12px; font-weight: 600; padding: 0.35em 0.6em; border-radius: 6px; }
.badge-success-brand { background-color: var(--success); color: #fff; }
.badge-danger-brand { background-color: var(--danger); color: #fff; }

/* Buttons */
.btn {
    min-height: 44px;
    cursor: pointer;
    touch-action: manipulation;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--t-fast) var(--ease-out),
                color var(--t-fast) var(--ease-out),
                transform var(--t-fast) var(--ease-out),
                opacity var(--t-fast) var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn.disabled { opacity: 0.65; cursor: not-allowed; }
.btn i { font-size: var(--icon-action); }
.btn-sm { min-height: 38px; }

.btn-navy { background-color: var(--navy); border-color: var(--navy); color: #fff; }
.btn-navy:hover, .btn-navy:focus { background-color: #2b2b4a; border-color: #2b2b4a; color: #fff; }
.btn-accent { background-color: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background-color: #3a78ec; color: #fff; }
.btn-outline-navy { border: 1px solid var(--navy); color: var(--navy); background: var(--surface); }
.btn-outline-navy:hover { background: var(--navy); color: #fff; }
.btn-danger:hover { background-color: #a93226; }
.btn-light:hover { background-color: #e2e6ea; }

/* Tables */
.table { color: var(--text); }
.table thead th {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    border-top: none;
}
.table td { border-top: 1px solid var(--border); vertical-align: middle; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Forms */
label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 4px;
}
.req { color: var(--danger); }
.form-control {
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    min-height: 44px;
}
.form-control:focus { border-color: var(--accent); box-shadow: none; }
.form-control-sm { min-height: 38px; }
.input-group-text { background: var(--bg); border-color: var(--border); color: var(--muted); }
.field-error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
}

/* 5. ---- Page-specific ---------------------------------------------------- */
/* Auth pages */
.auth-body {
    background-color: var(--navy);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    margin: 0;
}
.auth-card {
    background: var(--surface);
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    padding: 32px;
}
.auth-card-wide { max-width: 440px; }
.auth-brand {
    text-align: center;
    font-weight: 700;
    font-size: 28px;
    letter-spacing: 0.06em;
    color: var(--navy);
}
.auth-subtitle {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 24px;
}

/* Low-stock row: colour + badge/icon (never colour alone) */
#stock-table tr.low-stock,
#stock-table tr.low-stock > td { background-color: #fbeae8 !important; }

/* Upload dropzone + reliable bouncing dots */
.upload-dropzone {
    display: block;
    width: 100%;
    border: 2px dashed #c7ccd6;
    border-radius: var(--radius);
    padding: 40px 16px;
    text-align: center;
    color: var(--muted);
    cursor: pointer;
    margin-bottom: 0;
    transition: border-color var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}
.upload-dropzone:hover { border-color: var(--accent); color: var(--navy); }
.upload-dropzone.has-file { border-color: var(--success); color: var(--success); }

.bouncing-dots { display: none; justify-content: center; align-items: center; gap: 8px; padding: 40px 0; }
.scan-form.is-loading .upload-controls { display: none; }
.scan-form.is-loading .bouncing-dots { display: flex; }
.bouncing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--navy);
    animation: dot-bounce 1s infinite ease-in-out both;
}
.bouncing-dots span:nth-child(1) { animation-delay: 0s; }
.bouncing-dots span:nth-child(2) { animation-delay: 0.1s; }
.bouncing-dots span:nth-child(3) { animation-delay: 0.2s; }

/* Editable confirmation: borderless inputs unless focused */
.confirm-table .form-control { border-color: transparent; background: transparent; box-shadow: none; }
.confirm-table .form-control:focus { border-color: var(--accent); background: var(--surface); }

/* Reports */
.section-title { font-size: 18px; font-weight: 600; color: var(--navy); margin: 8px 0 16px; }
.section-divider { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }
.chart-wrap { position: relative; height: 280px; }
.chart-summary { font-size: 12px; color: var(--muted); margin-top: 12px; }

/* Welcome banner (dashboard) */
.welcome-banner {
    background: var(--surface);
    border-left: 4px solid var(--navy);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px 20px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.welcome-greeting h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--navy); }
.welcome-greeting .welcome-date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.welcome-badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.status-pill {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
}
.status-pill.navy { background: var(--navy); color: #fff; }
.status-pill.red { background: var(--danger); color: #fff; }
.status-pill.grey { background: #e2e6ea; color: #555; }
@media (max-width: 767.98px) {
    .welcome-banner { flex-direction: column; align-items: flex-start; }
}

/* Donut (stock health) */
.donut-wrap { position: relative; height: 280px; }
.donut-wrap.all-healthy canvas { filter: drop-shadow(0 0 8px rgba(26, 122, 74, 0.55)); }
.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}
.donut-center .dc-number { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; }
.donut-center .dc-label { font-size: 11px; color: var(--muted); }
.donut-legend { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 12px; }
.donut-legend .leg { display: inline-flex; align-items: center; font-size: 12px; color: var(--text); }
.donut-legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* Password show/hide toggle button matches input height */
.pw-toggle { border-color: var(--border); color: var(--muted); }
.pw-toggle:hover { background: var(--bg); color: var(--navy); }

/* Empty states */
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-state .empty-icon { font-size: 48px; color: #c2c8d0; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--navy); margin-bottom: 6px; }
.empty-state p { font-size: 12px; color: var(--muted); margin: 0; }

/* 6. ---- Utilities -------------------------------------------------------- */
.font-weight-600 { font-weight: 600; }
.cursor-pointer { cursor: pointer; }

/* 7. ---- Animations & keyframes ------------------------------------------- */
@keyframes dot-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}
@keyframes flash-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes flash-deplete {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

.alert {
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
    animation: flash-in var(--t-mid) var(--ease-out);
}
.flash-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    transform-origin: left center;
    animation: flash-deplete 5s linear forwards;
}

/* 8. ---- Media queries (mobile-first) ------------------------------------- */
@media (min-width: 768px) {
    :root { --pad-x: 24px; }
}
@media (min-width: 1024px) {
    :root { --pad-x: 32px; }
}

/* Touch targets stay generous on small screens */
@media (max-width: 767.98px) {
    .btn { min-height: 44px; }
    .search-filter-row > [class^="col-"] { width: 100%; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0ms !important;
        animation-duration: 0ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}

/* =========================================================================
   ===== ADMIN STYLES =====
   ========================================================================= */
.bg-success-brand { background-color: var(--success) !important; color: #fff !important; }

.badge-warning-brand { background-color: var(--warning); color: #fff; }
.text-warning-brand { color: var(--warning) !important; }

/* Activity action badges */
.badge-act-login { background-color: #e2e6ea; color: #555; }
.badge-act-scan { background-color: var(--accent); color: #fff; }
.badge-act-po { background-color: var(--success); color: #fff; }

/* Churn / at-risk card */
.card-churn { border-left: 4px solid var(--danger); }

/* Welcome toast */
.welcome-toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 3000;
    background: var(--navy);
    color: #fff;
    padding: 12px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    font-weight: 600;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity var(--t-mid) var(--ease-out), transform var(--t-mid) var(--ease-out);
}
.welcome-toast.show { opacity: 1; transform: translateY(0); }

/* Support notes list */
.support-note {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
}

/* Informational panel (placeholder) */
.info-panel {
    background: #eef4ff;
    border: 1px solid #cfe0ff;
    color: #2b4a73;
    border-radius: var(--radius);
    padding: 16px;
    font-size: 14px;
}
