/* MA Control Hub — Shared Stylesheet */
:root {
  --bg:        #0f0f0f;
  --surface:   #141414;
  --border:    #2a2820;
  --accent:    #c9a84c;
  --gold:      #c9a84c;
  --gold-dim:  #8b6914;
  --accent2:   #4ade80;
  --text:      #f0ece4;
  --muted:     #706860;
  --danger:    #f87171;
  --warn:      #f59e0b;
  --radius:    8px;
  --sidebar-w: 220px;
  --sk-base:   #161410;
  --sk-shine:  #1e1c18;
  /* surface tokens — replaces hardcoded rgba(255,255,255,…) */
  --input-bg:    rgba(255,255,255,0.05);
  --chip-bg:     rgba(255,255,255,0.03);
  --row-hover:   rgba(255,255,255,0.02);
  --row-border:  rgba(255,255,255,0.04);
  --tooltip-bg:  #0a0c14;
}

/* ── Light theme ── */
html[data-theme="light"] {
  --bg:        #f5f3ef;
  --surface:   #ffffff;
  --border:    #dbd6cf;
  --text:      #1a1814;
  --muted:     #706860;
  --sk-base:   #e8e4dc;
  --sk-shine:  #f0ede7;
  --input-bg:    rgba(0,0,0,0.04);
  --chip-bg:     rgba(0,0,0,0.03);
  --row-hover:   rgba(0,0,0,0.025);
  --row-border:  rgba(0,0,0,0.055);
  --tooltip-bg:  #1a1814;
}

