/* ==========================================================================
   ERP platform — modern professional UI. Self-hosted (CSP-safe). Gradient
   accents derive from --brand via color-mix so per-tenant theming flows through.
   Light/dark aware. Class names preserved so existing views keep working.
   ========================================================================== */

:root {
    --brand: #6366f1;
    --brand-2: color-mix(in srgb, var(--brand), #7c3aed 45%);
    --accent-soft: color-mix(in srgb, var(--brand), transparent 88%);
    --accent-glow: color-mix(in srgb, var(--brand), transparent 62%);
    --on-brand: #fff;
    --grad-brand: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);

    --bg: #f5f6fb;
    --bg-grad: radial-gradient(1100px 560px at 100% -12%, color-mix(in srgb, var(--brand), #fff 86%) 0%, transparent 58%), #f5f6fb;
    --surface: #ffffff;
    --surface-2: #f2f4f9;
    --surface-hover: #eef1f8;
    --sidebar-bg: #ffffff;
    --text: #1b2233;
    --text-muted: #5b6478;
    --text-faint: #8a91a3;
    --border: #e7e9f2;
    --border-strong: #d6d9e6;

    --green: #16a34a; --green-soft: rgba(22,163,74,.12);
    --amber: #d97706; --amber-soft: rgba(217,119,6,.14);
    --red: #dc2626;   --red-soft: rgba(220,38,38,.12);
    --danger: var(--red); --danger-bg: var(--red-soft);
    --success: var(--green); --success-bg: var(--green-soft);
    --warning: var(--amber);

    --radius-sm: 9px; --radius: 13px; --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
    --shadow: 0 4px 16px -4px rgba(16,24,40,.10), 0 2px 6px -2px rgba(16,24,40,.06);
    --shadow-lg: 0 24px 48px -14px rgba(16,24,40,.22);
    --ring: 0 0 0 3px var(--accent-soft);
    --sidebar-w: 260px; --topbar-h: 64px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
    --bg: #0b0e16; --bg-grad: radial-gradient(1100px 560px at 100% -12%, color-mix(in srgb, var(--brand), #000 55%) 0%, transparent 55%), #0b0e16;
    --surface: #151926; --surface-2: #1b2030; --surface-hover: #222839; --sidebar-bg: #0e111a;
    --text: #e8eaf2; --text-muted: #9aa3b8; --text-faint: #6b7488; --border: #232838; --border-strong: #2d3346;
    --green-soft: rgba(34,197,94,.16); --amber-soft: rgba(245,158,11,.18); --red-soft: rgba(248,113,113,.16);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 8px 24px -6px rgba(0,0,0,.5); --shadow-lg: 0 28px 56px -16px rgba(0,0,0,.65);
}}
:root[data-theme="dark"] {
    --bg: #0b0e16; --bg-grad: radial-gradient(1100px 560px at 100% -12%, color-mix(in srgb, var(--brand), #000 55%) 0%, transparent 55%), #0b0e16;
    --surface: #151926; --surface-2: #1b2030; --surface-hover: #222839; --sidebar-bg: #0e111a;
    --text: #e8eaf2; --text-muted: #9aa3b8; --text-faint: #6b7488; --border: #232838; --border-strong: #2d3346;
    --green-soft: rgba(34,197,94,.16); --amber-soft: rgba(245,158,11,.18); --red-soft: rgba(248,113,113,.16);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 8px 24px -6px rgba(0,0,0,.5); --shadow-lg: 0 28px 56px -16px rgba(0,0,0,.65);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font); background: var(--bg-grad); background-attachment: fixed; color: var(--text); font-size: 14.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { line-height: 1.25; letter-spacing: -.015em; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--text-muted), transparent 62%); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }

