@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Syne:wght@400;600;700&display=swap');

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0d0f;
  --surface:     #141416;
  --surface-2:   #1a1a1e;
  --border:      rgba(255,255,255,0.07);
  --border-2:    rgba(255,255,255,0.12);
  --text:        #e8e8ec;
  --text-muted:  #888899;
  --text-dim:    #55556a;
  --text-logo:  #7d004f;
  --accent:      #3b8add;

  --green:  #3dd6a0;
  --red:    #e24b4a;
  --yellow: #f5c842;
  --blue:   #3b8add;
  --orange: #f0874a;
  --purple: #9b7cf5;

  --green-bg:   rgba(61,214,160,0.08);
  --red-bg:     rgba(226,75,74,0.08);
  --yellow-bg:  rgba(245,200,66,0.08);
  --blue-bg:    rgba(59,138,221,0.08);
  --orange-bg:  rgba(240,135,74,0.08);

  --green-bg-toast:   rgb(125, 212, 182);
  --red-bg-toast:     rgb(224, 134, 134);
  --yellow-bg-toast:  rgb(243, 219, 147);
  --blue-bg-toast:    rgb(167, 206, 249);
  --orange-bg-toast:  rgb(240, 190, 160);
  --secondary-bg-toast:  rgba(192, 185, 181, 0.179);
  --border-color-toast: rgba(10, 10, 9, 0.992);

  --bg-tag: rgba(88, 168, 253, 0.3);
  --text-tag: #3b8add;
  --bg-version: rgba(13, 82, 35, 0.819);

  --radius:   8px;
  --radius-lg: 12px;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-disp: 'Syne', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, sans-serif;

  --sidebar-w: 220px;
  --header-h:  56px;
}

/* ── Light Mode ───────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:          #f2f2f5;
  --surface:     #ffffff;
  --surface-2:   #ebebef;
  --border:      rgba(0,0,0,0.08);
  --border-2:    rgba(0,0,0,0.14);
  --text:        #111118;
  --text-muted:  #5a5a72;
  --text-dim:    #a0a0b8;
  --accent:      #3b8add;

  --green-bg:   rgba(20,160,100,0.08);
  --red-bg:     rgba(200,50,50,0.08);
  --yellow-bg:  rgba(180,140,0,0.08);
  --blue-bg:    rgba(30,100,200,0.08);
  --orange-bg:  rgba(200,100,30,0.08);

  --green-bg-toast:   rgb(125, 212, 182);
  --red-bg-toast:     rgb(224, 134, 134);
  --yellow-bg-toast:  rgb(243, 219, 147);
  --blue-bg-toast:    rgb(167, 206, 249);
  --orange-bg-toast:  rgb(240, 190, 160);
  --secondary-bg-toast:  rgba(192, 185, 181, 0.179);
  --border-color-toast: rgba(10, 10, 9, 0.992);

  --bg-tag: rgba(88, 168, 253, 0.3);
  --text-tag: #3b8add;
  --bg-version: rgba(13, 82, 35, 0.819);
}

[data-theme="light"] .nav-item:hover         { background: rgba(0,0,0,0.04); }
[data-theme="light"] .sidebar                { background: var(--surface); }
[data-theme="light"] .log-entry:hover        { background: rgba(0,0,0,0.03); }
[data-theme="light"] .tr-expandable:hover td { background: rgba(0,0,0,0.03); }
[data-theme="light"] input[type="range"] { background: #dde1e7; border-color: #c8cdd5; }
[data-theme="light"] input[type="range"]::-webkit-slider-runnable-track { background: #dde1e7; border-radius: 3px; }
[data-theme="light"] input[type="range"]::-moz-range-track { background: #dde1e7; border-radius: 3px; }
[data-theme="light"] input[type="range"]::-webkit-slider-thumb { border-color: var(--surface); }
[data-theme="light"] input[type="range"]::-moz-range-thumb { border-color: var(--surface); }

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
h1, h2, h3, h4 { font-family: var(--font-disp); font-weight: 600; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

.mono { font-family: var(--font-mono); font-size: 0.85em; }

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

.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;
}

.sidebar-logo {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
}

.sidebar-logo .logo-icon {
  width: 50px; height: 28px;
  background: none;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}

.sidebar-logo .logo-icon img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.sidebar-logo .logo-text {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-logo);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
}

.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-item.active {
  color: var(--blue);
  border-left-color: var(--blue);
  background: var(--blue-bg);
}

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.nav-item .icon { width: 16px; text-align: center; opacity: 0.8; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Org Switcher ─────────────────────────────────────────────────────────── */
.org-switcher {
  position: relative;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.org-switcher-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  transition: background 0.15s;
}

