/* DMBud design system — single source of visual truth for every page. */

:root{
  --bg:#f5f6fa;
  --surface:#ffffff;
  --surface-alt:#fafbfd;
  --border:#e5e8f0;
  --border-strong:#d7dbe6;
  --text:#171b26;
  --text-muted:#6b7280;
  --text-faint:#9aa1b0;
  --accent:#5b6cf9;
  --accent-hover:#4a5aef;
  --accent-soft:#eef0ff;
  --accent-text:#4451e0;
  --ok:#1fa971;
  --ok-soft:#e6f7ef;
  --warn:#b9770e;
  --warn-soft:#fdf3e0;
  --danger:#dc3545;
  --danger-soft:#fdecee;
  --radius-sm:8px;
  --radius:12px;
  --radius-lg:16px;
  --shadow-sm:0 1px 2px rgba(16,20,40,.06);
  --shadow:0 6px 20px rgba(16,20,40,.08);
  --shadow-lg:0 16px 40px rgba(16,20,40,.14);
  --sidebar-w:252px;
  --header-h:64px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family:var(--font);
  background:var(--bg);
  color:var(--text);
  font-size:14px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
img{ max-width:100%; display:block; }
a{ color:var(--accent-text); text-decoration:none; }
a:hover{ text-decoration:underline; }
h1,h2,h3,h4{ margin:0; font-weight:650; letter-spacing:-.01em; }
p{ margin:0; }
button{ font-family:inherit; }
svg{ width:1em; height:1em; }

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

.sidebar{
  position:fixed; top:0; left:0; bottom:0; width:var(--sidebar-w);
  background:var(--surface); border-right:1px solid var(--border);
  display:flex; flex-direction:column; z-index:40;
  transition:transform .22s ease;
}
.sidebar-brand{
  height:var(--header-h); display:flex; align-items:center; gap:10px;
  padding:0 20px; border-bottom:1px solid var(--border); flex-shrink:0;
}
.sidebar-brand svg{ width:30px; height:30px; }
.sidebar-brand span{ font-weight:700; font-size:16px; }
.sidebar-nav{ flex:1; overflow-y:auto; padding:14px 12px; }
.nav-section-label{
  font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--text-faint);
  padding:14px 10px 6px;
}
.nav-item{
  display:flex; align-items:center; gap:11px; padding:10px 12px; border-radius:var(--radius-sm);
  color:var(--text-muted); font-weight:560; font-size:13.5px; cursor:pointer; margin-bottom:2px;
  min-height:44px;
}
.nav-item svg{ width:18px; height:18px; flex-shrink:0; }
.nav-item:hover{ background:var(--surface-alt); color:var(--text); text-decoration:none; }
.nav-item.active{ background:var(--accent-soft); color:var(--accent-text); }
.sidebar-foot{ padding:14px 12px; border-top:1px solid var(--border); }

.sidebar-overlay{
  position:fixed; inset:0; background:rgba(15,18,30,.45); z-index:35; opacity:0;
  pointer-events:none; transition:opacity .2s ease;
}
.sidebar-overlay.open{ opacity:1; pointer-events:auto; }

.main{ flex:1; margin-left:var(--sidebar-w); display:flex; flex-direction:column; min-width:0; }

.topbar{
  height:var(--header-h); position:sticky; top:0; z-index:30;
  background:var(--surface); border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:14px; padding:0 24px;
}
.icon-btn.topbar-hamburger{ display:none; }
.topbar-title{ font-size:17px; font-weight:650; flex-shrink:0; }
.topbar-spacer{ flex:1; }
.plan-badge{
  display:inline-flex; align-items:center; gap:6px; padding:5px 11px; border-radius:999px;
  background:var(--accent-soft); color:var(--accent-text); font-size:12.5px; font-weight:600;
}
.icon-btn{
  width:38px; height:38px; border-radius:var(--radius-sm); border:1px solid var(--border);
  background:var(--surface); display:flex; align-items:center; justify-content:center;
  color:var(--text-muted); cursor:pointer;
}
.icon-btn:hover{ background:var(--surface-alt); color:var(--text); }
.icon-btn svg{ width:18px; height:18px; }

