:root {
  --ink: #0c1f1c;
  --ink-2: #14302b;
  --ink-3: #1c3d37;
  --canvas: #eef2f1;
  --canvas-2: #f7f9f8;
  --panel: #ffffff;
  --border: #d5ddd9;
  --border-soft: #e4ebe7;
  --text: #12241f;
  --muted: #5c726b;
  --accent: #0f8f7b;
  --accent-2: #d97706;
  --accent-soft: rgba(15, 143, 123, 0.12);
  --good: #0f8a5f;
  --warn: #b45309;
  --bad: #c23b45;
  --shadow: 0 1px 2px rgba(12, 31, 28, 0.04), 0 12px 32px rgba(12, 31, 28, 0.06);
  --sidebar-w: 252px;
  --sidebar-collapsed-w: 76px;
  --inspector-w: 360px;
  --radius: 14px;
  --radius-sm: 10px;
  --font-display: "Roboto", sans-serif;
  --font-body: "Figtree", sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--canvas);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* —— App shell —— */
.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 220ms ease;
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(15, 143, 123, 0.08), transparent 55%),
    radial-gradient(700px 380px at 0% 100%, rgba(217, 119, 6, 0.05), transparent 50%),
    var(--canvas);
}

.app-body.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-w) 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, var(--ink-2) 0%, var(--ink) 55%, #091614 100%);
  color: #dce8e4;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 40;
  overflow: hidden;
  transition: width 220ms ease;
}

.app-body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-w);
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 280px at 20% 0%, rgba(15, 143, 123, 0.22), transparent 60%),
    radial-gradient(320px 240px at 100% 80%, rgba(217, 119, 6, 0.08), transparent 55%);
  pointer-events: none;
}

.sidebar-brand,
.sidebar-nav,
.sidebar-foot { position: relative; z-index: 1; }

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 1.1rem 0.85rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.collapse-btn {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: #dce8e4;
  cursor: pointer;
  padding: 0;
  box-shadow: none;
}

.collapse-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  filter: none;
}

.collapse-btn.top-collapse {
  color: var(--text);
  border-color: var(--border);
  background: var(--panel);
}

.icon-credit {
  margin: 0.55rem 0 0;
  font-size: 0.62rem;
  text-align: center;
  opacity: 0.45;
}

.icon-credit a {
  color: inherit !important;
  text-decoration: none !important;
}

.app-body.sidebar-collapsed .brand-text,
.app-body.sidebar-collapsed .nav-text,
.app-body.sidebar-collapsed .nav-label,
.app-body.sidebar-collapsed .user-meta,
.app-body.sidebar-collapsed .icon-credit {
  display: none;
}

.app-body.sidebar-collapsed .sidebar-brand {
  flex-direction: column;
  gap: 0.5rem;
}

.app-body.sidebar-collapsed .sidebar-brand .collapse-btn {
  display: inline-flex;
}

.app-body.sidebar-collapsed .top-collapse {
  display: none;
}

.app-body.sidebar-collapsed .brand-mark {
  justify-content: center;
  width: 100%;
}

.app-body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 0.7rem 0.4rem;
}

.app-body.sidebar-collapsed .user-chip {
  justify-content: center;
}

.app-body.sidebar-collapsed .logout-form .btn-block {
  padding: 0.55rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none !important;
}

.brand-logo {
  width: 2.15rem;
  height: 2.15rem;
  object-fit: contain;
  border-radius: 0.55rem;
  background: #0a0a0a;
  flex-shrink: 0;
}

.brand-glyph {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 0.7rem;
  background:
    conic-gradient(from 210deg, #0f8f7b, #d97706, #0f8f7b);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12), 0 8px 20px rgba(0, 0, 0, 0.25);
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

.brand-glyph::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 0.45rem;
  background: var(--ink);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  color: #f4faf8;
}
.brand-sub {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(220, 232, 228, 0.55);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 0.75rem 1rem;
}

.nav-label {
  margin: 1rem 0.65rem 0.4rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(220, 232, 228, 0.38);
}

.nav-label:first-child { margin-top: 0.25rem; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.15rem;
  border-radius: 10px;
  color: rgba(220, 232, 228, 0.72) !important;
  text-decoration: none !important;
  font-weight: 500;
  font-size: 0.92rem;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff !important;
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(15, 143, 123, 0.35), rgba(15, 143, 123, 0.12));
  color: #fff !important;
  box-shadow: inset 0 0 0 1px rgba(15, 143, 123, 0.35);
}

.nav-ico {
  width: 1.25rem;
  text-align: center;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.9;
  flex-shrink: 0;
}

.nav-ico::before {
  margin: 0;
}

i.fi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.nav-text { white-space: nowrap; }

.sidebar-foot {
  padding: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.user-chip {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 0.65rem;
  padding: 0.55rem 0.6rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: #7dffe4;
  border: 1px solid rgba(15, 143, 123, 0.4);
}

.user-email {
  font-size: 0.78rem;
  font-weight: 600;
  color: #eef6f3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 10.5rem;
}

.user-ws {
  font-size: 0.7rem;
  color: rgba(220, 232, 228, 0.45);
}

.logout-form { margin: 0; }
.btn-block { width: 100%; }

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

.page {
  padding: 1.5rem 1.75rem 2.5rem;
  max-width: 1180px;
  width: 100%;
  flex: 1;
  min-width: 0;
  animation: page-in 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* —— Right inspector (CRM detail pane) —— */
.inspector {
  width: var(--inspector-w);
  flex-shrink: 0;
  border-left: 1px solid var(--border-soft);
  background: var(--panel);
  display: none;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  box-shadow: -8px 0 28px rgba(12, 31, 28, 0.04);
  z-index: 15;
}

.app-body.inspector-open .inspector {
  display: flex;
  animation: inspector-in 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes inspector-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: none; }
}

.inspector-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border-soft);
}