.org-switcher-btn:hover {
  background: rgba(128,128,128,0.1);
}

.org-avatar {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  user-select: none;
}

.org-switcher-label {
  flex: 1;
  min-width: 0;
}

.org-switcher-name {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.org-switcher-role {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: capitalize;
}

.org-switcher-chevron {
  color: var(--text-dim);
  flex-shrink: 0;
  font-size: 0.7rem;
  transition: transform 0.15s;
}

.org-switcher.open .org-switcher-chevron {
  transform: rotate(180deg);
}

.org-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 12px; right: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  z-index: 200;
  display: none;
}

.org-switcher.open .org-dropdown {
  display: block;
}

.org-dropdown-header {
  padding: 4px 10px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.org-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.org-dropdown-item:hover {
  background: rgba(128,128,128,0.1);
}

.org-dropdown-item.is-current {
  background: var(--blue-bg);
}

.org-dropdown-item-info {
  flex: 1;
  min-width: 0;
}

.org-dropdown-item-name {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.org-dropdown-item-role {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: capitalize;
}

.org-dropdown-check {
  color: var(--blue);
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ── Pending-invitation badge on org avatar ───────────────────────────────── */
.org-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.org-inv-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--orange);
  color: #fff;
  border-radius: 999px;
  font-size: 0.58rem;
  font-weight: 700;
  min-width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--surface);
  pointer-events: none;
}

/* ── Pending-invitation popup ─────────────────────────────────────────────── */
.inv-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.inv-popup {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  position: relative;
}

.inv-popup-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.inv-popup-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0 0 20px;
}

.inv-popup-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.inv-popup-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.inv-popup-item-info {
  flex: 1;
  min-width: 0;
}

.inv-popup-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-popup-item-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Role-based visibility ────────────────────────────────────────────────── */
/* Elements marked data-requires="editor" are hidden for viewers.             */
/* Elements marked data-requires="owner" are hidden for editors and viewers.  */
body[data-role="viewer"] [data-requires="editor"],
body[data-role="viewer"] [data-requires="owner"],
body[data-role="editor"] [data-requires="owner"] {
  display: none !important;
}

/* ── Account picker (custom dropdown with avatars) ────────────────────────── */
.acc-picker {
  position: relative;
}

.acc-picker-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s;
}

.acc-picker-trigger:hover,
.acc-picker.open .acc-picker-trigger {
  border-color: var(--primary);
}

.acc-picker-selected {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.acc-picker-name {
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acc-picker-chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.acc-picker.open .acc-picker-chevron {
  transform: rotate(180deg);
}

.acc-picker-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  max-height: 220px;
  overflow-y: auto;
}

.acc-picker.open .acc-picker-dropdown {
  display: block;
}

.acc-picker-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.12s;
}

.acc-picker-option:hover {
  background: var(--surface-2);
}

.acc-picker-option.is-selected {
  background: var(--surface-2);
  font-weight: 600;
}

.acc-picker-option .acc-picker-check {
  margin-left: auto;
  color: var(--primary);
  font-size: 0.85rem;
}

/* ── Account color swatches ───────────────────────────────────────────────── */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.color-picker-input {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}

.color-picker-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker-input::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.color-picker-input::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

.color-picker-input:hover {
  transform: scale(1.15);
  border-color: var(--text);
}

.color-picker-input.custom-active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--surface);
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--surface);
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.color-swatch-none {
  background: var(--surface-2) !important;
  color: var(--text-muted);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-color: var(--border);
}

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

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}

.header-title {
  font-family: var(--font-disp);
  font-weight: 600;
  font-size: 1rem;
  flex: none;
  min-width: 100px;
}

