/* =========================================================================
   Instagram Manager — control panel design system
   Single stylesheet, theme-aware (light/dark), no external deps.
   ========================================================================= */

:root {
  /* Brand accent — an Instagram-adjacent warm gradient, used sparingly. */
  --grad: linear-gradient(135deg, #f9ce34 0%, #ee2a7b 45%, #6228d7 100%);
  --accent: #ee2a7b;
  --accent-soft: rgba(238, 42, 123, 0.12);
  --accent-ring: rgba(238, 42, 123, 0.35);

  /* Status hues */
  --s-planned: #64748b;
  --s-generated: #3b82f6;
  --s-media: #8b5cf6;
  --s-scheduled: #f59e0b;
  --s-publishing: #06b6d4;
  --s-published: #10b981;
  --s-failed: #ef4444;
  --s-rejected: #9ca3af;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, 0.18);
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ---- Light (default) ---- */
:root, :root[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-soft: #f1f3f9;
  --card: #ffffff;
  --border: #e6e8f0;
  --border-strong: #d3d7e4;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --sidebar-bg: #0f1222;
  --sidebar-text: #c7ccdb;
  --sidebar-text-2: #7c8199;
  --sidebar-active: rgba(255, 255, 255, 0.08);
}

/* ---- Dark ---- */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0b0e17;
    --bg-elev: #131826;
    --bg-soft: #0f1420;
    --card: #131826;
    --border: #232a3b;
    --border-strong: #2f3750;
    --text: #eef1f7;
    --text-2: #a3adc2;
    --text-3: #6b7590;
    --sidebar-bg: #090b13;
    --sidebar-text: #c7ccdb;
    --sidebar-text-2: #6b7590;
    --sidebar-active: rgba(255, 255, 255, 0.06);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #0b0e17;
  --bg-elev: #131826;
  --bg-soft: #0f1420;
  --card: #131826;
  --border: #232a3b;
  --border-strong: #2f3750;
  --text: #eef1f7;
  --text-2: #a3adc2;
  --text-3: #6b7590;
  --sidebar-bg: #090b13;
  --sidebar-text: #c7ccdb;
  --sidebar-text-2: #6b7590;
  --sidebar-active: rgba(255, 255, 255, 0.06);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* the attribute must always win over display rules */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
button { font-family: inherit; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; }
.brand-mark { width: 38px; height: 38px; flex-shrink: 0; }
.brand-mark img {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}
.brand-text { display: flex; flex-direction: column; overflow: hidden; }
.brand-name { font-weight: 700; font-size: 15px; color: #fff; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-text-2); text-transform: uppercase;
  letter-spacing: 0.08em; }

/* Account switcher */
.acct-switch-wrap { position: relative; margin: 4px 4px 12px; }
.acct-switch { width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 10px; cursor: pointer; color: #fff;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.09);
  font-size: 13.5px; font-weight: 600; font-family: inherit; }
.acct-switch:hover { background: rgba(255,255,255,0.11); }
.acct-dot { color: var(--accent); font-size: 11px; }
.acct-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.acct-caret { color: var(--sidebar-text-2); font-size: 11px; }
.acct-menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  background: #1b2030; border: 1px solid rgba(255,255,255,0.12); border-radius: 11px;
  box-shadow: var(--shadow-lg); padding: 6px; max-height: 340px; overflow: auto; }
.acct-menu-item { display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--sidebar-text);
  font-size: 13px; background: none; border: none; text-align: left; font-family: inherit; }
.acct-menu-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.acct-menu-item.active { color: #fff; }
.acct-menu-item.active::after { content: "✓"; margin-left: auto; color: var(--accent); }
.acct-menu-sep { height: 1px; background: rgba(255,255,255,0.08); margin: 6px 4px; }
.acct-menu-add { color: var(--accent); font-weight: 650; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-text); font-weight: 550; font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item.active .nav-ico { color: var(--accent); }
.nav-ico { width: 20px; text-align: center; opacity: 0.9; font-size: 15px; }
.nav-count {
  margin-left: auto; background: rgba(255,255,255,0.12); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px;
}

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.07); }
.mode-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; font-size: 12.5px; font-weight: 650;
  background: rgba(245, 158, 11, 0.14); color: #fbbf24;
}
.mode-pill.live { background: rgba(16, 185, 129, 0.16); color: #34d399; }
.mode-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.06); }
.conn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.conn-chip { font-size: 10.5px; font-weight: 650; padding: 3px 8px; border-radius: 6px;
  background: rgba(255,255,255,0.06); color: var(--sidebar-text-2); }