/* --- Auth ---------------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-hero { background: var(--grad-brand); color: #fff; padding: 3.5rem 3rem; display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.auth-hero::after { content:""; position:absolute; inset:0; background: radial-gradient(600px 300px at 80% 20%, rgba(255,255,255,.18), transparent 60%), radial-gradient(500px 260px at 10% 90%, rgba(255,255,255,.10), transparent 60%); }
.auth-hero h1 { font-size: 2.15rem; margin: 0 0 .75rem; position: relative; }
.auth-hero p { opacity: .92; max-width: 40ch; font-size: 1.02rem; position: relative; }
.auth-hero .badge-row { margin-top: 2rem; display: flex; gap: .5rem; flex-wrap: wrap; position: relative; }
.auth-hero .badge { background: rgba(255,255,255,.18); backdrop-filter: blur(4px); padding: .35rem .8rem; border-radius: 999px; font-size: .82rem; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.4rem; }
.auth-card h2 { margin: 0 0 .25rem; font-size: 1.5rem; }
.auth-card .sub { color: var(--text-muted); margin: 0 0 1.5rem; font-size: .92rem; }
@media (max-width: 860px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { display: none; } }

/* --- Forms --------------------------------------------------------------- */
.field { margin-bottom: 1.05rem; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .4rem; color: var(--text); }
.field .hint { font-size: .75rem; color: var(--text-muted); margin-top: .3rem; }
.input, .textarea { width: 100%; padding: .6rem .8rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: .92rem; font-family: inherit; transition: border-color .15s, box-shadow .15s; }
.input:hover { border-color: color-mix(in srgb, var(--brand), var(--border-strong) 55%); }
.input:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
select.input { cursor: pointer; }
.input-group { display: flex; }
.input-group .addon { display: flex; align-items: center; padding: 0 .8rem; background: var(--surface-2); border: 1px solid var(--border-strong); border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); color: var(--text-muted); font-size: .85rem; white-space: nowrap; }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .62rem 1.05rem; border: none; border-radius: var(--radius-sm); background: var(--grad-brand); color: var(--on-brand); font-size: .9rem; font-weight: 600; cursor: pointer; width: 100%; box-shadow: 0 6px 16px -8px var(--accent-glow); transition: transform .12s, box-shadow .15s, filter .15s; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn:hover { text-decoration: none; transform: translateY(-1px); filter: brightness(1.04); box-shadow: 0 10px 22px -8px var(--accent-glow); }
.btn:active { transform: translateY(0); }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); width: auto; box-shadow: var(--shadow-sm); }
.btn-ghost:hover { background: var(--surface-hover); border-color: color-mix(in srgb, var(--brand), var(--border-strong) 40%); color: var(--brand); filter: none; }

.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .87rem; margin-bottom: 1.1rem; display: flex; gap: .5rem; align-items: center; }
.alert-error { background: var(--red-soft); color: var(--red); border: 1px solid color-mix(in srgb, var(--red), transparent 72%); }
.alert-success { background: var(--green-soft); color: var(--green); border: 1px solid color-mix(in srgb, var(--green), transparent 72%); }

/* --- App shell ----------------------------------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow: hidden; }
.sidebar .brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1rem .9rem; }
.sidebar .brand .logo { width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px; background: var(--grad-brand); box-shadow: 0 6px 16px -6px var(--accent-glow); }
.sidebar .brand .bt { font-weight: 700; font-size: 15px; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar nav { padding: .35rem .7rem; overflow-y: auto; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; padding: .52rem .65rem; border-radius: 10px; color: var(--text-muted); font-size: .875rem; font-weight: 550; margin-bottom: 2px; transition: background .14s, color .14s; }
.sidebar nav a svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.sidebar nav a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--brand); font-weight: 650; }
.sidebar nav a.active svg { opacity: 1; }
.sidebar .navlabel { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); padding: 14px 10px 5px; font-weight: 700; }
.sidebar .foot { padding: .75rem; border-top: 1px solid var(--border); }
.sidebar .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: 14px; padding: 0 1.6rem; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: saturate(180%) blur(14px); position: sticky; top: 0; z-index: 30; }
.topbar .page-title { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.icon-btn { width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); display: grid; place-items: center; cursor: pointer; transition: all .14s; }
.icon-btn:hover { color: var(--brand); border-color: var(--brand); background: var(--accent-soft); text-decoration: none; }
.icon-btn svg { width: 19px; height: 19px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; background: linear-gradient(135deg, #8b5cf6, var(--brand)); cursor: pointer; }
.content { padding: 1.7rem; max-width: 1440px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.page-head h2 { margin: 0; }

/* --- KPI cards ----------------------------------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.15rem 1.2rem; box-shadow: var(--shadow-sm); overflow: hidden; transition: transform .15s, box-shadow .2s; }
.kpi::before { content:""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(135deg,#6366f1,#8b5cf6); }
.kpi:nth-child(6n+2)::before { background: linear-gradient(135deg,#0ea5e9,#22d3ee); }
.kpi:nth-child(6n+3)::before { background: linear-gradient(135deg,#10b981,#34d399); }
.kpi:nth-child(6n+4)::before { background: linear-gradient(135deg,#f59e0b,#f97316); }
.kpi:nth-child(6n+5)::before { background: linear-gradient(135deg,#ec4899,#f43f5e); }
.kpi:nth-child(6n+6)::before { background: linear-gradient(135deg,#14b8a6,#0ea5e9); }
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi .label { color: var(--text-muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi .value { font-size: 1.85rem; font-weight: 800; margin-top: .3rem; letter-spacing: -.02em; }
.kpi .value.grad { background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* --- Cards --------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow-sm); transition: box-shadow .2s; }
.card:hover { box-shadow: var(--shadow); }
.card h3 { margin-top: 0; }
.muted { color: var(--text-muted); }
.mt-2 { margin-top: 1rem; }
/* Charts share a fixed aspect ratio (ChartSvg), so a plain full-width SVG keeps
   side-by-side charts at equal, generous height. */
