/* =================================================================
   WA-AI · Portal UI — shared design system for Admin & Tenant
   Layered on top of Bootstrap 5. Themed via .theme-admin / .theme-tenant.
   ================================================================= */

:root {
    /* Brand */
    --brand:        #25d366;
    --brand-dark:   #1aa851;
    --brand-soft:   rgba(37, 211, 102, .12);

    /* Neutrals */
    --bg:           #eef1f6;
    --surface:      #ffffff;
    --surface-2:    #f6f8fb;
    --border:       #e6e9f0;
    --border-soft:  #eef1f6;

    --text:         #1d2433;
    --text-muted:   #6b7587;
    --text-faint:   #98a2b3;

    --shadow-sm:    0 1px 2px rgba(16, 24, 40, .05);
    --shadow:       0 4px 16px rgba(16, 24, 40, .07);
    --shadow-lg:    0 18px 48px rgba(16, 24, 40, .14);

    --radius:       16px;
    --radius-sm:    11px;
    --radius-pill:  999px;

    --sidebar-w:    256px;

    /* Theme-driven (defaults to admin) */
    --sidebar-grad: linear-gradient(180deg, #20203f 0%, #15152b 100%);
    --accent:       #25d366;
    --accent-soft:  rgba(37, 211, 102, .16);
    --topbar-glow:  rgba(37, 211, 102, .10);
}

.theme-admin {
    --sidebar-grad: linear-gradient(185deg, #232348 0%, #16162c 100%);
    --accent:       #7c9bff;
    --accent-soft:  rgba(124, 155, 255, .18);
    --topbar-glow:  rgba(124, 155, 255, .10);
}

.theme-tenant {
    --sidebar-grad: linear-gradient(185deg, #15402e 0%, #0c2a1d 100%);
    --accent:       #34e07b;
    --accent-soft:  rgba(52, 224, 123, .18);
    --topbar-glow:  rgba(37, 211, 102, .12);
}

/* ---------- Base ---------- */
* { -webkit-font-smoothing: antialiased; }

body {
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background:
        radial-gradient(1100px 520px at 100% -8%, var(--topbar-glow), transparent 60%),
        var(--bg);
    color: var(--text);
    letter-spacing: .1px;
}

h1, h2, h3, h4, h5, h6 { color: var(--text); letter-spacing: -.2px; }
.text-muted { color: var(--text-muted) !important; }
a { text-decoration: none; }

/* ===============================================================
   SIDEBAR
   =============================================================== */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-grad);
    position: fixed;
    top: 0; left: 0;
    z-index: 1040;
    box-shadow: 4px 0 30px rgba(8, 11, 22, .18);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}

.sidebar .brand {
    padding: 1.4rem 1.4rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    display: flex;
    align-items: center;
    gap: .7rem;
}
.sidebar .brand .brand-logo {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: grid; place-items: center;
    background: linear-gradient(140deg, var(--brand), var(--brand-dark));
    color: #fff;
    font-size: 1.25rem;
    box-shadow: 0 6px 16px rgba(37, 211, 102, .35);
    flex-shrink: 0;
}
.sidebar .brand .brand-text { line-height: 1.1; min-width: 0; }
.sidebar .brand span {
    color: #fff; font-weight: 700; font-size: 1.02rem;
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar .brand small {
    color: rgba(255, 255, 255, .42);
    font-size: .68rem; display: block; letter-spacing: .4px;
    text-transform: uppercase; margin-top: 2px;
}

.sidebar .nav { padding: .85rem .65rem 0; gap: 2px; }
.sidebar .nav-link {
    color: rgba(255, 255, 255, .66);
    padding: .62rem .8rem;
    border-radius: 11px;
    font-size: .9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    position: relative;
    transition: background .15s, color .15s, transform .12s;
}
.sidebar .nav-link .bi {
    width: 22px; display: inline-block;
    font-size: 1.05rem; margin-right: .35rem;
    opacity: .85;
}
.sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, .07);
}
.sidebar .nav-link.active {
    color: #fff;
    background: var(--accent-soft);
}
.sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: -.65rem; top: 50%;
    transform: translateY(-50%);
    width: 4px; height: 22px;
    border-radius: 0 4px 4px 0;
    background: var(--accent);
}
.sidebar .nav-link.active .bi { opacity: 1; }

