/* ===========================================================================
   Niyanta core stylesheet
   Design tokens derive from the active palette (--color-primary/secondary/accent)
   which is injected per-request by Branding::cssVariables(). Both light and dark
   modes are tinted by the palette via color-mix(), so switching palettes
   re-themes the whole app.
   =========================================================================== */

:root {
    --color-primary: #0B1F4D;
    --color-secondary: #6EC1FF;
    --color-accent: #FFD84D;

    --sidebar-width: 264px;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-pill: 999px;

    /* spacing scale */
    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
}

/* ---- Semantic tokens: LIGHT ---- */
:root,
[data-bs-theme="light"] {
    --brand: var(--color-primary);
    --brand-hover: color-mix(in srgb, var(--color-primary) 86%, #000);
    --brand-soft: color-mix(in srgb, var(--color-primary) 10%, transparent);
    --on-brand: #fff;
    --accent: var(--color-accent);

    --app-bg: color-mix(in srgb, var(--color-secondary) 9%, #f2f5fb);
    --surface: #ffffff;
    --surface-2: color-mix(in srgb, var(--color-secondary) 7%, #ffffff);
    --surface-muted: color-mix(in srgb, var(--color-secondary) 12%, #ffffff);
    --border: color-mix(in srgb, var(--color-primary) 12%, #e7eaf3);
    --ink: #1d2433;
    --muted: color-mix(in srgb, var(--color-primary) 35%, #71788a);

    --sidebar-bg: var(--color-primary);
    --sidebar-grad: color-mix(in srgb, var(--color-primary) 80%, #000);
    --sidebar-text: rgba(255, 255, 255, .78);
    --sidebar-text-strong: #fff;
    --sidebar-active-bg: var(--color-secondary);
    --sidebar-active-ink: var(--color-primary);
    --sidebar-hover-bg: rgba(255, 255, 255, .10);

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
    --shadow: 0 4px 16px rgba(16, 24, 40, .08);
    --shadow-lg: 0 18px 48px rgba(16, 24, 40, .18);
}

/* ---- Semantic tokens: DARK (palette-tinted) ---- */
[data-bs-theme="dark"] {
    --brand: color-mix(in srgb, var(--color-secondary) 70%, var(--color-primary));
    --brand-hover: color-mix(in srgb, var(--color-secondary) 85%, #fff);
    --brand-soft: color-mix(in srgb, var(--color-secondary) 16%, transparent);
    --on-brand: #06121f;
    --accent: var(--color-accent);

    --app-bg: color-mix(in srgb, var(--color-primary) 16%, #0b0e14);
    --surface: color-mix(in srgb, var(--color-primary) 14%, #11151c);
    --surface-2: color-mix(in srgb, var(--color-primary) 22%, #11151c);
    --surface-muted: color-mix(in srgb, var(--color-primary) 30%, #11151c);
    --border: color-mix(in srgb, var(--color-secondary) 14%, #2b313d);
    --ink: #e8edf6;
    --muted: color-mix(in srgb, var(--color-secondary) 24%, #97a0b3);

    --sidebar-bg: color-mix(in srgb, var(--color-primary) 42%, #070a0f);
    --sidebar-grad: color-mix(in srgb, var(--color-primary) 30%, #05070b);
    --sidebar-text: rgba(255, 255, 255, .72);
    --sidebar-text-strong: #fff;
    --sidebar-active-bg: color-mix(in srgb, var(--color-secondary) 30%, transparent);
    --sidebar-active-ink: #fff;
    --sidebar-hover-bg: rgba(255, 255, 255, .07);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 6px 20px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);

    /* re-point Bootstrap dark tokens at the palette */
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--ink);
    --bs-border-color: var(--border);
    --bs-secondary-bg: var(--surface-2);
    --bs-tertiary-bg: var(--surface);
    --bs-emphasis-color: #fff;
    --bs-secondary-color: var(--muted);
}

/* ---- Base ---- */
* { -webkit-font-smoothing: antialiased; }
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--app-bg);
    color: var(--ink);
    letter-spacing: -.01em;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
h1, h2, h3, h4, h5 { letter-spacing: -.02em; }
.text-muted { color: var(--muted) !important; }
code { color: var(--brand); }

/* ---- Bootstrap remaps onto the brand ---- */
:root { --bs-primary: var(--brand); --bs-link-color: var(--brand); --bs-link-hover-color: var(--brand-hover); }
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-hover);
    --bs-btn-hover-border-color: var(--brand-hover);
    --bs-btn-active-bg: var(--brand-hover);
    --bs-btn-active-border-color: var(--brand-hover);
    --bs-btn-color: var(--on-brand);
    --bs-btn-hover-color: var(--on-brand);
    --bs-btn-active-color: var(--on-brand);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-disabled-color: var(--on-brand);
}
.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: color-mix(in srgb, var(--brand) 55%, transparent);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-hover-color: var(--on-brand);
    --bs-btn-active-bg: var(--brand);
    --bs-btn-active-border-color: var(--brand);
    --bs-btn-active-color: var(--on-brand);
}
.badge.text-bg-primary { background: var(--brand) !important; color: var(--on-brand) !important; }
.badge.text-bg-success { background: #16a34a !important; }
.btn { --bs-btn-border-radius: var(--radius-sm); font-weight: 500; }
.btn-sm { --bs-btn-border-radius: 8px; }

.form-control, .form-select {
    background: var(--surface);
    border-color: var(--border);
    color: var(--ink);
    border-radius: var(--radius-sm);
    padding: .55rem .8rem;
}
.form-control:focus, .form-select:focus, .btn-check:focus + .btn, .btn:focus-visible {
    border-color: var(--brand);
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 30%, transparent);
}
.form-control::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.form-control:disabled { background: var(--surface-muted); }
.form-control-color { padding: .25rem; min-width: 48px; height: 42px; }

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

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-grad));
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid color-mix(in srgb, #000 12%, transparent);
}
.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.app-content { flex: 1 1 auto; padding: var(--space-6) clamp(1rem, 2.5vw, 2.25rem); }
.app-content > .container-inner { max-width: 1240px; margin: 0 auto; }

/* ---- Sidebar ---- */
.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1.15rem 1.15rem;
    margin-bottom: .25rem;
}
.sidebar-logo {
    width: 38px; height: 38px; object-fit: contain;
    border-radius: 9px; background: #fff; padding: 3px;
}
.sidebar-company { font-weight: 700; color: var(--sidebar-text-strong); font-size: 1.02rem; }
.sidebar-company small { display: block; font-weight: 400; font-size: .72rem; color: var(--sidebar-text); letter-spacing: .02em; }

.brand-badge {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--color-accent); color: var(--color-primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; text-transform: uppercase; flex: 0 0 auto;
}

.sidebar-section {
    padding: .5rem 1.3rem .35rem;
    font-size: .68rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
    color: color-mix(in srgb, var(--sidebar-text) 75%, transparent);
}
.sidebar-nav { padding: .35rem .7rem 1rem; display: flex; flex-direction: column; gap: .15rem; }
.sidebar-link {
    position: relative;
    display: flex; align-items: center; gap: .8rem;
    padding: .62rem .8rem; border-radius: var(--radius-sm);
    color: var(--sidebar-text); font-weight: 500; font-size: .94rem;
    transition: background .15s ease, color .15s ease;
}
.sidebar-link i { font-size: 1.1rem; width: 1.4rem; text-align: center; opacity: .9; }
.sidebar-link:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-strong); }
.sidebar-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-ink); font-weight: 600; }
.sidebar-link.active::before {
    content: ""; position: absolute; left: -.7rem; top: 50%; transform: translateY(-50%);
    width: 4px; height: 60%; border-radius: 0 4px 4px 0; background: var(--color-accent);
}

/* ---- Topbar ---- */
.app-topbar {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem clamp(1rem, 2.5vw, 1.6rem);
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1020;
    min-height: 64px;
}
.topbar-title { font-size: 1.05rem; font-weight: 600; margin: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.btn-icon {
    width: 42px; height: 42px; border-radius: var(--radius-pill);
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); background: var(--surface); color: var(--ink);
    font-size: 1.05rem; transition: background .15s ease, transform .15s ease;
}
.btn-icon:hover { background: var(--surface-muted); color: var(--brand); }
.btn-icon:active { transform: scale(.94); }

.user-menu { display: flex; align-items: center; gap: .55rem; color: var(--ink); padding: .25rem .4rem; border-radius: var(--radius-pill); border: 1px solid transparent; }
.user-menu:hover { background: var(--surface-muted); color: var(--ink); }
.user-menu small { line-height: 1; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 60%, var(--color-accent)));
    color: var(--on-brand);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; text-transform: uppercase; flex: 0 0 auto;
}
.dropdown-menu {
    border-color: var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow); background: var(--surface); padding: .4rem;
}
.dropdown-item { border-radius: 8px; padding: .5rem .7rem; }
.dropdown-item:hover { background: var(--surface-muted); }