.dash-chart { margin-top: .6rem; }
.dash-chart svg { width: 100%; height: auto; display: block; }
@media (max-width: 820px) { .app { grid-template-columns: 1fr; } .sidebar { display: none; } .content { padding: 1.05rem; } }

/* --- Tables -------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: .885rem; }
.table th, .table td { text-align: left; padding: .7rem .65rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { font-size: .69rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); font-weight: 700; background: var(--surface-2); }
.table thead th:first-child { border-radius: 8px 0 0 0; } .table thead th:last-child { border-radius: 0 8px 0 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--accent-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table code { background: var(--surface-2); padding: .1rem .4rem; border-radius: 5px; font-size: .85em; }

/* --- Pills --------------------------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .58rem; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); text-transform: capitalize; }
.pill-active { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green), transparent 70%); }
.pill-trial { background: var(--accent-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand), transparent 65%); }
.pill-suspended { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red), transparent 70%); }
.pill-inactive, .pill-cancelled, .pill-deleted { background: var(--surface-2); color: var(--text-muted); }

.linkbtn { background: none; border: none; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

/* Icon action buttons for table rows */
.act, button.act { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .13s; vertical-align: middle; }
.act:hover { color: var(--brand); border-color: var(--brand); background: var(--accent-soft); text-decoration: none; }
.act.danger:hover { color: var(--red); border-color: var(--red); background: var(--red-soft); }
.act svg { width: 16px; height: 16px; }
.act-group { display: inline-flex; gap: .35rem; align-items: center; }
input[type="color"] { height: 42px; padding: .2rem; cursor: pointer; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); }
hr { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* --- Co-pilot — right-docked slide-in panel ----------------------------- */
.copilot-fab { position: fixed; right: 24px; bottom: 24px; width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer; background: var(--grad-brand); color: #fff; box-shadow: 0 14px 34px -8px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.2); display: grid; place-items: center; z-index: 60; transition: transform .18s; }
.copilot-fab:hover { transform: translateY(-2px) scale(1.04); }
.copilot-fab svg { width: 24px; height: 24px; }
.copilot-panel { position: fixed; top: 0; right: 0; height: 100vh; width: 400px; max-width: 92vw; z-index: 70; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; transform: translateX(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1); }
.copilot-panel.open { transform: none; }
.copilot-head { display: flex; align-items: center; gap: 11px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.copilot-head .cp-logo { width: 34px; height: 34px; border-radius: 10px; background: var(--grad-brand); color: #fff; display: grid; place-items: center; }
.copilot-head .cp-logo svg { width: 18px; height: 18px; }
.copilot-head .t { font-weight: 700; font-size: 14.5px; }
.copilot-head .s { font-size: 11.5px; color: var(--text-muted); }
.copilot-head .x { margin-left: auto; width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; font-size: 18px; }
.copilot-head .x:hover { color: var(--brand); border-color: var(--brand); }
.cp-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.cp-msg { display: flex; gap: 10px; max-width: 92%; }
.cp-msg .cp-av { width: 28px; height: 28px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.cp-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.cp-msg.user .cp-av { background: var(--surface-hover); color: var(--text-muted); }
.cp-msg.bot .cp-av { background: var(--grad-brand); color: #fff; }
.cp-bubble { padding: 10px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; }
.cp-msg.user .cp-bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.cp-msg.bot .cp-bubble { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.cp-suggest { display: flex; gap: .4rem; flex-wrap: wrap; padding: .6rem 1rem; border-top: 1px solid var(--border); }
.cp-suggest button { font-size: .76rem; padding: .32rem .6rem; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-muted); cursor: pointer; }
.cp-suggest button:hover { border-color: var(--brand); color: var(--brand); }
.cp-foot { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--border); background: var(--surface); }
.cp-foot .input { flex: 1; }
.cp-link { display: block; padding: .4rem .55rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-top: .4rem; }