.conn-chip.ok { color: #34d399; background: rgba(16,185,129,0.14); }
.conn-chip.bad { color: #fb7185; background: rgba(244,63,94,0.14); }
.theme-toggle {
  align-self: flex-start; background: rgba(255,255,255,0.07); border: none;
  color: var(--sidebar-text); width: 34px; height: 34px; border-radius: 9px;
  cursor: pointer; font-size: 15px;
}
.theme-toggle:hover { background: rgba(255,255,255,0.14); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 30px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title h1 { font-size: 20px; }
.topbar-sub { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.menu-btn { display: none; background: none; border: none; font-size: 20px; color: var(--text);
  cursor: pointer; }
.view { padding: 26px 30px 60px; max-width: 1280px; width: 100%; }

/* ========================= Buttons ========================= */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  cursor: pointer; transition: all 0.14s; white-space: nowrap;
}
.btn:hover { border-color: var(--text-3); background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--grad); border: none; color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.05); background: var(--grad); }
.btn-accent { background: var(--accent); border: none; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger { color: var(--s-failed); border-color: color-mix(in srgb, var(--s-failed) 40%, var(--border)); }
.btn-danger:hover { background: color-mix(in srgb, var(--s-failed) 12%, transparent); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }

/* ========================= Cards & grid ========================= */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.grid { display: grid; gap: 18px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-gallery { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-3); margin: 30px 0 14px; font-weight: 700; }
.section-title:first-child { margin-top: 0; }

/* Stat tile */
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--stat-accent, var(--accent)); }
.stat-label { font-size: 12px; color: var(--text-3); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 30px; font-weight: 720; letter-spacing: -0.02em; line-height: 1; }
.stat-sub { font-size: 12px; color: var(--text-2); }

/* ========================= Badges ========================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.02em; text-transform: uppercase;
  background: var(--badge-bg, var(--bg-soft)); color: var(--badge-fg, var(--text-2));
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; }
.badge.plain::before { display: none; }
.badge-PLANNED    { --badge-fg: var(--s-planned);    --badge-bg: color-mix(in srgb, var(--s-planned) 15%, transparent); }
.badge-GENERATED  { --badge-fg: var(--s-generated);  --badge-bg: color-mix(in srgb, var(--s-generated) 15%, transparent); }
.badge-MEDIA_READY{ --badge-fg: var(--s-media);      --badge-bg: color-mix(in srgb, var(--s-media) 15%, transparent); }
.badge-SCHEDULED  { --badge-fg: var(--s-scheduled);  --badge-bg: color-mix(in srgb, var(--s-scheduled) 16%, transparent); }
.badge-PUBLISHING { --badge-fg: var(--s-publishing); --badge-bg: color-mix(in srgb, var(--s-publishing) 15%, transparent); }
.badge-PUBLISHED  { --badge-fg: var(--s-published);  --badge-bg: color-mix(in srgb, var(--s-published) 16%, transparent); }
.badge-FAILED     { --badge-fg: var(--s-failed);     --badge-bg: color-mix(in srgb, var(--s-failed) 15%, transparent); }
.badge-REJECTED   { --badge-fg: var(--s-rejected);   --badge-bg: color-mix(in srgb, var(--s-rejected) 18%, transparent); }
.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 7px;
  font-size: 11.5px; font-weight: 600; background: var(--bg-soft); color: var(--text-2); }
.chip-tag { color: var(--accent); background: var(--accent-soft); }

/* ========================= Post cards ========================= */
.post-card { display: flex; flex-direction: column; overflow: hidden; }
.post-media {
  aspect-ratio: 4 / 5; background: var(--bg-soft); position: relative;
  display: grid; place-items: center; overflow: hidden;
}
.post-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-media .placeholder { color: var(--text-3); font-size: 34px; }
.post-media .carousel-badge { position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,0.6); color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 7px; }
.post-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.post-topline { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.post-topic { font-weight: 650; font-size: 14.5px; line-height: 1.3; }
.post-pillar { font-size: 11.5px; color: var(--text-3); font-weight: 600; }
.post-caption { font-size: 13px; color: var(--text-2); display: -webkit-box;
  -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.post-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.post-meta { font-size: 11.5px; color: var(--text-3); display: flex; align-items: center;
  gap: 8px; }
.post-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }

/* ========================= Tables ========================= */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-3); font-weight: 700;
  padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-soft); }