/* ── Theme transition ── */
html.hub-theme-transition,
html.hub-theme-transition * {
  transition: background-color 0.18s ease, color 0.12s ease, border-color 0.15s ease !important;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Outfit', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ── */
.hub-layout {
  display: flex;
  min-height: 100vh;
}

.hub-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.hub-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar-logo {
  padding: 18px 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-mark {
  height: 30px;
  width: auto;
  flex-shrink: 0;
}
.sidebar-logo .brand {
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: -0.2px;
  line-height: 1.2;
}
.sidebar-logo .sub {
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
  letter-spacing: 0.3px;
}
.login-logo-mark {
  height: 48px;
  width: auto;
  display: block;
  margin: 0 auto 14px;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
}
.nav-section {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  padding: 12px 8px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  font-size: 13.5px;
  transition: background 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover   { background: rgba(201,168,76,0.08); }
.nav-item.active  { background: rgba(201,168,76,0.14); color: var(--gold); }
.nav-item .icon   { width: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-item .icon svg { display: block; opacity: 0.7; }
.nav-item.active .icon svg,
.nav-item:hover .icon svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--chip-bg);
}
.user-chip .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #111; flex-shrink: 0;
}
.user-chip .info { flex: 1; overflow: hidden; }
.user-chip .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.btn-logout {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 4px; flex-shrink: 0;
  transition: color 0.15s;
}
.btn-logout:hover { color: var(--danger); }

/* ── Topbar ── */
.hub-topbar {
  height: 54px;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ── Content ── */
.hub-content {
  padding: 24px;
  flex: 1;
}

/* ── Stat cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-card .label  { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-card .value  { font-size: 28px; font-weight: 700; }
.stat-card .icon   { font-size: 22px; margin-bottom: 4px; }
.stat-card.c1 .value { color: var(--gold); }
.stat-card.c2 .value { color: var(--accent2); }
.stat-card.c3 .value { color: #60a5fa; }
.stat-card.c4 .value { color: var(--warn); }

/* ── Tables ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 { font-size: 14px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--row-border);
  font-size: 13px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.04em;
}
.badge-active   { background: rgba(74,222,128,0.15); color: var(--accent2); }
.badge-trial    { background: rgba(251,191,36,0.15);  color: var(--warn); }
.badge-suspended{ background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-revoked  { background: rgba(100,116,139,0.15); color: var(--muted); }
.badge-online   { background: rgba(74,222,128,0.15);  color: var(--accent2); }
.badge-offline  { background: rgba(100,116,139,0.15); color: var(--muted); }
.badge-admin    { background: rgba(201,168,76,0.15);  color: var(--gold); }
.badge-reseller { background: rgba(56,189,248,0.15);  color: #38bdf8; }
.badge-support  { background: rgba(251,191,36,0.1);   color: var(--warn); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary  { background: var(--accent); color: #111; }
.btn-primary:hover { background: var(--gold-dim); }
.btn-ghost    { background: none; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--input-bg); }
.btn-danger   { background: none; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(248,113,113,0.1); }
.btn-sm       { padding: 5px 10px; font-size: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.form-control {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--muted); }
select.form-control option { background: var(--surface); }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-error { background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.3); color: var(--danger); }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .brand-name { font-size: 22px; font-weight: 800; color: var(--accent); }
.login-logo .brand-sub  { font-size: 12px; color: var(--muted); margin-top: 3px; }
.login-card h1 { font-size: 18px; font-weight: 600; margin-bottom: 20px; text-align: center; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p     { font-size: 14px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Mobile sidebar ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.55); z-index: 99;
}
.sidebar-overlay.open { display: block; }

.hub-topbar-menu {
  display: none; background: none; border: none;
  color: var(--text); font-size: 22px; cursor: pointer;
  padding: 4px 8px; margin-right: 4px; line-height: 1; flex-shrink: 0;
}

/* ── Responsive — 768px ── */
@media (max-width: 768px) {
  .hub-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .hub-sidebar.open { transform: translateX(0); }
  .hub-main { margin-left: 0; }
  .hub-topbar { padding: 0 16px; }
  .hub-topbar-menu { display: inline-flex; align-items: center; }
  .hub-content { padding: 16px; }

  /* Tables scroll horizontally instead of overflowing */
  .card { overflow: auto; }
  table { min-width: 560px; }

  /* Stats grid collapses to 2 cols */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }
  .stat-card { padding: 14px 16px; }
  .stat-card .value { font-size: 22px; }

  /* Modal: bottom-sheet on mobile */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box {
    max-width: 100%; width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
  }

  /* Prevent iOS auto-zoom on form inputs */
  input.form-control,
  select.form-control,
  textarea.form-control { font-size: 16px; }

  /* Login card — full-width with margin */
  .login-card { padding: 28px 20px; max-width: 100%; margin: 16px; }
}

/* ── Responsive — 480px ── */
@media (max-width: 480px) {
  .hub-content { padding: 12px; }
  .hub-topbar { height: 48px; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .topbar-title { font-size: 14px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card .value { font-size: 20px; }
  .btn-sm { padding: 5px 8px; font-size: 11px; }
  table { min-width: 480px; }
}

/* ═══════════════════════════════════════════════════════════════
   SKELETON LOADERS
   ═══════════════════════════════════════════════════════════════ */
@keyframes sk-wave {
  0%   { background-position: -600px 0; }
  100% { background-position:  600px 0; }
}
.sk {
  background: linear-gradient(90deg,
    var(--sk-base) 25%,
    var(--sk-shine) 50%,
    var(--sk-base) 75%);
  background-size: 1200px 100%;
  animation: sk-wave 1.6s infinite linear;
  border-radius: var(--radius);
  display: block;
  pointer-events: none;
}
/* Sizes */
.sk-row   { height: 46px; margin-bottom: 8px; }
.sk-row-sm{ height: 34px; margin-bottom: 6px; }
.sk-card  { height: 90px; }
.sk-text  { height: 13px; border-radius: 4px; margin-bottom: 6px; }
.sk-circle{ border-radius: 50%; }
/* Width helpers */
.sk.w-100 { width: 100%; }
.sk.w-70  { width: 70%; }
.sk.w-50  { width: 50%; }
.sk.w-30  { width: 30%; }

/* Skeleton table: replaces <tbody> content */
.sk-tbody td { padding: 0; border: none !important; background: transparent !important; }
.sk-tbody td .sk { margin: 6px 8px; }

/* Skeleton stat cards */
.sk-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px,1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.sk-stat { height: 90px; }

/* ═══════════════════════════════════════════════════════════════
   TOOLTIPS  (zero JS — pure CSS via data-tip attribute)
   ═══════════════════════════════════════════════════════════════ */
[data-tip] {
  position: relative;
  cursor: default;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--tooltip-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  white-space: nowrap;
  max-width: 220px;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 9990;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
[data-tip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* Tip pointing down (for items near bottom of screen) */
[data-tip-down]::after {
  bottom: auto;
  top: calc(100% + 7px);
  transform: translateX(-50%) translateY(-4px);
}
[data-tip-down]:hover::after {
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════════════
   OPTIMISTIC UI — flash feedback
   ═══════════════════════════════════════════════════════════════ */
@keyframes opt-pulse {
  0%   { opacity: 1; }
  50%  { opacity: 0.5; }
  100% { opacity: 1; }
}
/* Applied during in-flight update */
.opt-saving {
  animation: opt-pulse 0.8s ease infinite;
  pointer-events: none;
}
/* Rollback flash (red outline, fades) */
@keyframes opt-fail {
  0%   { box-shadow: 0 0 0 2px var(--danger); }
  100% { box-shadow: none; }
}
.opt-failed { animation: opt-fail 0.6s ease forwards; }

/* Last-synced timestamp badge */
.sync-ts {
  font-size: 11px;
  color: var(--muted);
  margin-left: 8px;
  vertical-align: middle;
}
