/* ============================================================================
   Better Trends DMS — custom design system (on Bootstrap 5.3)
   A bespoke, modern admin theme. Tokens → shell → components.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    /* ── Brand & palette ─────────────────────────────────────── */
    --dms-primary:      #6c5ce7;   /* indigo-violet */
    --dms-primary-600:  #5a48d6;
    --dms-primary-700:  #4c3cc4;
    --dms-primary-soft: #efecff;
    --dms-primary-rgb:  108, 92, 231;

    --dms-accent:   #0ea5e9;
    --dms-success:  #18a558;
    --dms-warning:  #f5a524;
    --dms-danger:   #ef4444;
    --dms-info:     #3b82f6;

    /* Neutrals (slate) */
    --dms-ink:      #0e1525;   /* sidebar */
    --dms-ink-2:    #18203250;
    --dms-body:     #f5f7fb;   /* app background */
    --dms-surface:  #ffffff;
    --dms-border:   #e8ebf2;
    --dms-border-2: #eef1f6;
    --dms-text:     #1f2733;
    --dms-muted:    #717a90;
    --dms-faint:    #99a1b3;

    /* Geometry */
    --dms-radius:    14px;
    --dms-radius-sm: 10px;
    --dms-radius-xs: 8px;
    --dms-shadow-sm: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.04);
    --dms-shadow:    0 4px 12px rgba(16,24,40,.06), 0 2px 4px rgba(16,24,40,.04);
    --dms-shadow-lg: 0 18px 40px rgba(16,24,40,.16);
    --dms-sidebar-w: 264px;

    /* ── Bootstrap variable overrides (5.3) ──────────────────── */
    --bs-body-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --bs-body-bg: var(--dms-body);
    --bs-body-color: var(--dms-text);
    --bs-body-font-size: 0.9rem;
    --bs-emphasis-color: #0b1220;
    --bs-secondary-color: var(--dms-muted);
    --bs-border-color: var(--dms-border);
    --bs-border-radius: var(--dms-radius-sm);
    --bs-border-radius-sm: var(--dms-radius-xs);
    --bs-border-radius-lg: var(--dms-radius);
    --bs-primary: var(--dms-primary);
    --bs-primary-rgb: var(--dms-primary-rgb);
    --bs-link-color: var(--dms-primary);
    --bs-link-color-rgb: var(--dms-primary-rgb);
    --bs-link-hover-color: var(--dms-primary-700);
}

* { -webkit-font-smoothing: antialiased; }
body { background: var(--dms-body); letter-spacing: -0.01em; }
h1,h2,h3,h4,h5,h6 { font-weight: 700; color: var(--bs-emphasis-color); letter-spacing: -0.02em; }
a { text-decoration: none; }
::selection { background: var(--dms-primary-soft); }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #cdd3df; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #aeb6c6; background-clip: content-box; }

