:root {
  --canvas: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #edf2f8;
  --ink: #172033;
  --muted: #667085;
  --line: #dbe2ec;
  --accent: #2f6bff;
  --accent-soft: #e9efff;
  --success: #178b65;
  --warning: #c85b38;
  --danger: #c33d4b;
  --sidebar: #101827;
  --sidebar-muted: #98a2b3;
  --shadow: 0 16px 40px rgb(27 39 61 / 8%);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--canvas); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent);
  outline-offset: 2px;
}

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
}
.auth-screen h1 { margin: 8px 0 0; font: 700 30px/1.1 "Avenir Next", Inter, sans-serif; letter-spacing: -.04em; }
.auth-screen p { margin: 0 0 14px; color: var(--muted); }
.auth-mark, .product-glyph {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 13px 5px 13px 5px;
  color: #fff;
  background: var(--accent);
  font: 800 15px/1 "SFMono-Regular", Consolas, monospace;
  letter-spacing: -.08em;
}

.shell { min-height: 100dvh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: 252px;
  flex-direction: column;
  padding: 24px 18px 20px;
  color: #fff;
  background: var(--sidebar);
}
.product-mark { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.product-mark .product-glyph { width: 40px; height: 40px; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 30%, transparent); }
.product-mark strong { display: block; font: 700 16px/1.1 "Avenir Next", Inter, sans-serif; }
.product-mark small, .sidebar-footer small { display: block; margin-top: 4px; color: var(--sidebar-muted); font-size: 11px; letter-spacing: .04em; }
.nav { display: grid; gap: 5px; }
.nav-item {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  color: #cbd3df;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.nav-item > span { width: 21px; color: #8793a6; font: 700 18px/1 "SFMono-Regular", monospace; text-align: center; }
.nav-item:hover { color: #fff; background: rgb(255 255 255 / 5%); }
.nav-item.active { color: #fff; background: color-mix(in srgb, var(--accent) 28%, #172034); }
.nav-item.active > span { color: #fff; }
.nav-badge { margin-left: auto; padding: 2px 7px; border-radius: 999px; color: #fff; background: var(--danger); font-size: 11px; }
.sidebar-footer { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgb(255 255 255 / 8%); }
.sidebar-footer strong { display: block; font-size: 13px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #45d49d; box-shadow: 0 0 0 5px rgb(69 212 157 / 12%); }

.workspace { min-height: 100dvh; margin-left: 252px; }
.identity-rail {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 34px;
  border-bottom: 1px solid var(--line);
  background: rgb(244 247 251 / 92%);
  backdrop-filter: blur(14px);
}
.identity-copy { display: flex; align-items: baseline; gap: 10px; }
.identity-copy .eyebrow { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.identity-copy strong { font: 700 19px/1 "Avenir Next", Inter, sans-serif; letter-spacing: -.02em; }
.live-pill { padding: 3px 7px; border-radius: 5px; color: #087653; background: #dff6ed; font: 800 10px/1 "SFMono-Regular", monospace; letter-spacing: .08em; }
.identity-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); cursor: pointer; }
.icon-button:hover { border-color: var(--accent); color: var(--accent); }

.content { max-width: 1220px; margin: 0 auto; padding: 34px 34px 72px; }
.content:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-head h1 { margin: 0; font: 700 30px/1.08 "Avenir Next", Inter, sans-serif; letter-spacing: -.045em; }
.page-head p { max-width: 640px; margin: 8px 0 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.button {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  font-weight: 650;
}
.button:hover { border-color: color-mix(in srgb, var(--accent) 58%, var(--line)); }
.button.primary { border-color: var(--accent); color: #fff; background: var(--accent); }
.button.danger { border-color: #f0cbd0; color: var(--danger); background: #fff8f9; }
.button.small { min-height: 34px; padding: 0 11px; font-size: 13px; }
.button:disabled { opacity: .5; cursor: not-allowed; }

.operations-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.operation-stat { min-height: 116px; padding: 22px; border-right: 1px solid var(--line); cursor: pointer; }
.operation-stat:last-child { border-right: 0; }
.operation-stat:hover { background: #fafcff; }
.operation-stat strong { display: block; margin: 3px 0 6px; font: 700 30px/1 "Avenir Next", Inter, sans-serif; letter-spacing: -.04em; }
.operation-stat span { color: var(--muted); font-size: 12px; }
.operation-stat small { color: var(--accent); font-weight: 650; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 28px rgb(27 39 61 / 5%); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font: 700 17px/1.2 "Avenir Next", Inter, sans-serif; letter-spacing: -.02em; }
.panel-body { padding: 20px; }
.metric-list { display: grid; gap: 0; }
.metric-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 48px; border-bottom: 1px solid var(--line); }
.metric-row:last-child { border-bottom: 0; }
.metric-row span { color: var(--muted); }
.metric-row strong { font-variant-numeric: tabular-nums; }
.status-good { color: var(--success); }
.status-warn { color: var(--warning); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.field { display: grid; gap: 7px; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field textarea, .field select, .search-input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
}
.field textarea { min-height: 120px; resize: vertical; }
.search-input { max-width: 360px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .wide { grid-column: 1 / -1; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #fafcff; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdff; }
.person { display: flex; align-items: center; gap: 11px; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 800; }
.person strong, .person small { display: block; }
.person small, .muted { color: var(--muted); }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 999px; color: #526071; background: #edf1f5; font-size: 11px; font-weight: 700; }
.badge.good { color: #087653; background: #dff6ed; }
.badge.warn { color: #97441e; background: #fff0e7; }
.badge.danger { color: #a5293a; background: #fdecef; }

.inbox-layout { display: grid; grid-template-columns: minmax(290px, 36%) 1fr; min-height: 650px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.thread-list { border-right: 1px solid var(--line); }
.thread-list-head { padding: 16px; border-bottom: 1px solid var(--line); }
.thread-items { max-height: 594px; overflow: auto; }
.thread-item { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); color: var(--ink); background: #fff; cursor: pointer; text-align: left; }
.thread-item:hover, .thread-item.active { background: #f5f8ff; }
.thread-copy { min-width: 0; }
.thread-copy strong, .thread-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-copy span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.thread-meta { display: grid; justify-items: end; gap: 5px; color: var(--muted); font-size: 10px; }
.unread { display: grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; color: #fff; background: var(--accent); font-size: 10px; font-weight: 800; }
.chat { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.chat-messages { display: flex; flex-direction: column; gap: 10px; max-height: 500px; padding: 20px; overflow: auto; background: #f8fafd; }
.message { max-width: min(76%, 620px); padding: 10px 13px; border: 1px solid var(--line); border-radius: 13px 13px 13px 4px; background: #fff; box-shadow: 0 5px 14px rgb(27 39 61 / 4%); }
.message.outbound { align-self: flex-end; border-color: color-mix(in srgb, var(--accent) 20%, var(--line)); border-radius: 13px 13px 4px 13px; background: var(--accent-soft); }
.message p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.message small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; text-align: right; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line); }
.chat-form textarea { min-height: 46px; max-height: 130px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
.empty-state { display: grid; min-height: 280px; place-content: center; justify-items: center; padding: 32px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); font: 700 18px/1.2 "Avenir Next", Inter, sans-serif; }

.item-stack { display: grid; gap: 12px; }
.editable-item { display: grid; grid-template-columns: 42px minmax(150px, .8fr) minmax(260px, 1.5fr) 88px auto; align-items: end; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.drag-index { display: grid; place-items: center; width: 38px; height: 42px; color: var(--muted); font: 700 12px/1 monospace; }
.item-actions { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

.danger-zone { border-color: #efcfd4; background: #fffafb; }
.safety-note { display: flex; gap: 10px; padding: 12px 14px; border: 1px solid #f0d4b9; border-radius: 10px; color: #7b4a20; background: #fff9f0; font-size: 13px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: 380px; padding: 12px 16px; border-radius: 10px; color: #fff; background: var(--ink); box-shadow: 0 14px 36px rgb(16 24 39 / 22%); }
.toast.error { background: var(--danger); }
.skeleton { min-height: 90px; border-radius: 12px; background: linear-gradient(90deg, #edf1f6, #f8fafc, #edf1f6); background-size: 200% 100%; animation: skeleton 1.2s linear infinite; }
@keyframes skeleton { to { background-position: -200% 0; } }
.mobile-nav { display: none; }

@media (max-width: 920px) {
  .sidebar { display: none; }
  .workspace { margin-left: 0; }
  .identity-rail { min-height: 64px; padding: 10px 16px; }
  .identity-copy .eyebrow, .identity-meta > span { display: none; }
  .content { padding: 24px 16px calc(94px + var(--safe-bottom)); }
  .operations-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .operation-stat:nth-child(2) { border-right: 0; }
  .operation-stat:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .grid.two, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    min-height: calc(66px + var(--safe-bottom));
    padding: 6px 4px var(--safe-bottom);
    border-top: 1px solid var(--line);
    background: rgb(255 255 255 / 96%);
    backdrop-filter: blur(14px);
  }
  .mobile-nav-item { display: grid; place-items: center; gap: 2px; border: 0; color: var(--muted); background: transparent; font-size: 10px; }
  .mobile-nav-item span { font: 700 20px/1 monospace; }
  .mobile-nav-item.active { color: var(--accent); }
  .page-head { align-items: flex-start; flex-direction: column; }
  .inbox-layout { display: block; min-height: 0; }
  .thread-list { border-right: 0; }
  .thread-items { max-height: none; }
  .chat { min-height: 620px; }
  .chat[hidden] { display: none; }
  .inbox-layout.chat-open .thread-list { display: none; }
  .editable-item { grid-template-columns: 38px 1fr; }
  .editable-item .url-field, .editable-item .position-field, .editable-item .item-actions { grid-column: 2; }
}

@media (max-width: 520px) {
  .content { padding-inline: 12px; }
  .identity-rail { padding-inline: 12px; }
  .operations-strip { box-shadow: none; }
  .operation-stat { min-height: 100px; padding: 17px; }
  .operation-stat strong { font-size: 26px; }
  .panel-head, .panel-body { padding: 16px; }
  .message { max-width: 88%; }
  .chat-form { grid-template-columns: 1fr; }
  .chat-form .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