.sidebar .sidebar-foot {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, .07);
}
.sidebar .sidebar-foot .user-row {
    display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem;
}
.sidebar .sidebar-foot .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(140deg, var(--brand), var(--brand-dark));
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: .8rem; flex-shrink: 0;
}
.sidebar .sidebar-foot .user-email {
    color: rgba(255, 255, 255, .62);
    font-size: .75rem; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar .btn-logout {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, .16);
    color: rgba(255, 255, 255, .8);
    background: rgba(255, 255, 255, .04);
    border-radius: 10px;
    font-size: .82rem; font-weight: 500;
    padding: .45rem;
    transition: background .15s, border-color .15s, color .15s;
}
.sidebar .btn-logout:hover {
    background: rgba(255, 255, 255, .1);
    border-color: rgba(255, 255, 255, .28);
    color: #fff;
}

/* ===============================================================
   LAYOUT SHELL
   =============================================================== */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    transition: margin .28s cubic-bezier(.4, 0, .2, 1);
}

.topbar {
    background: rgba(255, 255, 255, .78);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
    padding: .85rem 1.6rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.topbar h6 {
    font-size: 1.18rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -.3px;
}
.topbar .sidebar-toggle {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    width: 40px; height: 40px;
    border-radius: 10px;
    display: none;
    align-items: center; justify-content: center;
    font-size: 1.2rem;
}

.content-area { padding: 1.75rem 1.6rem; }

/* Sidebar mobile overlay */
.sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(10, 14, 24, .5);
    backdrop-filter: blur(2px);
    z-index: 1035;
    opacity: 0; visibility: hidden;
    transition: opacity .25s;
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

/* ===============================================================
   CARDS
   =============================================================== */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.card .card-body { padding: 1.4rem 1.5rem; }

.stat-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    position: relative;
    overflow: hidden;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: #dbe0ea;
}
.stat-card .card-body { padding: 1.3rem 1.4rem; }

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.45rem;
    flex-shrink: 0;
}
/* Make Bootstrap's bg-opacity icon tiles richer */
.stat-icon.bg-success   { background: linear-gradient(140deg, #d8f8e5, #b6f0cd) !important; color: #129a48 !important; }
.stat-icon.bg-primary   { background: linear-gradient(140deg, #dde7ff, #c4d6ff) !important; color: #2f6bff !important; }
.stat-icon.bg-warning   { background: linear-gradient(140deg, #fff1d6, #ffe2ad) !important; color: #d18700 !important; }
.stat-icon.bg-info      { background: linear-gradient(140deg, #d7f3fb, #b6e9f7) !important; color: #0a93b8 !important; }
.stat-icon.bg-danger    { background: linear-gradient(140deg, #ffe1e1, #ffc9c9) !important; color: #e23b3b !important; }
.stat-icon.bg-secondary { background: linear-gradient(140deg, #eceef3, #dde1ea) !important; color: #5a6473 !important; }

.card h6.fw-semibold,
.card .card-title { font-weight: 700; letter-spacing: -.2px; }

/* ===============================================================
   BUTTONS
   =============================================================== */
.btn {
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: .1px;
    padding: .5rem 1rem;
    transition: transform .12s ease, box-shadow .15s ease, background .15s, border-color .15s, color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: .38rem .75rem; border-radius: 9px; font-size: .82rem; }
.btn-lg { padding: .7rem 1.3rem; border-radius: 12px; }

.btn-success {
    background: linear-gradient(140deg, var(--brand), var(--brand-dark));
    border: none;
    color: #fff;
    box-shadow: 0 6px 16px rgba(37, 211, 102, .28);
}
.btn-success:hover {
    background: linear-gradient(140deg, #2bdc70, var(--brand-dark));
    box-shadow: 0 10px 22px rgba(37, 211, 102, .34);
    color: #fff;
}
.btn-primary {
    background: linear-gradient(140deg, #4f7cff, #2f6bff);
    border: none;
    box-shadow: 0 6px 16px rgba(47, 107, 255, .26);
}
.btn-primary:hover { background: linear-gradient(140deg, #5b86ff, #2f6bff); box-shadow: 0 10px 22px rgba(47, 107, 255, .32); }

.btn-outline-secondary {
    border-color: var(--border);
    color: var(--text-muted);
    background: var(--surface);
}
.btn-outline-secondary:hover {
    background: var(--surface-2);
    border-color: #d3d9e3;
    color: var(--text);
}
.btn-outline-success {
    border-color: var(--brand);
    color: var(--brand-dark);
}
.btn-outline-success:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

.btn-light { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-light:hover { background: #eaeef4; }

/* ===============================================================
   TABLES
   =============================================================== */
.table { margin-bottom: 0; color: var(--text); }
.table > :not(caption) > * > * { padding: .85rem 1rem; }
.table thead th,
.table > thead.table-light th {
    background: transparent;
    color: var(--text-faint);
    text-transform: uppercase;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .6px;
    border-bottom: 1px solid var(--border);
}
.table tbody td {
    border-top: 1px solid var(--border-soft);
    border-bottom: none;
    vertical-align: middle;
}
.table tbody tr:first-child td { border-top: none; }
.table-hover tbody tr { transition: background .12s; }
.table-hover tbody tr:hover { background: var(--surface-2); }

/* ===============================================================
   BADGES
   =============================================================== */
.badge {
    font-weight: 600;
    padding: .4em .7em;
    border-radius: var(--radius-pill);
    letter-spacing: .2px;
    font-size: .72rem;
}
.badge.bg-success   { background: var(--brand-soft) !important; color: #0f8c41 !important; }
.badge.bg-primary   { background: rgba(47, 107, 255, .14) !important; color: #2f6bff !important; }
.badge.bg-warning   { background: rgba(209, 135, 0, .16) !important; color: #b87400 !important; }
.badge.bg-danger    { background: rgba(226, 59, 59, .14) !important; color: #d8302f !important; }
.badge.bg-info      { background: rgba(10, 147, 184, .14) !important; color: #0a8eb0 !important; }
.badge.bg-secondary { background: rgba(90, 100, 115, .14) !important; color: #5a6473 !important; }

/* Plan helpers (kept from original) */
.badge-starter  { background: #6c757d; }
.badge-smart    { background: #0d6efd; }
.badge-pro      { background: #6f42c1; }
.plan-starter   { color: #6c757d; }
.plan-smart     { color: #0d6efd; }
.plan-pro       { color: #6f42c1; }

/* ===============================================================
   FORMS
   =============================================================== */
.form-label { font-weight: 600; font-size: .85rem; color: var(--text); margin-bottom: .4rem; }
.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .58rem .8rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
}
.form-control-sm, .form-select-sm { border-radius: 9px; padding: .4rem .65rem; }
.input-group-text { border-radius: 10px; border-color: var(--border); background: var(--surface-2); color: var(--text-muted); }

/* ===============================================================
   PROGRESS
   =============================================================== */
.progress {
    background: var(--surface-2);
    border-radius: var(--radius-pill);
    overflow: hidden;
}
.progress-bar { border-radius: var(--radius-pill); }
.progress-bar.bg-success { background: linear-gradient(90deg, var(--brand), var(--brand-dark)) !important; }

/* ===============================================================
   ALERTS
   =============================================================== */
.alert {
    border: 1px solid transparent;
    border-radius: 12px;
    font-size: .9rem;
    box-shadow: var(--shadow-sm);
}
.alert-success { background: #e9faf0; border-color: #bdedcf; color: #0f7a3c; }
.alert-danger  { background: #fdeeee; border-color: #f6cccc; color: #c22f2f; }

/* ===============================================================
   LIST GROUP / DEFINITION LISTS
   =============================================================== */
.list-group-item { border-color: var(--border-soft); }
dl.row dt { color: var(--text-muted); font-weight: 600; }

/* ===============================================================
   RESPONSIVE
   =============================================================== */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar .sidebar-toggle { display: inline-flex; }
    .content-area { padding: 1.25rem 1rem; }
}

/* ===============================================================
   LOGIN
   =============================================================== */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}
.auth-body::before,
.auth-body::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    filter: blur(8px);
    opacity: .5;
    pointer-events: none;
}
.auth-body::before { width: 480px; height: 480px; top: -180px; right: -120px; background: radial-gradient(circle, rgba(37,211,102,.5), transparent 70%); }
.auth-body::after  { width: 420px; height: 420px; bottom: -160px; left: -120px; background: radial-gradient(circle, rgba(255,255,255,.16), transparent 70%); }

.auth-card {
    width: 100%;
    max-width: 412px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 22px;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 30px 70px rgba(0, 0, 0, .4);
    padding: 2.4rem 2.2rem;
    position: relative;
    z-index: 2;
    animation: auth-rise .5s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes auth-rise {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
.auth-logo {
    width: 62px; height: 62px;
    border-radius: 18px;
    display: grid; place-items: center;
    margin: 0 auto;
    background: linear-gradient(140deg, var(--brand), var(--brand-dark));
    color: #fff; font-size: 1.9rem;
    box-shadow: 0 12px 28px rgba(37, 211, 102, .4);
}
.auth-title { font-weight: 800; font-size: 1.35rem; margin-top: 1rem; letter-spacing: -.4px; }
.auth-sub   { color: var(--text-muted); font-size: .88rem; }
.auth-card .btn-success { padding: .68rem; font-size: .98rem; border-radius: 12px; }
.auth-foot { text-align: center; margin-top: 1.5rem; color: var(--text-faint); font-size: .76rem; }