/* ========================= Forms ========================= */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--text-3); }
.input, .textarea, .select {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); font-size: 13.5px; font-family: inherit;
  transition: border 0.14s, box-shadow 0.14s;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 42px; height: 24px; border-radius: 999px; background: var(--border-strong);
  transition: background 0.16s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px;
  height: 18px; border-radius: 50%; background: #fff; transition: transform 0.16s;
  box-shadow: var(--shadow-sm); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ========================= Misc ========================= */
.row { display: flex; gap: 12px; align-items: center; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.banner {
  display: flex; align-items: center; gap: 12px; padding: 13px 18px;
  border-radius: var(--radius); font-size: 13.5px; font-weight: 550; margin-bottom: 22px;
  border: 1px solid transparent;
}
.banner-warn { background: color-mix(in srgb, var(--s-scheduled) 12%, transparent);
  color: color-mix(in srgb, var(--s-scheduled) 78%, var(--text));
  border-color: color-mix(in srgb, var(--s-scheduled) 30%, transparent); }
.banner-info { background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 70%, var(--text));
  border-color: var(--accent-ring); }
.empty { text-align: center; padding: 64px 24px; color: var(--text-3); }
.empty .empty-ico { font-size: 42px; opacity: 0.5; }
.empty h3 { margin: 14px 0 6px; color: var(--text-2); font-weight: 650; }

/* Spinner */
.spinner { width: 20px; height: 20px; border-radius: 50%; display: inline-block;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-splash { display: grid; place-items: center; padding: 90px 0; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

/* Toasts */
.toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column;
  gap: 10px; z-index: 100; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 11px;
  background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 550; min-width: 240px; max-width: 380px;
  animation: toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.toast .toast-bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--accent); }
.toast-success .toast-bar { background: var(--s-published); }
.toast-error .toast-bar { background: var(--s-failed); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* Modal */
.modal-root { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: rgba(8, 11, 20, 0.55); backdrop-filter: blur(3px); padding: 20px; }
.modal-root[hidden] { display: none; }
.modal { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  animation: toast-in 0.2s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--bg-elev); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px;
  border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--bg-elev); }
.close-x { background: none; border: none; font-size: 22px; color: var(--text-3); cursor: pointer;
  line-height: 1; }
.close-x:hover { color: var(--text); }

/* ========================= Auth gate ========================= */
.auth-gate { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: var(--bg); padding: 20px; }
.auth-gate[hidden] { display: none; }
.auth-card { width: 100%; max-width: 384px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 32px 28px; text-align: center; }
.auth-logo img { width: 52px; height: 52px; filter: drop-shadow(0 6px 14px rgba(0,0,0,0.3)); }
.auth-title { font-size: 20px; margin: 14px 0 4px; }
.auth-sub { color: var(--text-3); font-size: 13px; margin: 0 0 22px; }
.auth-form { text-align: left; }
.auth-error { margin: 2px 0 14px; }
.auth-form .btn-block { margin-top: 6px; padding: 11px; }
.auth-switch { margin-top: 18px; font-size: 13px; color: var(--text-3); }
.auth-switch a { color: var(--accent); font-weight: 600; cursor: pointer; }

/* Sidebar footer user box */
.footer-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-box { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-email { font-size: 11px; color: var(--sidebar-text-2); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; max-width: 112px; }
.logout-btn { background: rgba(255,255,255,0.06); border: none; color: var(--sidebar-text-2);
  font-size: 11px; font-weight: 600; padding: 5px 9px; border-radius: 7px; cursor: pointer;
  font-family: inherit; }
.logout-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* ========================= Responsive ========================= */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform 0.22s;
    box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .view { padding: 20px 16px 50px; }
  .topbar { padding: 14px 16px; }
}