/* ===========================================================================
   Page header
   =========================================================================== */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: var(--space-5); }
.page-header h1 { font-size: 1.6rem; font-weight: 700; margin: 0 0 .2rem; }
.page-header .page-sub { color: var(--muted); margin: 0; }
.page-header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ===========================================================================
   Cards
   =========================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.4rem; }
.card h2.h6, .card h3.h6 { font-weight: 600; letter-spacing: 0; }
hr { border-color: var(--border); opacity: 1; }

/* ---- Dashboard stat widgets ---- */
.widget-card { position: relative; overflow: hidden; }
.widget-card::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
    background: linear-gradient(90deg, var(--brand), var(--color-accent));
    opacity: .85;
}
.widget-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.widget-title { font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.widget-icon {
    width: 44px; height: 44px; border-radius: 12px;
    background: var(--brand-soft); color: var(--brand);
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem;
}
.widget-body { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.widget-body .text-muted { font-size: .85rem; font-weight: 500; }

/* ===========================================================================
   Settings tab nav
   =========================================================================== */
.settings-nav {
    display: flex; gap: .35rem; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-pill); padding: .35rem; margin-bottom: var(--space-5);
    width: fit-content; max-width: 100%; box-shadow: var(--shadow-sm);
}
.settings-nav a {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .5rem .95rem; border-radius: var(--radius-pill);
    color: var(--muted); font-weight: 500; font-size: .92rem; white-space: nowrap;
}
.settings-nav a:hover { background: var(--surface-muted); color: var(--ink); }
.settings-nav a.active { background: var(--brand); color: var(--on-brand); }

/* ===========================================================================
   Palettes
   =========================================================================== */
.palette-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .85rem; background: var(--surface-2); transition: border-color .15s ease, box-shadow .15s ease; }
.palette-card.is-active { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 35%, transparent); }
.palette-swatches { display: flex; gap: .35rem; }
.palette-swatches span { flex: 1; height: 34px; border-radius: 8px; border: 1px solid rgba(0, 0, 0, .08); }
.logo-preview { max-width: 96px; max-height: 96px; border-radius: var(--radius-sm); border: 1px solid var(--border); padding: 6px; background: var(--surface); }

/* ---- Tables ---- */
.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); border-color: var(--border); margin-bottom: 0; }
.table > :not(caption) > * > * { border-color: var(--border); padding: .8rem .75rem; }
.table thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); }

/* ---- Alerts ---- */
.alert { border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ===========================================================================
   Auth & install
   =========================================================================== */
.auth-body {
    min-height: 100vh; display: flex; align-items: center;
    background:
        radial-gradient(1100px 520px at 100% -10%, color-mix(in srgb, var(--color-secondary) 30%, transparent), transparent),
        radial-gradient(900px 480px at -10% 110%, color-mix(in srgb, var(--color-primary) 22%, transparent), transparent),
        var(--app-bg);
}
.auth-wrap { width: 100%; max-width: 430px; margin: auto; padding: 1.25rem; }
.auth-card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.auth-logo { width: 68px; height: 68px; object-fit: contain; border-radius: 14px; }

/* ===========================================================================
   Responsive
   =========================================================================== */
.sidebar-toggle { color: var(--ink); font-size: 1.5rem; padding: .1rem .4rem; }
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed; z-index: 1045; left: 0; top: 0;
        transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
    }
    .app-sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1040; }
    .app-content { padding: var(--space-5) var(--space-4); }
}