.user-menu{ position:relative; }
.user-chip{
  display:flex; align-items:center; gap:9px; padding:6px 10px 6px 6px; border-radius:999px;
  border:1px solid var(--border); background:var(--surface); cursor:pointer;
}
.user-avatar{
  width:28px; height:28px; border-radius:50%; background:var(--accent); color:#fff;
  display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:700; flex-shrink:0;
}
.user-chip span.name{ font-weight:600; font-size:13px; max-width:130px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.dropdown{
  position:absolute; right:0; top:calc(100% + 8px); background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); box-shadow:var(--shadow-lg); min-width:200px; padding:6px; display:none; z-index:50;
}
.dropdown.open{ display:block; }
.dropdown-item{
  display:flex; align-items:center; gap:10px; padding:9px 10px; border-radius:var(--radius-sm);
  font-size:13.5px; color:var(--text); cursor:pointer;
}
.dropdown-item:hover{ background:var(--surface-alt); text-decoration:none; }
.dropdown-item svg{ width:16px; height:16px; color:var(--text-muted); }
.dropdown-sep{ height:1px; background:var(--border); margin:6px 4px; }

.content{ padding:26px 28px 60px; max-width:1320px; width:100%; margin:0 auto; }

/* ---------- Primitives ---------- */
.card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:20px; }
.card-title{ font-size:15px; font-weight:650; margin-bottom:4px; }
.card-sub{ color:var(--text-muted); font-size:13px; }

.grid{ display:grid; gap:18px; }
.grid-2{ grid-template-columns:repeat(2,1fr); }
.grid-3{ grid-template-columns:repeat(3,1fr); }
.grid-4{ grid-template-columns:repeat(4,1fr); }

/* Connection card (Instagram/Shopify/WooCommerce) — used on connections.html,
   dashboard.html's mini connection cards, and admin-connections.html. */