.inspector-title {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  font-family: var(--font-display);
  font-weight: 700;
}

.inspector-close {
  width: 2rem;
  height: 2rem;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
}

.inspector-empty {
  text-align: center;
  padding: 2.5rem 1rem;
}

.inspector-empty-ico {
  width: 3.2rem;
  height: 3.2rem;
  margin: 0 auto 0.85rem;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.35rem;
}

.inspector-empty h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.inspector-kv {
  display: grid;
  gap: 0.65rem;
  margin: 0 0 1rem;
}

.inspector-kv dt {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.inspector-kv dd {
  margin: 0.15rem 0 0;
  font-size: 0.92rem;
  word-break: break-word;
}

.inspector-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
}

.inspector-section h3 {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  font-family: var(--font-display);
}

[data-inspect] {
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease;
}

tr[data-inspect]:hover {
  background: rgba(15, 143, 123, 0.04);
}

tr[data-inspect].is-selected,
.panel[data-inspect].is-selected {
  background: rgba(15, 143, 123, 0.08);
  box-shadow: inset 3px 0 0 var(--accent);
}

.top-collapse { display: none; }


.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.75rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(247, 249, 248, 0.82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.menu-btn { display: none; }

.eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 0.75rem;
}

.topbar-link {
  color: var(--muted) !important;
  text-decoration: none !important;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.topbar-link:hover {
  color: var(--text) !important;
  border-color: var(--border);
  background: var(--panel);
}

.page-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.page-hero .sub { margin-bottom: 1.25rem; }

@media (prefers-reduced-motion: reduce) {
  .page { animation: none; }
  .nav-item { transition: none; }
  .inspector { animation: none; }
}

/* —— Typography —— */
h1 {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 2.2vw, 1.9rem);
  font-weight: 750;
  letter-spacing: -0.035em;
  margin: 0 0 0.35rem;
  color: var(--text);
}

h2 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

.sub {
  color: var(--muted);
  margin: 0 0 1.4rem;
  font-size: 0.98rem;
  max-width: 42rem;
}

/* —— Surfaces —— */
.grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  padding: 1.05rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 180ms ease, border-color 180ms ease;
}

a.stat:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 143, 123, 0.35);
  text-decoration: none !important;
}

.stat .n {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat .l {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 0.25rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.panel > h2:first-child,
.panel > h3:first-child {
  margin-top: 0;
}

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

th, td {
  text-align: left;
  padding: 0.75rem 0.55rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

form.inline {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

input, select, textarea {
  background: var(--canvas-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  font: inherit;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}

textarea { min-height: 110px; resize: vertical; }

button, .btn {
  background: linear-gradient(180deg, #14a892 0%, var(--accent) 100%);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.95rem;
  font-weight: 650;
  cursor: pointer;
  font: inherit;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 6px 14px rgba(15, 143, 123, 0.22);
  transition: transform 140ms ease, filter 140ms ease;
}

button:hover, .btn:hover { filter: brightness(1.04); }
button:active { transform: translateY(1px); }

button.secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.secondary:hover { background: var(--canvas-2); filter: none; }

button:disabled { opacity: 0.55; cursor: wait; }

.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #e8eeeb;
  color: var(--muted);
}

.badge.done, .badge.positive { background: rgba(15, 138, 95, 0.12); color: var(--good); }
.badge.warn, .badge.neutral { background: rgba(180, 83, 9, 0.12); color: var(--warn); }
.badge.bad, .badge.unsubscribe { background: rgba(194, 59, 69, 0.12); color: var(--bad); }
.badge.premium { background: var(--accent-soft); color: var(--accent); }

.muted { color: var(--muted); }
.row-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }
.error { color: var(--bad); font-size: 0.9rem; margin: 0.5rem 0 0; }

.htmx-request .btn-label { opacity: 0.5; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* —— Login —— */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(800px 400px at 20% 0%, rgba(15, 143, 123, 0.18), transparent 55%),
    radial-gradient(700px 380px at 100% 100%, rgba(217, 119, 6, 0.12), transparent 50%),
    linear-gradient(160deg, var(--ink) 0%, #102824 45%, #1a3832 100%);
}

.login-box {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 1.75rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.login-box h1 {
  font-family: var(--font-display);
  margin-bottom: 0.25rem;
}

.login-box .sub { color: var(--muted); }

.sidebar-backdrop {
  display: none;
}

@media (max-width: 960px) {
  .app-body,
  .app-body.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 220ms ease;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.25);
  }

  .app-body.sidebar-collapsed .sidebar {
    width: min(280px, 86vw);
  }

  .sidebar.open { transform: translateX(0); }

  .menu-btn { display: inline-flex; }
  .top-collapse { display: none !important; }
  .sidebar-brand .collapse-btn { display: none; }

  .sidebar-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(12, 31, 28, 0.45);
    z-index: 35;
    backdrop-filter: blur(2px);
  }

  .page { padding: 1.15rem 1rem 2rem; }
  .topbar { padding: 0.75rem 1rem; }
  .topbar-actions .topbar-link:not(#inspector-toggle) { display: none; }

  .inspector {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    width: min(var(--inspector-w), 92vw);
    z-index: 45;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.18);
  }
}

@media (max-width: 640px) {
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr {
    border-bottom: 1px solid var(--border-soft);
    padding: 0.65rem 0;
  }
  td { border: 0; padding: 0.2rem 0; }
}
