:root {
  --bg: #f3f5f8;
  --bg-soft: #ffffff;
  --ink: #1f2733;
  --muted: #607081;
  --line: #d7dde6;
  --line-strong: #b8c3d1;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --accent: #1b2430;
  --accent-soft: #44566c;
  --ok: #1b8f63;
  --err: #b23e4c;
  --shadow-xl: 0 14px 34px rgba(22, 34, 51, 0.14);
  --shadow-sm: 0 6px 16px rgba(22, 34, 51, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Oxanium', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #e6ebf2 0%, transparent 32%),
    radial-gradient(circle at 100% 0%, #edf1f7 0%, transparent 28%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(24, 34, 48, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 34, 48, 0.02) 1px, transparent 1px);
  background-size: 30px 30px;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1140px, 94vw);
  margin: 20px auto 44px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(8px);
}

.auth-panel {
  max-width: 460px;
  margin: 70px auto;
  padding: 28px;
  animation: rise 0.36s ease;
}

.auth-panel h1,
.topbar h2,
.editor h3,
.admin-head h3 {
  margin: 0;
  font-family: 'Teko', sans-serif;
  letter-spacing: 0.04em;
}

.auth-panel h1 {
  font-size: clamp(2.4rem, 8vw, 3rem);
}

.muted {
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 10px;
  margin: 20px 0;
}

.tab,
.view-tab {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.13s ease, border-color 0.13s ease, background 0.13s ease;
}

.tab:hover,
.view-tab:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.tab.active,
.view-tab.active {
  background: linear-gradient(140deg, var(--accent), #2c3948);
  border-color: #2c3948;
  color: #fff;
}

.auth-form,
.macro-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: #445468;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #8da0b6;
  box-shadow: 0 0 0 3px rgba(84, 104, 129, 0.16);
}

textarea {
  resize: vertical;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.13s ease, box-shadow 0.13s ease, border-color 0.13s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

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

.btn.primary {
  color: #fff;
  border-color: #2f3f51;
  background: linear-gradient(140deg, var(--accent), #2d3d4e);
  box-shadow: var(--shadow-sm);
}

.btn.ghost {
  background: #fff;
}

#hintsBtn {
  color: #ffffff;
  border-color: #0f8ecf;
  background: linear-gradient(140deg, #0ea5e9, #22b8f5);
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.28);
}

#hintsBtn:hover {
  border-color: #0b7fb8;
  background: linear-gradient(140deg, #0b99db, #1aaef0);
}

.hidden {
  display: none !important;
}

.site-gate-locked {
  overflow: hidden;
}

.site-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 35, 0.62);
  backdrop-filter: blur(4px);
}

.site-gate-modal {
  width: min(420px, 96vw);
  border: 1px solid #d8e0ea;
  border-radius: 14px;
  padding: 18px;
  background: #ffffff;
  box-shadow: 0 16px 36px rgba(13, 24, 36, 0.28);
}

.site-gate-modal h3 {
  margin: 0 0 6px;
}

.site-gate-modal p {
  margin: 0 0 12px;
}

.site-gate-form {
  display: grid;
  gap: 8px;
}

.site-gate-form input {
  min-height: 40px;
}

.site-gate-form .btn {
  width: 100%;
}

.site-gate-error {
  min-height: 18px;
  margin: 8px 0 0;
  color: #c74655;
  font-weight: 700;
}

.message {
  min-height: 20px;
  margin-top: 10px;
  font-weight: 700;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 15px;
  margin-bottom: 10px;
  align-items: start;
  animation: rise 0.36s ease;
}

.hero-copy h2 {
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 0.95;
  color: #131b25;
}