/* ── App shell ───────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--dms-sidebar-w); flex-shrink: 0;
    background: var(--dms-ink);
    color: #aeb6c9;
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column;
    z-index: 1030;
}
.sidebar-brand {
    height: 70px; display: flex; align-items: center; gap: 10px;
    padding: 0 20px; flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand .brand-plate { background: #fff; border-radius: 9px; padding: 7px 10px; display: inline-flex; max-width: 100%; overflow: hidden; }
.sidebar-brand img { display: block; max-width: 100%; max-height: 24px; width: auto; height: auto; object-fit: contain; }
.sidebar-nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #ffffff22; }
.nav-section {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
    color: #5d6679; padding: 16px 12px 6px;
}
.nav-section-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; background: none; border: none; font: inherit; text-align: left; cursor: pointer;
    -webkit-appearance: none; appearance: none; box-shadow: none;
}
.nav-section-toggle:focus-visible { outline: 2px solid var(--dms-primary); outline-offset: 2px; border-radius: var(--dms-radius-xs); }
.nav-section-toggle:hover { color: #8a93a8; }
.nav-toggle-icon { font-size: 16px; opacity: .55; transition: transform .15s ease; flex-shrink: 0; }
.nav-group.collapsed .nav-toggle-icon { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-items { display: none; }
.nav-item-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin-bottom: 2px; border-radius: var(--dms-radius-sm);
    color: #aeb6c9; font-weight: 500; font-size: .9rem;
    transition: background .15s, color .15s;
}
.nav-item-link .mdi { font-size: 19px; opacity: .85; }
.nav-item-link:hover { background: #ffffff0d; color: #fff; }
.nav-item-link.active { background: var(--dms-primary); color: #fff; box-shadow: 0 6px 16px rgba(var(--dms-primary-rgb),.35); }
.nav-item-link.active .mdi { opacity: 1; }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.06); font-size: 12px; color: #5d6679; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Topbar */
.app-topbar {
    height: 70px; background: rgba(255,255,255,.85); backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--dms-border);
    display: flex; align-items: center; gap: 8px; padding: 0 22px;
    position: sticky; top: 0; z-index: 1020;
}
.topbar-btn {
    width: 40px; height: 40px; border: 1px solid var(--dms-border); background: var(--dms-surface);
    border-radius: var(--dms-radius-sm); color: var(--dms-text);
    display: inline-grid; place-items: center; font-size: 20px; cursor: pointer;
    transition: background .15s, border-color .15s;
}
.topbar-btn:hover { background: var(--dms-body); border-color: #d7dce6; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 8px; border-radius: var(--dms-radius-sm); }
.topbar-user:hover { background: var(--dms-body); }
.topbar-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--dms-primary); color: #fff; display: grid; place-items: center; font-weight: 700; }

.app-content { padding: 26px; max-width: 1320px; width: 100%; }

/* Page head */
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 1.4rem; margin: 0; }
.page-head .breadcrumb { margin: 4px 0 0; font-size: .82rem; }
.breadcrumb-item, .breadcrumb-item a { color: var(--dms-muted); }
.breadcrumb-item.active { color: var(--dms-text); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--dms-surface);
    border: 1px solid var(--dms-border);
    border-radius: var(--dms-radius);
    box-shadow: var(--dms-shadow-sm);
    margin-bottom: 22px;
}
.card-body { padding: 22px; }
.card-title { font-size: 1.02rem; font-weight: 700; }
.card-subtitle { color: var(--dms-muted); }

