/* ============================================================
   saas-azimstech — admin.css
   Modern light-default SaaS theme. Dark is a secondary toggle.
   Theming via CSS custom properties on <html data-theme data-color
   data-layout>. Color presets override --primary*. Mobile responsive.
   ============================================================ */

/* ---- Palette: light (default) ---- */
:root {
  --primary:        #6366f1;
  --primary-hover:  #4f46e5;
  --primary-soft:   #eef2ff;
  --primary-contrast:#ffffff;

  --bg:        #f4f5fb;
  --bg-grad-1: #f7f8fe;
  --bg-grad-2: #eef0fa;
  --surface:   #ffffff;
  --surface-2: #f9fafb;
  --sidebar:   #ffffff;

  --text:      #1a1f36;
  --text-muted:#6b7280;
  --text-soft: #9aa1ad;
  --border:    #e6e8ef;
  --border-strong:#d6d9e2;

  --success:#10b981; --success-soft:#ecfdf5;
  --warning:#f59e0b; --warning-soft:#fffbeb;
  --danger: #ef4444; --danger-soft:#fef2f2;
  --info:   #3b82f6; --info-soft:#eff6ff;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow:    0 4px 16px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.12);
  --radius:    12px;
  --radius-sm: 8px;
  --sidebar-w: 250px;
  --topbar-h:  64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Palette: dark (secondary) ---- */
:root[data-theme="dark"] {
  --primary-soft:   #23253a;
  --primary-contrast:#ffffff;

  --bg:        #0e1220;
  --bg-grad-1: #111627;
  --bg-grad-2: #0c101c;
  --surface:   #171c2e;
  --surface-2: #1e2438;
  --sidebar:   #141928;

  --text:      #e7ebf3;
  --text-muted:#9aa3b8;
  --text-soft: #6b7488;
  --border:    #262c40;
  --border-strong:#333a52;

  --success-soft:#0e2a20; --warning-soft:#2a220e;
  --danger-soft:#2a1414;  --info-soft:#111f36;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow:    0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

/* ---- Color presets (override accent) ---- */
:root[data-color="violet"]  { --primary:#8b5cf6; --primary-hover:#7c3aed; --primary-soft:#f3effe; }
:root[data-color="blue"]    { --primary:#3b82f6; --primary-hover:#2563eb; --primary-soft:#eff6ff; }
:root[data-color="emerald"] { --primary:#10b981; --primary-hover:#059669; --primary-soft:#ecfdf5; }
:root[data-color="rose"]    { --primary:#f43f5e; --primary-hover:#e11d48; --primary-soft:#fff1f3; }
:root[data-color="amber"]   { --primary:#f59e0b; --primary-hover:#d97706; --primary-soft:#fffbeb; }
:root[data-theme="dark"][data-color="violet"]  { --primary-soft:#241f38; }
:root[data-theme="dark"][data-color="blue"]    { --primary-soft:#122036; }
:root[data-theme="dark"][data-color="emerald"] { --primary-soft:#0e2a20; }
:root[data-theme="dark"][data-color="rose"]    { --primary-soft:#2a1420; }
:root[data-theme="dark"][data-color="amber"]   { --primary-soft:#2a220e; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
  min-height: 100vh;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Global icon sizing — SVGs default to a huge intrinsic size without this */
.ico { width: 18px; height: 18px; flex: none; }

/* AI "thinking / writing" indicator */
.ai-thinking { display:inline-flex; align-items:center; gap:.5rem; color:var(--primary); font-weight:600; font-size:.88rem; }
.ai-thinking .dots { display:inline-flex; gap:3px; }
.ai-thinking .dots span { width:6px; height:6px; border-radius:50%; background:var(--primary); animation:aiblink 1.2s infinite both; }
.ai-thinking .dots span:nth-child(2){ animation-delay:.2s; }
.ai-thinking .dots span:nth-child(3){ animation-delay:.4s; }
@keyframes aiblink { 0%,80%,100%{ opacity:.25; transform:scale(.8);} 40%{ opacity:1; transform:scale(1);} }
@keyframes airow { from{ opacity:0; transform:translateY(6px);} to{ opacity:1; transform:none;} }
.airow-in { animation:airow .25s ease both; }

/* Impersonation banner */
.impersonate-bar {
  background: var(--warning); color: #3a2a00; padding: .5rem 1rem;
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  font-size: .85rem; font-weight: 600; flex-wrap: wrap;
}
.impersonate-bar a { color: #3a2a00; text-decoration: underline; font-weight: 700; }

/* ============================================================
   App shell — sidebar layout (default)
   ============================================================ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 40;
}
.sidebar__brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.15rem 1.25rem; font-weight: 700; font-size: 1.1rem;
  color: var(--text); border-bottom: 1px solid var(--border);
}
.sidebar__brand .logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  display: grid; place-items: center; color: #fff; font-weight: 800; flex: none;
}
.brandlogo { max-height: 34px; max-width: 170px; width: auto; object-fit: contain; display: block; }
.brand-inline .brandlogo { max-height: 30px; max-width: 150px; }
.sidebar__scope {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-soft); padding: 1rem 1.35rem .4rem;
}
.nav { list-style: none; margin: 0; padding: .25rem .6rem; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .75rem; margin: .1rem 0; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; transition: background .15s, color .15s;
}
.nav a .ico { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav a.active .ico { opacity: 1; }
.nav a .badge {
  margin-left: auto; background: var(--success); color: #fff;
  font-size: .68rem; font-weight: 700; padding: .1rem .4rem; border-radius: 999px;
}
/* Live count pills in the nav (Support open tickets, Live Visitors online, …) */
.navcount {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: auto;
  border-radius: 9px; background: var(--primary); color: #fff;
  font-size: .66rem; font-weight: 700; line-height: 1; flex: 0 0 auto;
}
.navgroup__top .navcount { margin-left: .35rem; margin-right: .3rem; }
.nav-inline .navcount { margin-left: .35rem; min-width: 16px; height: 16px; }

/* Rich-text body (ticket replies, and any user-written rich body) — theme-aware,
   so pasted content never blends (background is stripped server-side). */
.tkbody { word-break: break-word; }
.tkbody p { margin: 0 0 .5rem; }
.tkbody p:last-child { margin-bottom: 0; }
.tkbody a { color: var(--primary); text-decoration: underline; }
.tkbody ul, .tkbody ol { margin: .3rem 0 .6rem 1.4rem; }
.tkbody blockquote {
  margin: .5rem 0; padding: .4rem .9rem; border-left: 3px solid var(--border);
  color: var(--text-muted); background: var(--surface-2); border-radius: 4px;
}
.tkbody code {
  background: var(--surface-2); padding: .1rem .35rem; border-radius: 4px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em;
}
.tkbody pre, .tkbody .ql-syntax {
  background: var(--surface-2); color: var(--text); padding: .7rem .9rem;
  border-radius: 6px; overflow-x: auto; margin: .5rem 0;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .86rem;
  white-space: pre; border: 1px solid var(--border);
}
.tkbody img { max-width: 100%; height: auto; border-radius: 6px; }
.tkbody table { border-collapse: collapse; margin: .5rem 0; max-width: 100%; }
.tkbody td, .tkbody th { border: 1px solid var(--border); padding: .35rem .6rem; }
.tkbody .ql-align-center { text-align: center; }
.tkbody .ql-align-right { text-align: right; }
.tkbody .ql-align-justify { text-align: justify; }
/* Collapsible nav groups (per-product suites) */
.navgroup { list-style: none; }
.navgroup__top {
  display: flex; align-items: center; gap: .7rem; width: 100%;
  padding: .6rem .75rem; margin: .1rem 0; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; background: none; border: none;
  cursor: pointer; font: inherit; text-align: left; transition: background .15s, color .15s;
}
.navgroup__top .ico { width: 18px; height: 18px; flex: none; opacity: .85; }
.navgroup__top > span { flex: 1; }
.navgroup__top:hover { background: var(--surface-2); color: var(--text); }
.navgroup__top.active { color: var(--text); font-weight: 600; }
.navgroup__caret { flex: none; transition: transform .18s; opacity: .6; }
.navgroup.open > .navgroup__top .navgroup__caret { transform: rotate(180deg); }
.navgroup__sub { list-style: none; margin: 0; padding: 0; max-height: 0; overflow: hidden; transition: max-height .22s ease; }
.navgroup.open > .navgroup__sub { max-height: 420px; }
.navgroup__sub a { padding: .45rem .75rem .45rem 2.4rem; margin: .05rem 0; font-size: .92rem; }

.sidebar__foot { padding: .8rem 1rem; border-top: 1px solid var(--border); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.4rem; position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-weight: 650; font-size: 1.05rem; }
.topbar__spacer { flex: 1; }
.hamburger { display: none; background: none; border: 0; cursor: pointer; color: var(--text); padding: .3rem; }

.iconbtn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  display: grid; place-items: center; transition: .15s;
}
.iconbtn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.usermenu { position: relative; }
.usermenu__btn { display: flex; align-items: center; gap: .55rem; background: none; border: 0; cursor: pointer; color: var(--text); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: .85rem;
}
.usermenu__name { font-weight: 600; font-size: .85rem; line-height: 1.1; }
.usermenu__role { font-size: .72rem; color: var(--text-soft); }
.dropdown {
  position: absolute; right: 0; top: calc(100% + .5rem); min-width: 210px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .4rem; display: none; z-index: 50;
}
.dropdown.open { display: block; }
.dropdown a, .dropdown button {
  display: flex; width: 100%; align-items: center; gap: .6rem; text-align: left;
  padding: .55rem .7rem; border-radius: var(--radius-sm); color: var(--text);
  background: none; border: 0; cursor: pointer; font: inherit;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: .35rem 0; }
.dropdown .seg { display: flex; gap: .3rem; padding: .3rem .4rem; }
.dropdown .seg button {
  flex: 1; justify-content: center; border: 1px solid var(--border); font-size: .78rem; padding: .35rem;
}
.dropdown .seg button.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.swatches { display: flex; gap: .4rem; padding: .4rem; flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }

/* Notifications bell */
.notifmenu { position: relative; }
.notifbell { position: relative; }
.notifbadge {
  position: absolute; top: -5px; right: -5px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 9px; background: var(--danger, #ef4444); color: #fff; font-size: .64rem;
  font-weight: 700; line-height: 16px; text-align: center; box-shadow: 0 0 0 2px var(--surface);
}
.dropdown.notifdd { min-width: 320px; max-width: 92vw; padding: 0; max-height: 460px; overflow-y: auto; }
.notifitem { display: block !important; padding: .6rem .8rem !important; border-bottom: 1px solid var(--border);
  border-radius: 0 !important; text-decoration: none; }
.notifitem:hover { background: var(--surface-2); }
.notifitem.unread { background: var(--primary-soft); }
.notifitem.unread:hover { filter: brightness(.98); }
.notifitem__title { font-size: .84rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.notifitem__body  { font-size: .78rem; color: var(--text-soft); margin-top: .15rem; line-height: 1.35; }
.notifitem__time  { font-size: .7rem; color: var(--text-soft); margin-top: .25rem; }
.swatch.on { border-color: var(--text); }

.page { padding: 1.6rem; max-width: 1400px; width: 100%; }
.page__head { margin-bottom: 1.3rem; }
.page__head h1 { margin: 0 0 .2rem; font-size: 1.5rem; font-weight: 700; }
.page__head p { margin: 0; color: var(--text-muted); }

/* ---- Cards / grid ---- */
.grid { display: grid; gap: 1.1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1.1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.2rem;
}
.card:hover { box-shadow: var(--shadow); }
.card__label { color: var(--text-muted); font-size: .82rem; font-weight: 500; }
.card__value { font-size: 1.9rem; font-weight: 750; margin: .3rem 0 .1rem; letter-spacing: -.02em; }
.card__delta { font-size: .78rem; font-weight: 600; }
.card__delta.up { color: var(--success); }
.card__delta.down { color: var(--danger); }
.card__icon {
  width: 44px; height: 44px; border-radius: 12px; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; margin-bottom: .8rem;
}
.card__icon .ico { width: 22px; height: 22px; }

/* ---- Draggable / reorderable widget affordance ---- */
.widget { position: relative; }
.widget__grip {
  position: absolute; top: .6rem; right: .6rem; cursor: grab; color: var(--text-soft);
  opacity: 0; transition: opacity .15s;
}
.widget:hover .widget__grip { opacity: 1; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
  padding: .6rem 1.05rem; border-radius: var(--radius-sm); font-weight: 600; font-size: .88rem;
  border: 1px solid transparent; transition: .15s; line-height: 1;
}
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .4rem .7rem; font-size: .8rem; }

/* ---- Forms ---- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: .35rem; }
.input, select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font: inherit; transition: border .15s, box-shadow .15s;
}
.input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.data td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }

/* ---- Badges / status pills ---- */
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.pill.active    { background: var(--success-soft); color: var(--success); }
.pill.pending   { background: var(--warning-soft); color: var(--warning); }
.pill.suspended { background: var(--danger-soft);  color: var(--danger); }
.pill.cancelled { background: var(--surface-2);    color: var(--text-muted); }
.pill::before { content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }

/* ---- Alerts ---- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .88rem; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info    { background: var(--info-soft);    color: var(--info); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }

/* ============================================================
   Auth pages (login / forgot / reset)
   ============================================================ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth__card {
  width: 100%; max-width: 410px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 2.2rem 2rem;
}
.auth__brand { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1.4rem; font-weight: 700; font-size: 1.25rem; }
.auth__brand .logo { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), var(--primary-hover)); color: #fff; display: grid; place-items: center; font-weight: 800; }
.auth h1 { text-align: center; font-size: 1.25rem; margin: 0 0 .3rem; }
.auth p.sub { text-align: center; color: var(--text-muted); margin: 0 0 1.5rem; font-size: .9rem; }
.auth .btn-primary { width: 100%; justify-content: center; padding: .7rem; }
.auth__foot { text-align: center; margin-top: 1.2rem; font-size: .85rem; color: var(--text-muted); }

/* ---- Sidebar footer sign-out link ---- */
.sidebar__foot .nav-link {
  display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem;
  border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500;
}
.sidebar__foot .nav-link:hover { background: var(--surface-2); color: var(--text); }

/* ---- App footer ---- */
.appfoot {
  margin-top: auto; padding: 1rem 1.6rem; text-align: center;
  color: var(--text-soft); font-size: .82rem; border-top: 1px solid var(--border);
}
.appfoot a { font-weight: 600; }

/* ---- Inline (top-bar) brand + nav — hidden in sidebar mode ---- */
.brand-inline, .nav-inline { display: none; }
.nav-inline a {
  display: flex; align-items: center; gap: .45rem; padding: .5rem .7rem;
  border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; white-space: nowrap;
}
.nav-inline a:hover { background: var(--surface-2); color: var(--text); }
.nav-inline a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ============================================================
   Layout variant: top menu bar (data-layout="topbar")
   One clean bar: brand + horizontal nav + spacer + theme + user.
   ============================================================ */
:root[data-layout="topbar"] .app { grid-template-columns: 1fr; }
:root[data-layout="topbar"] .sidebar { display: none; }
:root[data-layout="topbar"] .topbar__title { display: none; }
:root[data-layout="topbar"] .brand-inline {
  display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem;
  padding-right: 1rem; margin-right: .3rem; border-right: 1px solid var(--border); white-space: nowrap;
}
:root[data-layout="topbar"] .nav-inline {
  display: flex; gap: .15rem; align-items: center; overflow-x: auto; flex: 1; min-width: 0;
}

/* ============================================================
   Mobile (<=768px) — sidebar becomes a slide-in drawer
   ============================================================ */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  /* On mobile, ALWAYS use the slide-in drawer regardless of layout pref */
  .sidebar,
  :root[data-layout="topbar"] .sidebar {
    display: flex; flex-direction: column; align-items: stretch;
    position: fixed; left: 0; top: 0; width: 264px; height: 100vh;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open,
  :root[data-layout="topbar"] .sidebar.open { transform: translateX(0); }
  /* Hide the inline top-bar nav/brand on mobile — the drawer handles nav */
  .brand-inline, .nav-inline,
  :root[data-layout="topbar"] .brand-inline,
  :root[data-layout="topbar"] .nav-inline { display: none; }
  :root[data-layout="topbar"] .topbar__title { display: block; }
  .hamburger { display: grid; place-items: center; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; display: none; }
  .scrim.open { display: block; }
  .page { padding: 1rem; }
  .card__value { font-size: 1.6rem; }
  .appfoot { padding: 1rem; }
}