.brand-link {
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.brand-link:hover {
  opacity: 0.86;
}

.btn-compact {
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 2px;
  color: #8090a3;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

.nm-badge {
  display: inline-block;
  margin: 0 0 6px;
  padding: 2px 8px;
  border: 1px solid #cfd8e4;
  border-radius: 999px;
  background: #f8fafc;
  color: #526579;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hotkey-hint,
.hero-note {
  font-size: 11px;
}

.hero-note {
  max-width: 340px;
  margin: 0;
  text-align: right;
}

.hero-side {
  display: grid;
  gap: 8px;
  justify-items: end;
  align-self: start;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.topbar-actions .btn-compact {
  padding: 6px 10px;
  min-height: 34px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.filters.proposals-mode .search-wrap,
.filters.proposals-mode .category-pills {
  display: none;
}

.view-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
}

.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.suggestions button {
  width: 100%;
  border: 0;
  padding: 10px 11px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.suggestions button:hover,
.suggestions button.active {
  background: #eef3f9;
}

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

#filterCategoryPills {
  padding: 6px;
  border-color: #d7dee8;
  border-radius: 12px;
  background: #f9fbfd;
}

.pill {
  border: 1px solid #ced7e2;
  border-radius: 8px;
  padding: 7px 10px;
  background: #f9fbfd;
  color: #415264;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
}

#filterCategoryPills .pill {
  border-radius: 999px;
  padding: 7px 12px;
  border-color: #cfd8e4;
  background: #ffffff;
  color: #44586d;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

#filterCategoryPills .pill:hover {
  border-color: #b8c5d4;
  background: #f3f7fb;
}

.pill.active {
  color: #fff;
  border-color: #2f3f51;
  background: linear-gradient(140deg, var(--accent), #2d3d4e);
}

#filterCategoryPills .pill.active {
  border-color: #34495f;
  background: #2f4256;
  color: #ffffff;
}

.quick-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.editor,
.admin-panel {
  padding: 14px;
  margin-bottom: 10px;
}

.editor-lead {
  margin: 4px 0 12px;
  padding: 9px 11px;
  border: 1px dashed #9fb2c9;
  border-radius: 10px;
  background: linear-gradient(125deg, #f4f8ff 0%, #ecf4ff 100%);
  color: #40556d;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
}

.editor.proposal-mode {
  border: 1px solid #a9bfd9;
  background: radial-gradient(circle at 86% -15%, rgba(111, 155, 211, 0.24) 0, rgba(111, 155, 211, 0) 46%), linear-gradient(180deg, #f6fbff 0%, #f1f7ff 100%);
}

.editor.proposal-mode h3 {
  color: #162b45;
}

.editor.proposal-mode .macro-form {
  border: 1px solid #d1deef;
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.9);
}

.editor.proposal-mode .btn.primary {
  border-color: #214368;
  background: linear-gradient(125deg, #17324e 0%, #325c8a 100%);
}

.editor-actions,
.proposal-actions {
  display: flex;
  gap: 8px;
}

.admin-head p {
  margin: 3px 0 12px;
}

.admin-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-section {
  animation: rise 0.2s ease;
}

.admin-categories-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: #f4f7fb;
  border: 1px solid #dde3ee;
  border-radius: 8px;
  font-size: 14px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 10px;
  align-items: start;
}

.admin-stack {
  display: grid;
  gap: 10px;
}

.admin-form,
.proposal-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.admin-form h4,
.proposal-head h4 {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#adminsSummary {
  margin: 8px 0 0;
  font-size: 11px;
}

.proposal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.admin-search-row {
  margin-bottom: 10px;
}

.admin-search-row input {
  background: #fbfcfe;
}

.proposal-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

.proposal-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: #fdfefe;
}

.proposal-item h5 {
  margin: 0 0 4px;
  font-size: 15px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.proposal-item p {
  margin: 0 0 6px;
  font-size: 11px;
}

.status-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  border: 1px solid transparent;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-pending {
  color: #6a561d;
  background: #fff8e5;
  border-color: #f1dfaa;
}

.status-approved {
  color: #17563f;
  background: #e9f8f1;
  border-color: #b9e8d1;
}

.status-editor {
  color: #1f4d72;
  background: #e8f2fb;
  border-color: #b9d3ea;
}

.status-rejected {
  color: #8f2f3d;
  background: #feecf0;
  border-color: #f2bfca;
}

.proposal-item pre {
  margin: 0 0 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f9fc;
  font-size: 12px;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
}

.admin-macro-card {
  padding: 12px;
  border-color: #d7e0ea;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfd 100%);
  box-shadow: 0 6px 18px rgba(31, 45, 61, 0.05);
}

.admin-macro-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.admin-macro-top .macro-category {
  flex-shrink: 0;
}

.admin-macro-body {
  margin: 0 0 8px;
  padding: 10px 11px;
  border: 1px solid #dbe3ec;
  border-radius: 10px;
  background: #fcfdff;
  color: #35485b;
  font-size: 12px;
  line-height: 1.55;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

.admin-macro-actions {
  justify-content: flex-end;
}

.macro-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.macro-card {
  position: relative;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 62px;
  max-height: 72px;
  overflow: hidden;
  border-color: #c7d3e1;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, max-height 0.26s ease, border-color 0.2s ease;
}

.macro-card::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 54px;
  border-radius: 0 0 12px 12px;
  background: linear-gradient(180deg, rgba(247, 250, 254, 0) 0%, rgba(247, 250, 254, 0.96) 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.macro-card:hover,
.macro-card:focus-within,
.macro-card.expanded {
  transform: translateY(-2px);
  max-height: 120px;
  border-color: #8ea6c0;
  box-shadow: var(--shadow-xl);
}

.macro-card:hover::after,
.macro-card:focus-within::after,
.macro-card.expanded::after {
  opacity: 1;
}

.macro-card.copied {
  border-color: #5e91bf;
  box-shadow: 0 0 0 2px rgba(94, 145, 191, 0.22), var(--shadow-xl);
}

.macro-card.is-collapsing {
  transform: translateY(0) !important;
  max-height: 72px !important;
}

.macro-card.is-collapsing::after {
  opacity: 0 !important;
}

.macro-card:focus-visible {
  outline: 2px solid #8fa2b8;
  outline-offset: 2px;
}

.macro-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.macro-title {
  margin: 0;
  font-size: 1.03rem;
  line-height: 1.12;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.macro-meta,
.macro-category,
.macro-hover-hint,
.macro-tags {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.macro-category {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid #d4dbe6;
  background: #f6f8fb;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4c5f74;
  font-weight: 700;
}

.macro-meta,
.macro-category,
.macro-hover-hint,
.macro-body,
.macro-tags,
.macro-actions,
.favorite-btn {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.macro-card:hover .macro-meta,
.macro-card:hover .macro-category,
.macro-card:hover .macro-hover-hint,
.macro-card:hover .macro-tags,
.macro-card:hover .macro-actions,
.macro-card:hover .favorite-btn,
.macro-card:focus-within .macro-meta,
.macro-card:focus-within .macro-category,
.macro-card:focus-within .macro-hover-hint,
.macro-card:focus-within .macro-tags,
.macro-card:focus-within .macro-actions,
.macro-card:focus-within .favorite-btn,
.macro-card.expanded .macro-meta,
.macro-card.expanded .macro-category,
.macro-card.expanded .macro-hover-hint,
.macro-card.expanded .macro-tags,
.macro-card.expanded .macro-actions,
.macro-card.expanded .favorite-btn {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.macro-card.is-collapsing .macro-meta,
.macro-card.is-collapsing .macro-category,
.macro-card.is-collapsing .macro-hover-hint,
.macro-card.is-collapsing .macro-body,
.macro-card.is-collapsing .macro-tags,
.macro-card.is-collapsing .macro-actions,
.macro-card.is-collapsing .favorite-btn {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.macro-body {
  display: none;
  margin: 0;
  padding: 10px 10px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fbff 0%, #f1f6fd 100%);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  color: #2a3a4e;
  white-space: pre-wrap;
  max-height: 184px;
  overflow: hidden;
}

.macro-card:hover .macro-body,
.macro-card:focus-within .macro-body,
.macro-card.expanded .macro-body {
  display: none;
  max-height: 0;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #cad6e5;
}

.macro-preview-popover {
  position: fixed;
  z-index: 1100;
  width: min(420px, calc(100vw - 24px));
  border: 1px solid #b6c7d8;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  box-shadow: 0 20px 46px rgba(23, 39, 58, 0.24);
  padding: 12px;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.macro-preview-popover.visible {
  opacity: 1;
  transform: translateY(0);
}

.macro-preview-title {
  margin: 0 0 4px;
  font-size: 16px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #1e2d40;
}

.macro-preview-category,
.macro-preview-tags {
  margin: 0 0 8px;
  font-size: 11px;
  color: #5d6e82;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.macro-preview-body {
  margin: 0;
  padding: 10px;
  border: 1px solid #c5d4e3;
  border-radius: 10px;
  background: #f2f7fd;
  color: #2b3b4f;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: min(54vh, 420px);
  overflow: auto;
}

mark.search-hit {
  padding: 0 2px;
  border-radius: 3px;
  background: #fff3b8;
  color: inherit;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: #607082;
  cursor: pointer;
  font-size: 14px;
}

.icon-btn.active {
  color: #16202d;
  border-color: #768ca5;
}

.macro-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 880px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-side {
    justify-items: start;
  }

  .hero-note {
    text-align: left;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .layout {
    width: min(96vw, 1120px);
    margin-top: 12px;
  }

  .macro-preview-popover {
    display: none !important;
  }

  .macro-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .editor-actions,
  .macro-actions,
  .proposal-actions {
    width: 100%;
    grid-template-columns: 1fr;
  }
}