/* Stat tiles */
.stat-tile { display: flex; align-items: center; gap: 16px; }
.stat-ico { width: 52px; height: 52px; border-radius: 13px; display: grid; place-items: center; font-size: 26px; }
.stat-ico.primary { background: var(--dms-primary-soft); color: var(--dms-primary); }
.stat-ico.info { background: #e3f2fe; color: var(--dms-info); }
.stat-ico.success { background: #e3f7ec; color: var(--dms-success); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn { font-weight: 600; border-radius: var(--dms-radius-sm); padding: .5rem .95rem; letter-spacing: -0.01em; transition: all .15s; }
.btn-sm { padding: .34rem .7rem; border-radius: var(--dms-radius-xs); }
.btn:focus-visible, .form-control:focus, .form-select:focus { box-shadow: 0 0 0 .2rem rgba(var(--dms-primary-rgb),.25); }
.btn-primary { --bs-btn-bg: var(--dms-primary); --bs-btn-border-color: var(--dms-primary); --bs-btn-hover-bg: var(--dms-primary-600); --bs-btn-hover-border-color: var(--dms-primary-600); --bs-btn-active-bg: var(--dms-primary-700); color:#fff; box-shadow: 0 6px 16px rgba(var(--dms-primary-rgb),.30); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(var(--dms-primary-rgb),.38); }
.btn-outline-primary { --bs-btn-color: var(--dms-primary); --bs-btn-border-color: #d8d2fb; --bs-btn-hover-bg: var(--dms-primary); --bs-btn-hover-border-color: var(--dms-primary); }
.btn-light { --bs-btn-bg: var(--dms-body); --bs-btn-border-color: var(--dms-border); --bs-btn-hover-bg: #eef1f6; }
.btn-outline-secondary { --bs-btn-color: var(--dms-muted); --bs-btn-border-color: var(--dms-border); --bs-btn-hover-bg: var(--dms-body); --bs-btn-hover-color: var(--dms-text); --bs-btn-hover-border-color: var(--dms-border); }
.btn-outline-danger { --bs-btn-color: var(--dms-danger); --bs-btn-border-color: #f3c8c8; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-label { font-weight: 600; font-size: .82rem; color: #41495b; margin-bottom: .35rem; }
.form-control, .form-select { border-color: var(--dms-border); border-radius: var(--dms-radius-xs); padding: .55rem .8rem; font-size: .9rem; background-color: #fcfdff; }
.form-control:hover, .form-select:hover { border-color: #d4d9e3; }
.form-control:focus, .form-select:focus { border-color: var(--dms-primary); background-color: #fff; }
.form-control::placeholder { color: var(--dms-faint); }
.form-check-input:checked { background-color: var(--dms-primary); border-color: var(--dms-primary); }
.form-switch .form-check-input { width: 2.4em; height: 1.25em; }
.input-group-text { background: var(--dms-body); border-color: var(--dms-border); color: var(--dms-muted); }

/* ── Tables ─────────────────────────────────────────────────── */
.table { --bs-table-hover-bg: #f7f8fc; margin-bottom: 0; }
.table > thead th {
    font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--dms-faint); border-bottom: 1px solid var(--dms-border); padding: .7rem .85rem; white-space: nowrap;
}
.table > tbody td { padding: .8rem .85rem; border-bottom: 1px solid var(--dms-border-2); vertical-align: middle; }
.table > tbody tr:last-child td { border-bottom: 0; }

/* ── Badges (soft, modern) ──────────────────────────────────── */
.badge { font-weight: 600; padding: .4em .65em; border-radius: 7px; font-size: .72rem; letter-spacing: .01em; }
.badge.bg-success { background: #e3f7ec !important; color: #0f7a3d !important; }
.badge.bg-warning { background: #fff3df !important; color: #a3650b !important; }
.badge.bg-secondary { background: #eef1f6 !important; color: #59617a !important; }
.badge.bg-primary { background: var(--dms-primary-soft) !important; color: var(--dms-primary-700) !important; }
.badge.bg-info { background: #e3f2fe !important; color: #0b6aa8 !important; }
.badge.bg-danger { background: #fde7e7 !important; color: #b42318 !important; }
.badge.bg-light { background: var(--dms-body) !important; color: var(--dms-muted) !important; border: 1px solid var(--dms-border); }

/* ── Tabs (modern underline) ────────────────────────────────── */
.nav-tabs { border-bottom: 1px solid var(--dms-border); gap: 2px; flex-wrap: wrap; }
.nav-tabs .nav-link {
    border: 0; border-bottom: 2px solid transparent; color: var(--dms-muted);
    font-weight: 600; font-size: .88rem; padding: .7rem .95rem; border-radius: 0;
}
.nav-tabs .nav-link:hover { color: var(--dms-text); border-bottom-color: #d8dbe4; }
.nav-tabs .nav-link.active { color: var(--dms-primary); background: transparent; border-bottom-color: var(--dms-primary); }
.nav-tabs .nav-link .badge { transform: translateY(-1px); }

/* ── Dropdowns / modals / alerts ────────────────────────────── */
.dropdown-menu { border: 1px solid var(--dms-border); border-radius: var(--dms-radius); box-shadow: var(--dms-shadow-lg); padding: 8px; font-size: .88rem; }
.dropdown-item { border-radius: var(--dms-radius-xs); padding: .5rem .7rem; font-weight: 500; }
.dropdown-item:hover { background: var(--dms-body); }
.dropdown-item:active { background: var(--dms-primary); }
.dropdown-header { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dms-faint); }
.modal-content { border: 0; border-radius: var(--dms-radius); box-shadow: var(--dms-shadow-lg); }
.modal-header, .modal-footer { border-color: var(--dms-border); }
.alert { border: 0; border-radius: var(--dms-radius-sm); font-weight: 500; padding: .85rem 1rem; }
.alert-success { background: #e3f7ec; color: #0f7a3d; }
.alert-danger { background: #fde7e7; color: #b42318; }
.alert-warning { background: #fff3df; color: #a3650b; }

/* List groups (key highlights etc.) */
.list-group-item { border-color: var(--dms-border-2); }

/* ── Mega menu ──────────────────────────────────────────────── */
.mega-dropdown { position: static; }
.mega-dropdown .dropdown-menu { width: min(680px, 92vw); padding: 20px 22px; }
.mega-dropdown h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dms-faint); }
.list-style-none { list-style: none; padding: 0; margin: 0; }
.list-style-none .dropdown-item { padding: .42rem .4rem; }

/* ── Auth ───────────────────────────────────────────────────────────────
   Split panel: a branded side (left, dark) carrying the one signature
   element — an animated "circle of business" diagram (PIM → Procurement →
   Shipment → Warehouse → Marketplace → Finance, looping) — and a plain
   sign-in panel (right, white) matching the rest of the app's forms. */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr minmax(360px, 400px); }

.auth-brand {
    background: radial-gradient(1100px 560px at 75% -8%, #2a2350 0%, var(--dms-ink) 55%);
    color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 40px; position: relative; overflow: hidden;
}
.auth-logo-mobile { display: none; }

/* The circle-of-business diagram: an SVG layer (glow + orbit path + comet-trail
   dot) under an HTML overlay (center logo + 6 icon/label nodes), sharing one
   coordinate system via `aspect-ratio` matching the SVG viewBox exactly, so
   the percentage-positioned HTML nodes always land precisely on the SVG path. */
.auth-cycle { position: relative; width: 100%; max-width: 620px; aspect-ratio: 440 / 400; margin: auto; }
.auth-cycle-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.auth-lane-path { fill: none; stroke: #3a4160; stroke-width: 2; stroke-dasharray: 1 7; stroke-linecap: round; }
.auth-lane-dot { fill: var(--dms-accent); filter: drop-shadow(0 0 5px rgba(14,165,233,.85)); }
.auth-lane-dot-trail1 { opacity: .5; filter: drop-shadow(0 0 3px rgba(14,165,233,.6)); }
.auth-lane-dot-trail2 { opacity: .22; filter: none; }

.auth-cycle-center {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 40%; display: flex; align-items: center; justify-content: center;
}
.auth-cycle-center img { display: block; max-width: 100%; max-height: 88px; width: auto; height: auto; object-fit: contain; }

/* The node's own left/top % is the exact point on the r=140 orbit — the icon
   is centered ON that point directly (translate -50%/-50%) so it sits exactly
   on the path the dot travels; the label is a sibling offset below it, NOT
   part of a shared centered stack (that was the earlier bug: centering an
   icon+label flex column put the icon itself off the true circle). */
.auth-cycle-node { position: absolute; }
.auth-cycle-icon {
    position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
    width: 50px; height: 50px; border-radius: 50%;
    background: var(--dms-ink); border: 2px solid #4a5378;
    display: grid; place-items: center; color: #aeb6c9; font-size: 22px;
    animation: authCyclePulse 10s infinite;
}
.auth-cycle-icon .mdi { position: relative; top: -1px; }
.auth-cycle-label {
    position: absolute; left: 0; top: 33px; transform: translate(-50%, 0);
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #7c869e;
}
@keyframes authCyclePulse {
    0%   { box-shadow: 0 0 0 0 rgba(14,165,233,.65); border-color: var(--dms-accent); color: #fff; }
    6%   { box-shadow: 0 0 0 9px rgba(14,165,233,0); border-color: var(--dms-accent); color: #fff; }
    13%, 100% { border-color: #4a5378; color: #aeb6c9; }
}
@media (prefers-reduced-motion: reduce) {
    .auth-cycle-icon { animation: none; }
}

.auth-form-panel { background: var(--dms-surface); display: flex; align-items: center; justify-content: center; padding: 40px 32px; }
.auth-form-inner { width: 100%; max-width: 320px; }
.auth-form-inner h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 24px; }
.auth-form-inner .form-label { font-weight: 600; font-size: .84rem; color: var(--dms-text); }
.auth-field-wrap { position: relative; }
.auth-field-wrap .form-control { padding-right: 42px; }
.auth-toggle-pw {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px; border: 0; background: transparent; color: var(--dms-faint);
    border-radius: var(--dms-radius-xs); display: grid; place-items: center; cursor: pointer;
}
.auth-toggle-pw:hover { color: var(--dms-muted); background: var(--dms-body); }
.auth-foot { color: var(--dms-faint); font-size: .78rem; margin-top: 28px; }

/* ── Avatar crop (profile photo) ─────────────────────────────── */
.avatar-crop-viewport {
    position: relative; width: 280px; height: 280px; margin: 0 auto;
    overflow: hidden; border-radius: var(--dms-radius-sm); background: var(--dms-body);
    cursor: grab; touch-action: none; user-select: none;
}
.avatar-crop-viewport:active { cursor: grabbing; }
.avatar-crop-viewport img { position: absolute; top: 0; left: 0; max-width: none; pointer-events: none; }
.avatar-crop-guide {
    position: absolute; inset: 0; border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(14, 21, 37, .55);
    border: 2px solid #fff; pointer-events: none;
}

@media (max-width: 767.98px) {
    .auth-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .auth-brand { flex-direction: row; align-items: center; justify-content: flex-start; padding: 20px 24px; }
    .auth-logo-mobile { display: block; }
    .auth-logo-mobile img { display: block; max-width: 180px; max-height: 30px; width: auto; height: auto; object-fit: contain; }
    .auth-cycle { display: none; }
    .auth-form-panel { padding: 32px 24px; }
}

/* ── Dashboard gauges & donut (pure CSS) ────────────────────── */
.gauge { width: 86px; height: 86px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.gauge-hole { width: 64px; height: 64px; border-radius: 50%; background: var(--dms-surface); display: grid; place-items: center; font-weight: 800; font-size: .9rem; color: var(--dms-text); }
.kpi-card { display: flex; align-items: center; justify-content: space-between; }
.kpi-card .kpi-label { font-size: 1.05rem; font-weight: 700; }
.kpi-card .kpi-sub { color: var(--dms-muted); font-size: .85rem; }
.donut { width: 240px; height: 240px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto; }
.donut-hole { width: 150px; height: 150px; border-radius: 50%; background: var(--dms-surface); display: grid; place-items: center; text-align: center; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 7px; }
.deptbar { height: 9px; border-radius: 6px; background: var(--dms-primary); }
.deptbar-track { background: var(--dms-body); border-radius: 6px; overflow: hidden; }

/* Utilities */
.text-muted { color: var(--dms-muted) !important; }
.fw-medium { font-weight: 600 !important; }
.cursor-pointer { cursor: pointer; }
.img-thumbnail { border-radius: var(--dms-radius-xs); border-color: var(--dms-border); }

/* Responsive sidebar */
.sidebar-backdrop { display: none; }
@media (max-width: 991px) {
    .app-sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; }
    .app.sidebar-open .app-sidebar { transform: translateX(0); }
    .app.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(8,12,22,.5); z-index: 1029; }
}