.conn-card{ display:flex; align-items:flex-start; gap:16px; }
.conn-icon{ width:46px; height:46px; border-radius:12px; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.conn-icon.instagram{ background:linear-gradient(135deg,#f9ce34,#ee2a7b 45%,#6228d7); color:#fff; }
.conn-icon.shopify{ background:#95c675; color:#fff; }
.conn-icon.woocommerce{ background:#7f54b3; color:#fff; }
.conn-icon svg{ width:24px; height:24px; }

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:10px 16px; border-radius:var(--radius-sm); border:1px solid transparent;
  font-weight:600; font-size:13.5px; cursor:pointer; min-height:40px; white-space:nowrap;
}
.btn svg{ width:16px; height:16px; }
.btn-primary{ background:var(--accent); color:#fff; }
.btn-primary:hover{ background:var(--accent-hover); }
.btn-secondary{ background:var(--surface); color:var(--text); border-color:var(--border-strong); }
.btn-secondary:hover{ background:var(--surface-alt); }
.btn-danger{ background:var(--danger-soft); color:var(--danger); }
.btn-danger:hover{ background:#fbd7dc; }
.btn-ghost{ background:transparent; color:var(--text-muted); }
.btn-ghost:hover{ background:var(--surface-alt); color:var(--text); }
.btn-sm{ padding:7px 12px; min-height:32px; font-size:12.5px; }
.btn:disabled{ opacity:.55; cursor:not-allowed; }

.badge{ display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:999px; font-size:11.5px; font-weight:650; }
.badge-ok{ background:var(--ok-soft); color:var(--ok); }
.badge-warn{ background:var(--warn-soft); color:var(--warn); }
.badge-danger{ background:var(--danger-soft); color:var(--danger); }
.badge-neutral{ background:var(--surface-alt); color:var(--text-muted); border:1px solid var(--border); }

.field{ margin-bottom:16px; }
.field label{ display:block; font-size:12.5px; font-weight:600; color:var(--text-muted); margin-bottom:6px; }
.field .hint{ font-size:11.5px; color:var(--text-faint); margin-top:5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea{
  width:100%; padding:10px 12px; border-radius:var(--radius-sm); border:1px solid var(--border-strong);
  background:var(--surface); color:var(--text); font-size:13.5px; font-family:inherit;
}
textarea{ resize:vertical; min-height:80px; }
input:focus, select:focus, textarea:focus{ outline:2px solid var(--accent); outline-offset:1px; border-color:var(--accent); }

.switch{ position:relative; display:inline-block; width:40px; height:23px; flex-shrink:0; }
.switch input{ opacity:0; width:0; height:0; }
.switch .track{ position:absolute; inset:0; background:var(--border-strong); border-radius:999px; transition:.15s; cursor:pointer; }
.switch .track::before{ content:""; position:absolute; width:17px; height:17px; left:3px; top:3px; background:#fff; border-radius:50%; transition:.15s; box-shadow:0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track{ background:var(--accent); }
.switch input:checked + .track::before{ transform:translateX(17px); }

/* A label + description + switch row — used for any on/off setting (fallback
   toggles, plan visibility, etc). Not specific to any one feature. */
.toggle-row{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:16px; padding:12px 14px; background:var(--surface-alt); border-radius:var(--radius-sm); }
.toggle-row .label{ font-size:13px; font-weight:600; }
.toggle-row .hint{ font-size:11.5px; color:var(--text-muted); }

/* Any direct container of a <table> becomes a horizontal scroller instead of
   letting a wide table blow out the page's layout viewport on small screens. */
*:has(> table){ overflow-x:auto; -webkit-overflow-scrolling:touch; }
table{ width:100%; min-width:520px; border-collapse:collapse; }
th{ text-align:left; font-size:11.5px; text-transform:uppercase; letter-spacing:.04em; color:var(--text-faint); padding:10px 14px; border-bottom:1px solid var(--border); }
td{ padding:13px 14px; border-bottom:1px solid var(--border); font-size:13.5px; vertical-align:middle; }
tr:last-child td{ border-bottom:none; }

.empty-state{ text-align:center; padding:56px 24px; color:var(--text-muted); }
.empty-state svg{ width:40px; height:40px; color:var(--text-faint); margin-bottom:14px; }

.modal-backdrop{ position:fixed; inset:0; background:rgba(15,18,30,.5); display:flex; align-items:center; justify-content:center; z-index:80; padding:20px; }
.modal{ background:var(--surface); border-radius:var(--radius-lg); width:100%; max-width:560px; max-height:90vh; overflow-y:auto; box-shadow:var(--shadow-lg); }
.modal-head{ display:flex; align-items:center; justify-content:space-between; padding:18px 22px; border-bottom:1px solid var(--border); }
.modal-body{ padding:22px; }
.modal-foot{ display:flex; justify-content:flex-end; gap:10px; padding:16px 22px; border-top:1px solid var(--border); }

.modal-confirm{ max-width:400px; }
.confirm-title{ font-size:16px; font-weight:700; margin:0 0 8px; }
.confirm-message{ font-size:13.5px; color:var(--text-muted); line-height:1.6; margin:0; }

.toast-stack{ position:fixed; bottom:20px; right:20px; z-index:100; display:flex; flex-direction:column; gap:10px; }
.toast{ background:var(--text); color:#fff; padding:12px 16px; border-radius:var(--radius-sm); font-size:13px; box-shadow:var(--shadow-lg); display:flex; align-items:center; gap:10px; max-width:340px; }
.toast.ok{ background:#16794f; }
.toast.err{ background:#a3222c; }
.toast svg{ width:16px; height:16px; flex-shrink:0; }

.progress{ height:7px; border-radius:999px; background:var(--surface-alt); border:1px solid var(--border); overflow:hidden; }
.progress > span{ display:block; height:100%; background:var(--accent); border-radius:999px; }
.progress.warn > span{ background:var(--warn); }
.progress.danger > span{ background:var(--danger); }

.dm-spin{ animation:dm-spin 0.8s linear infinite; }
@keyframes dm-spin{ to{ transform:rotate(360deg); } }

.tabs{ display:flex; gap:4px; border-bottom:1px solid var(--border); margin-bottom:20px; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.tab{ padding:11px 16px; font-size:13.5px; font-weight:600; color:var(--text-muted); cursor:pointer; border-bottom:2px solid transparent; white-space:nowrap; min-height:44px; display:flex; align-items:center; gap:8px; }
.tab.active{ color:var(--accent-text); border-bottom-color:var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 1023px){
  .sidebar{ transform:translateX(-100%); box-shadow:var(--shadow-lg); }
  .sidebar.open{ transform:translateX(0); }
  .main{ margin-left:0; }
  .icon-btn.topbar-hamburger{ display:flex; }
  .grid-4{ grid-template-columns:repeat(2,1fr); }
  .grid-3{ grid-template-columns:repeat(2,1fr); }
}

@media (max-width: 640px){
  .content{ padding:18px 14px 48px; }
  .topbar{ padding:0 14px; gap:10px; }
  .grid-2, .grid-3, .grid-4{ grid-template-columns:1fr; }
  .user-chip span.name{ display:none; }
  .plan-badge{ display:none; }
  .modal{ max-height:100vh; border-radius:var(--radius-lg) var(--radius-lg) 0 0; align-self:flex-end; }
  .modal-backdrop{ align-items:flex-end; padding:0; }
}