.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* ── Page ─────────────────────────────────────────────────────────────────── */
.page { padding: 24px; flex: 1; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { font-size: 1.4rem; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header.collapsible {
  cursor: pointer;
  user-select: none;
}
.card-header.collapsible:hover { background: var(--surface-hover, rgba(255,255,255,.04)); }

.collapse-chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform .18s ease;
  margin-left: 8px;
  flex-shrink: 0;
}
.card.collapsed .collapse-chevron { transform: rotate(-90deg); }

.card-collapsible-body {
  overflow: hidden;
  transition: max-height .2s ease, opacity .15s ease;
  max-height: 2000px;
  opacity: 1;
}
.card.collapsed .card-collapsible-body {
  max-height: 0;
  opacity: 0;
}
.card.collapsed .card-header { border-bottom-color: transparent; }

.card.card-nested {
  border-radius: 0;
  border: none;
  border-top: 1px solid var(--border);
}
.card.card-nested:first-child {
  border-top: none;
}

.card-title { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.card-body  { padding: 20px; overflow-y: auto; height:100% !important}

/* ── Grid ─────────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
.grid-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; }

@media (max-width: 1600px) { .grid-6 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1400px) { .grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 1000px) { .grid-5, .grid-6 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.header-clock {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ── Account Cards ────────────────────────────────────────────────────────── */
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.account-name { font-weight: 600; font-size: 0.95rem; }
.account-id   { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }

.account-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 0.8rem;
}

.account-stat { color: var(--text-muted); }
.account-stat span { color: var(--text); font-weight: 500; }

.account-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* ── Badges & Pills ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-green  { background: var(--green-bg);  color: var(--green);  }
.badge-red    { background: var(--red-bg);    color: var(--red);    }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue);   }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-gray   { background: rgba(173, 173, 173, 0.224); color: var(--text-muted); }
.badge-purple  { background: rgba(154, 107, 255, 0.217); color: #b07fff; }
.badge-warning { background: var(--yellow-bg); color: var(--yellow); }
.badge-danger  { background: var(--red-bg);    color: var(--red);    }
.badge-success { background: var(--green-bg);  color: var(--green);  }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-green  { background: var(--green); }
.dot-red    { background: var(--red); }
.dot-yellow { background: var(--yellow); }
.dot-blue   { background: var(--blue); }
.dot-gray   { background: var(--text-dim); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid;
}

.pill-running { background: var(--green-bg);  color: var(--green);  border-color: rgba(61,214,160,0.2); }
.pill-paused  { background: var(--yellow-bg); color: var(--yellow); border-color: rgba(245,200,66,0.2); }
.pill-error   { background: var(--red-bg);    color: var(--red);    border-color: rgba(226,75,74,0.2); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn-primary:hover:not(:disabled) { background: #2d76c8; border-color: #2d76c8; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-2);
}
.btn-secondary:hover:not(:disabled) { background: #2d76c8; border-color: #2d76c8; color: #fff}

.btn-aurelia {
  background: var(--text-logo);
  color: #fff;
  border-color: var(--text-logo);
}
.btn-aurelia:hover:not(:disabled) { background: #590039; border-color: #590039; }

.btn-danger {
  background: var(--red);
  color: white;
  border-color: var(--red);
}
.btn-danger:hover:not(:disabled) { background: rgba(226,75,74,0.15); }

.btn-success {
  background: var(--green-bg);
  color: var(--green);
  border-color: rgba(61,214,160,0.2);
}

.btn-sm { padding: 6px 10px; font-size: 0.75rem; }
.btn-lg { padding: 10px 20px; font-size: 0.9rem; }

.btn-icon {
  padding: 6px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 5px;}
.form-label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }

.form-control {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.875rem;
  transition: border-color 0.15s;
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,138,221,0.12);
}

.form-control::placeholder { color: var(--text-dim); }

select.form-control { appearance: none; cursor: pointer; }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint { font-size: 0.75rem; color: var(--text-muted); }

/* Toggle Switch */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.toggle input { display: none; }

.toggle-track {
  width: 36px; height: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 100px;
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 0.2s;
}

.toggle input:checked + .toggle-track { background: var(--blue); border-color: var(--blue); }
.toggle input:checked + .toggle-track::after { left: 18px; background: #fff; }

.toggle-label { font-size: 0.875rem; user-select: none; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th {
  text-align: left;
  padding: 10px 14px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: rgba(255,255,255,0.02); }

.tr-expandable { cursor: pointer; }
.tr-expandable td:first-child { padding-left: 10px; }

.tr-details td {
  background: var(--surface-2);
  padding: 12px 14px;
}

.tr-details-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.detail-item label { display: block; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 2px; }
.detail-item span  { font-family: var(--font-mono); font-size: 0.78rem; word-break: break-all; }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  height: 95vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  transition: transform 0.2s;
}

.modal-backdrop.open .modal { transform: none; }

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-title { font-size: 0.95rem; font-weight: 600; }


.modal-body  { padding: 20px; flex: 1; overflow-y: auto; }
.modal-body.flex-form { display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}

.tab {
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Log Panel ────────────────────────────────────────────────────────────── */
.log-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.log-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.log-panel-title { font-size: 0.8rem; font-weight: 600; flex: 1; }

.log-body {
  height: 320px;
  overflow-y: auto;
  padding: 8px 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.log-entry {
  display: flex;
  gap: 8px;
  padding: 3px 14px;
  line-height: 1.4;
  transition: background 0.1s;
}

.log-entry:hover { background: rgba(255,255,255,0.03); }

.log-ts     { color: var(--text-dim); flex-shrink: 0; }
.log-level  { width: 40px; flex-shrink: 0; font-weight: 500; }
.log-acct   { color: var(--text-muted); flex-shrink: 0; max-width: 100px; overflow: hidden; text-overflow: ellipsis; }
.log-msg    { color: var(--text); word-break: break-word; flex: 1; }

.log-level-debug { color: var(--text-dim); }
.log-level-info  { color: var(--blue); }
.log-level-warn  { color: var(--yellow); }
.log-level-error { color: var(--red); }

/* ── Stat Cards ───────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 1.8rem; font-weight: 700; font-family: var(--font-disp); line-height: 1; }
.stat-sub   { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  /*display: flex;*/
  align-items: flex-start;
  gap: 10px;
  border: 1px solid;
}

.alert-info    { background: var(--blue-bg);   color: var(--blue);   border-color: rgba(59,138,221,0.2); }
.alert-success { background: var(--green-bg);  color: var(--green);  border-color: rgba(61,214,160,0.2); }
.alert-warning { background: var(--yellow-bg); color: var(--yellow); border-color: rgba(245,200,66,0.2); }
.alert-error   { background: var(--red-bg);    color: var(--red);    border-color: rgba(226,75,74,0.2); }
.alert-orange  { background: var(--orange-bg); color: var(--orange); border-color: rgba(240,135,74,0.2); }

/* ── Separator ────────────────────────────────────────────────────────────── */
.sep { height: 1px; background: var(--border); margin: 16px 0; }

/* ── Flex utilities ───────────────────────────────────────────────────────── */
.flex       { display: flex; gap: 10px;}
.flex-col   { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.flex-1 { flex: 1; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.ml-auto { margin-left: auto; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.75rem; }
.font-mono { font-family: var(--font-mono); }
.w-full { width: 100%; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 360px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon {
  width: 48px; height: 48px;
  background: none;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 12px;
}

.login-logo h1 { font-size: 1.2rem; color: var(--text-logo)}
.login-logo p  { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: currentColor;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Range Slider ─────────────────────────────────────────────────────────── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  border-radius: 3px;
}

/* ── Tag Input ────────────────────────────────────────────────────────────── */
.tag-wrap {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 40px; padding: 6px 10px;
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: var(--radius); cursor: text;
}
.tag-wrap:focus-within { border-color: var(--blue); }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px 2px 10px; background: var(--blue-bg);
  border: 1px solid rgba(59,138,221,0.4); border-radius: 20px;
  font-size: 0.78rem; white-space: nowrap; color: var(--blue);
}
.tag-remove {
  cursor: pointer; opacity: 0.6; font-size: 1rem; line-height: 1;
  background: none; border: none; color: inherit; padding: 0;
}
.tag-remove:hover { opacity: 1; }
.tag-search {
  flex: 1; min-width: 120px; background: none; border: none;
  outline: none; color: var(--text); font-size: 0.85rem; padding: 2px 0;
}
.tag-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius); z-index: 200;
  max-height: 220px; overflow-y: auto; display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.tag-dropdown.open { display: block; }
.tag-option {
  padding: 9px 14px; cursor: pointer; font-size: 0.83rem;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.tag-option:last-child { border-bottom: none; }
.tag-option:hover { background: var(--surface-2); }
.tag-option small { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }
.tag-option.already-added { opacity: 0.4; pointer-events: none; }

/* ── Section label (modal sections) ─────────────────────────────────────── */
.section-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.section-label + * { margin-top: 0; }

.section-label-spaced { margin-top: 20px; }

/* ── Modal tabs (inside modal, above body) ───────────────────────────────── */
.modal-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  padding: 0 20px; gap: 0; flex-shrink: 0;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
/* ── Mobile sidebar overlay ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ── Mobile hamburger button (hidden on desktop) ──────────────────────────── */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  margin-right: 4px;
  border-radius: 6px;
  color: var(--text);
  flex-shrink: 0;
}
.hamburger:hover { background: var(--surface-2); }
.hamburger svg { display: block; }

/* ── Mobile header logo (hidden on desktop) ───────────────────────────────── */
.header-mobile-logo {
  display: none;
  align-items: center;
  gap: 8px;
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-logo);
  flex: 1;
}
.header-mobile-logo img { height: 22px; width: auto; }

@media (max-width: 768px) {
  /* Sidebar: hidden by default, slides in as overlay */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  /* Content takes full width */
  .main-content { margin-left: 0; }
  .page { padding: 16px; }

  /* Grid collapses */
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Show hamburger + mobile logo, hide desktop header-title */
  .hamburger { display: flex; align-items: center; justify-content: center; }
  .header-mobile-logo { display: flex; }
  .header-title { display: none; }

  /* Header: tighter on mobile */
  .header { padding: 0 12px; gap: 8px; }

  /* Tables: scroll horizontally instead of overflowing */
  .table-wrap, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }

  /* Cards: remove excess padding */
  .card-body { padding: 12px 14px; }
  .card-header { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }

  /* Modals: full-width on small screens */
  .modal { max-width: calc(100vw - 24px); margin: 12px; }

  /* Modal tabs: scroll horizontally */
  .tabs { overflow-x: auto; flex-wrap: nowrap; }

  /* Summary cards: single column on very small screens */
  .summary-cards { grid-template-columns: 1fr 1fr; }

  /* Billing controls: stack vertically */
  .billing-controls { flex-direction: column; align-items: stretch; }
  .period-presets { flex-wrap: wrap; }
  .date-nav { flex-wrap: wrap; }
  .client-filter-wrap { min-width: 0; width: 100%; }
}

/* ── Bulk selection ───────────────────────────────────────────────────────── */
tr.bulk-selected { background: var(--blue-bg) !important; }
tr.bulk-selected td { border-color: var(--blue-bg) !important; }
.post-item.bulk-selected { background: var(--blue-bg); border-radius: 8px; }
.btn-link { background: none; border: none; padding: 0; color: var(--blue); cursor: pointer; text-decoration: underline; font-size: inherit; }

/* ── Fade-in ──────────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn 0.2s ease; }

/* ── Code ─────────────────────────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--blue);
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 2rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 0.875rem; }

/* ── Rules editor ─────────────────────────────────────────────────────────── */
.rule-row {
  display: grid;
  grid-template-columns: 1fr 1fr 80px 1fr 80px 36px;
  gap: 6px;
  align-items: center;
}

/* ── Budget adjustment row ────────────────────────────────────────────────── */
.budget-change {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.budget-old { color: var(--text-muted); text-decoration: line-through; }
.budget-new-up   { color: var(--green); }
.budget-new-down { color: var(--red); }

/* ── Upload Area ──────────────────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--blue);
  background: rgba(59,130,246,0.05);
}
.upload-area-inner {
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
}
.upload-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.82rem;
}
.upload-file-row .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-file-row .file-size { color: var(--text-dim); white-space: nowrap; }
.upload-progress {
  height: 4px;
  background: var(--surface-3, var(--border));
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.upload-progress-bar {
  height: 100%;
  background: var(--blue);
  transition: width 0.2s;
}

/* ── Post Cards (legacy) ─────────────────────────────────────────────────── */
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.post-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.post-card-body {
  padding: 12px 16px;
  font-size: 0.84rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}
.post-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ── Insights Grid ───────────────────────────────────────────────────────── */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top:25px;
}
.insight-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 0;
}
.insight-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.insight-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Post Items (new two-section layout) ─────────────────────────────────── */
.post-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.post-item:last-child { border-bottom: none; }
.post-thumb {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.post-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.post-thumb-icon { font-size: 1.6rem; }
.post-info {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}
.post-actions {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  align-items: flex-start;
  padding-top: 2px;
}
.mb-32 { margin-bottom: 32px; }

/* ── Dry-run banner ───────────────────────────────────────────────────────── */
.dryrun-banner {
  background: var(--orange-bg);
  border-bottom: 1px solid rgba(240,135,74,0.2);
  color: var(--orange);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Post Preview Phone Mockup ────────────────────────────────────────────── */
/* ── Post modal split layout ─────────────────────────────────────────────── */
.post-modal-wide {
  width:     clamp(680px, 77vw, 1400px);
  max-width: clamp(680px, 77vw, 1400px);
}

/* Override modal-body defaults for the split layout */
.modal-body.post-modal-body {
  display:        flex !important;
  flex-direction: row !important;
  overflow:       hidden !important;
  padding:        0 !important;
  flex:           1 1 0 !important;
  min-height:     0 !important;
}

.post-form-pane {
  width:          50%;
  min-width:      360px;
  flex-shrink:    0;
  overflow-y:     auto;
  padding:        20px;
  border-right:   1px solid var(--border);
  display:        flex;
  flex-direction: column;
  gap:            16px;
  min-height:     0;
}

.post-preview-pane {
  flex:           1 1 0;
  display:        flex;
  flex-direction: column;
  overflow:       hidden;
  background:     var(--surface-2);
  min-width:      0;
  min-height:     0;
}

.preview-toggle-bar {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     10px 16px;
  border-bottom: 1px solid var(--border);
  background:  var(--surface);
  flex-shrink: 0;
}

.preview-viewport {
  flex:            1 1 0;
  overflow-y:      auto;
  display:         flex;
  align-items:     flex-start;
  justify-content: center;
  padding:         20px 16px;
  min-height:      0;
}

.preview-hint {
  font-size:   0.72rem;
  color:       var(--text-muted);
  text-align:  center;
  padding:     6px 16px 10px;
  flex-shrink: 0;
  margin:      0;
}

/* Narrow: collapse to single panel, preview is overlay */
@media (max-width: 1100px) {
  .post-modal-wide { width: 95vw; max-width: 95vw; }
  .post-preview-pane { display: none; }
  .post-preview-pane.preview-open {
    display:  flex;
    position: absolute;
    inset:    0;
    z-index:  20;
    background: var(--surface);
  }
}
@media (min-width: 1101px) {
  .preview-narrow-btn { display: none !important; }
}

/* ── Instagram feed mock ─────────────────────────────────────────────────── */
.ig-feed-scroll {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}
.ig-feed-item { border-bottom: 1px solid #efefef; }
.ig-feed-item.ig-feed-current {
  outline: 2px solid #0095f6;
  outline-offset: -2px;
  position: relative;
}
.ig-feed-current-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #0095f6;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  z-index: 1;
  letter-spacing: .03em;
}

/* Desktop preview frame */
.desktop-frame {
  width: 100%;
  max-width: 600px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0,0,0,.15);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: #111;
}

/* Legacy .preview-panel kept for compatibility */
.preview-panel { display: none; }
.preview-panel.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

.phone-frame {
  width: 320px;
  border-radius: 34px;
  border: 7px solid #111;
  background: #000;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 24px 64px rgba(0,0,0,0.6);
  flex-shrink: 0;
}
[data-theme="light"] .phone-frame { border-color: #333; box-shadow: 0 0 0 1px rgba(0,0,0,0.12), 0 24px 64px rgba(0,0,0,0.25); }

.phone-notch {
  height: 26px;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
}
.phone-notch-bar {
  width: 80px;
  height: 10px;
  background: #222;
  border-radius: 6px;
}
.phone-screen {
  background:  #fff;
  color:       #111;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size:   11px;
  height:      600px;
  overflow-y:  auto;
  overflow-x:  hidden;
  scrollbar-width: thin;
}
.ig-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-bottom: 1px solid #efefef;
}
.ig-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
  font-weight: 700;
}
.ig-username { font-weight: 600; font-size: 11px; color: #111; flex: 1; }
.ig-more     { font-size: 16px; color: #888; line-height: 1; }

.ig-image {
  width: 100%;
  aspect-ratio: 1/1;
  background: #efefef;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.ig-image img,
.ig-image video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ig-image-icon { font-size: 2.5rem; opacity: 0.3; }

.ig-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px 4px;
}
.ig-action-icon { font-size: 18px; cursor: pointer; }
.ig-bookmark    { margin-left: auto; }
.ig-likes       { padding: 0 10px 4px; font-weight: 700; font-size: 11px; color: #111; }
.ig-caption     { padding: 0 10px 8px; font-size: 10.5px; color: #111; line-height: 1.4; word-break: break-word; }
.ig-caption .ig-cap-user { font-weight: 700; }
.ig-caption .ig-hashtag  { color: #00376b; }
.ig-time { padding: 0 10px 10px; font-size: 9px; color: #8e8e8e; text-transform: uppercase; letter-spacing: .02em; }
/* ── Post View Modal ──────────────────────────────────────────────────────── */
.phone-frame-sm { width: 240px; }
.phone-frame-sm .phone-screen { height: 460px; }

.pv-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.pv-stat-cell {
  background: var(--surface-2, #f5f5f5);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.pv-stat-val { font-size: 1rem; font-weight: 700; color: var(--text); }
.pv-stat-lbl { font-size: 0.68rem; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }

/* ── First Comment ────────────────────────────────────────────────────────── */
.ig-first-comment { display: flex; align-items: flex-start; gap: 6px; padding: 0 10px 6px; }
.ig-first-comment .ig-avatar { width: 18px; height: 18px; min-width: 18px; font-size: 7px; flex-shrink: 0; }
.ig-first-comment .ig-avatar img { width: 18px; height: 18px; }
.ig-first-comment-text { font-size: 10px; color: #111; line-height: 1.4; word-break: break-word; }

/* ── Post Error Detail ────────────────────────────────────────────────────── */
.post-error-expand {
  margin-top: 6px;
}
.post-error-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 600;
  user-select: none;
}
.post-error-detail {
  display: none;
  margin-top: 5px;
  padding: 8px 10px;
  background: var(--red-bg);
  border: 1px solid var(--red);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}
.post-error-detail.open { display: block; }

/* ── Toast Notifications ──────────────────────────────────────────────────── */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 280px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.4;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  pointer-events: all;
  cursor: pointer;
  animation: toastIn 0.22s ease;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.hiding {
  opacity: 0;
  transform: translateX(20px);
}
.toast-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; min-width: 0; overflow-wrap: break-word; word-break: break-word; }
.toast-title { font-weight: 600; margin-bottom: 2px; overflow-wrap: break-word; word-break: break-word; }
.toast-msg   { color: var(--text-muted); font-size: 0.82rem; overflow-wrap: break-word; word-break: break-word; }
.toast-close { flex-shrink: 0; font-size: 1rem; opacity: 0.4; line-height: 1; }
.toast-close:hover { opacity: 0.9; }

.toast-body :focus{
  outline: none;
}

.toast.toast-success { border-color: var(--green);  background: var(--green-bg-toast); }
.toast.toast-error   { border-color: var(--red);    background: var(--red-bg-toast);   }
.toast.toast-warning { border-color: var(--orange);       background: var(--orange-bg-toast); }
.toast.toast-info    { color: black; border-color: var(--blue);   background: var(--blue-bg-toast);  }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── OAuth Discovery ──────────────────────────────────────────────────────── */
.discovery-page-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  transition: border-color 0.15s;
}
.discovery-page-row:not(.discovery-page-disabled):hover {
  border-color: var(--accent);
}
.discovery-page-disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ── Notification Bell ───────────────────────────────────────────────────── */
.notif-bell { position: relative; padding: 4px 6px; }
.notif-badge {
  position: absolute;
  top: -2px; right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  pointer-events: none;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 9000;
  overflow: hidden;
}
.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
}
.notif-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.notif-tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-bottom: -1px;
}
.notif-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.notif-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}
.notif-read-all {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
}
.notif-list { max-height: 320px; overflow-y: auto; }
.notif-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface-2); }
.notif-item-label { font-size: 0.72rem; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.notif-item-body { font-size: 0.8rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-ts { font-size: 0.7rem; color: var(--text-muted); margin-top: 3px; }
.notif-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  gap: 8px;
}
.notif-profile-link {
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
}
.notif-profile-link:hover { text-decoration: underline; }
.notif-loading, .notif-empty { padding: 16px 14px; font-size: 0.82rem; color: var(--text-muted); }

/* ── Comment Panel ────────────────────────────────────────────────────────── */
.comment-panel { display: flex; flex-direction: column; gap: 0; }
.comment-panel-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.comment-panel-tab {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s;
}
.comment-panel-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.comment-list { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.comment-bubble {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 11px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.comment-bubble.own { background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.comment-bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.comment-bubble-author { font-weight: 600; color: var(--text); }
.comment-bubble-body { font-size: 0.83rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.comment-bubble-body .mention { color: var(--accent); font-weight: 500; }
.comment-bubble-del {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 2px;
  opacity: 0.6;
}
.comment-bubble-del:hover { opacity: 1; color: var(--red); }
.comment-compose { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.comment-compose-row { display: flex; gap: 6px; align-items: flex-end; }
.comment-textarea {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.82rem;
  padding: 8px 10px;
  resize: none;
  min-height: 60px;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.15s;
}
.comment-textarea:focus { outline: none; border-color: var(--accent); }
.comment-send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  align-self: flex-end;
}
.comment-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.comment-vis-row { display: flex; gap: 6px; align-items: center; font-size: 0.75rem; }
.comment-vis-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.74rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.1s, color 0.1s;
}
.comment-vis-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.mention-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 8000;
  min-width: 200px;
  max-height: 180px;
  overflow-y: auto;
}
.mention-option {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.mention-option:hover, .mention-option.highlighted { background: var(--surface-2); }
.mention-option-name { font-weight: 600; }
.mention-option-label { font-size: 0.7rem; color: var(--text-muted); }
.post-filter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.post-filter-item:last-child { border-bottom: none; }
.post-filter-item:hover { background: var(--surface-2); }
.post-filter-item.selected { background: color-mix(in srgb, var(--blue) 10%, transparent); }
.post-filter-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.post-filter-thumb-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  font-size: 1.2rem;
}
.post-filter-item-info { min-width: 0; flex: 1; }
.pf-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}
.pf-badge-warn { background: color-mix(in srgb, var(--warning, #f59e0b) 18%, transparent); color: #b45309; }
.pf-badge-open { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.pf-badge-gray { background: var(--surface-2); color: var(--text-muted); }
.post-filter-item-caption {
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.post-filter-item-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

.comment-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  margin-left: 4px;
  vertical-align: middle;
}

/* ── Multi-Account Picker ──────────────────────────────────────────────────── */
.multi-acc-picker {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-y: auto;
  max-height: 260px;
  background: var(--surface);
}
.multi-acc-brand-header {
  padding: 6px 12px 4px;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.multi-acc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.multi-acc-row:last-child { border-bottom: none; }
.multi-acc-row:hover { background: var(--surface-2); }
.multi-acc-row.is-selected { background: color-mix(in srgb, var(--blue) 10%, transparent); }
