:root {
  color-scheme: light;
  --bg: #f3efe3;
  --panel: #fffdf8;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #ded7c8;
  --accent: #4f70d8;
  --accent-dark: #3151b8;
  --accent-2: #9a4f13;
  --shadow: 0 24px 70px rgba(31, 41, 51, .11);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: linear-gradient(135deg, #f7f2e6, var(--bg));
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main { min-height: 100vh; }

h1 {
  margin: 0;
  max-width: 900px;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: .96;
  letter-spacing: -.045em;
}

h2 { margin: 0; font-size: 1.15rem; }
p { margin: 0; color: var(--muted); }
a { color: inherit; }
button, input, select { font: inherit; }

button {
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  background: var(--accent-dark);
  color: #fff;
  cursor: pointer;
}

button.secondary {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, .82);
  color: var(--ink);
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(100%, 560px);
  display: grid;
  gap: 20px;
  padding: clamp(24px, 5vw, 46px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 248, .92);
  box-shadow: var(--shadow);
}

.eyebrow {
  color: var(--accent-2);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

form { display: grid; gap: 8px; }
label { color: var(--ink); font-weight: 700; }
.login-row { display: flex; gap: 8px; }

input, select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
}

.error { color: #9f1239; font-weight: 700; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 20px;
  background: var(--accent);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(255,255,255,.2);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: .06em;
  line-height: 1.25;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #fff;
  color: var(--accent-dark);
  font-size: .9rem;
  letter-spacing: 0;
}

.main-nav { display: grid; gap: 18px; margin-top: 24px; }

.nav-group { display: grid; gap: 7px; }
.nav-group p {
  margin: 8px 0 2px;
  color: rgba(255,255,255,.58);
  font-size: .78rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.nav-link {
  display: block;
  border-radius: 8px;
  padding: 10px 12px;
  color: rgba(255,255,255,.84);
  text-decoration: none;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.16);
  color: #fff;
}

.page-shell {
  width: min(1280px, 100%);
  padding: 34px 22px 60px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.menu-toggle { display: none; }
.lede { margin-top: 18px; max-width: 840px; font-size: 1.05rem; }

.meta, .toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 11px;
  background: rgba(255, 253, 248, .76);
  color: var(--muted);
  font-size: .9rem;
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 13px;
  margin-top: 22px;
}

.card, .issue {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, .94);
  box-shadow: 0 14px 44px rgba(31, 41, 51, .07);
}

.card { border-radius: 14px; padding: 16px; }
.metric { font-size: 2rem; font-weight: 850; letter-spacing: -.05em; }
.label { margin-top: 4px; color: var(--muted); font-size: .9rem; }
.toolbar input { flex: 1 1 320px; }
.toolbar select { flex: 0 1 180px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 300px) 1fr;
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.issue-menu {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  background: rgba(255, 253, 248, .82);
  color: var(--ink);
  text-align: left;
}

.menu-item.active {
  border-color: rgba(79, 112, 216, .45);
  background: var(--accent-dark);
  color: #fff;
}

.menu-item span { line-height: 1.25; }
.menu-item strong {
  flex: 0 0 auto;
  min-width: 2.2rem;
  border-radius: 8px;
  padding: 3px 8px;
  background: rgba(31, 41, 51, .08);
  text-align: center;
}
.menu-item.active strong { background: rgba(255, 255, 255, .2); }

.issues { display: grid; gap: 18px; }
.issue { border-radius: 14px; overflow: hidden; margin-top: 18px; }
.workspace .issue { margin-top: 0; }

.issue-head {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.issue-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.count { color: var(--accent-2); font-weight: 850; }
.action { color: var(--accent-dark); font-weight: 700; }
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #ece5d8;
}

th {
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: #fbf8ef;
  white-space: nowrap;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-transform: inherit;
  letter-spacing: inherit;
}

.sort-button.active { color: var(--accent-dark); }

.load-more {
  display: flex;
  justify-content: center;
  padding: 16px;
}

td.context { min-width: 270px; color: var(--muted); }
.empty, .loading { padding: 18px; color: var(--muted); }
.empty-inline { color: var(--muted); }

.api-login-prompt {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.api-login-prompt h2 { color: var(--ink); }

.media-upload-panel,
.media-editor-panel {
  margin-top: 18px;
}

.media-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.media-form h3 {
  margin: 0;
  font-size: 1.02rem;
}

.media-form-grid,
.media-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.media-advanced-options {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 248, .72);
}

.media-advanced-options summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 700;
}

.advanced-grid {
  padding: 0 14px 14px;
}

.media-form label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.media-form textarea {
  min-height: 110px;
}

.media-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.media-editor-grid.simple {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

button.danger {
  border-color: #d8b4b4;
  color: #8f1d1d;
}

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: rgba(79, 112, 216, .08); }
.active-row { background: rgba(79, 112, 216, .12); cursor: pointer; }

.issue-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: .76rem;
  font-weight: 800;
  white-space: nowrap;
}

.issue-badge.real {
  background: rgba(65, 138, 91, .14);
  color: #1f6a39;
}

.issue-badge.placeholder {
  background: rgba(180, 108, 41, .14);
  color: #92561d;
}

.issue-inline-hint {
  padding: 16px 18px 18px;
  color: var(--muted);
}

.issue-modal-backdrop,
.table-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(19, 26, 34, .38);
}

.issue-modal,
.table-modal {
  width: min(780px, 100%);
  max-height: min(84vh, 860px);
  overflow: auto;
}

.issue-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.issue-modal-head .secondary {
  flex: 0 0 auto;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 22px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 13px;
  background: rgba(255, 253, 248, .82);
  color: var(--ink);
  text-decoration: none;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.detail-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  background: rgba(255, 253, 248, .94);
  box-shadow: 0 14px 44px rgba(31, 41, 51, .07);
}

details.detail-card summary {
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 850;
  letter-spacing: -.03em;
}

details.detail-card[open] summary {
  margin-bottom: 14px;
}

.detail-card.wide {
  grid-column: 1 / -1;
}

.detail-card.wide .field-row {
  grid-template-columns: 1fr;
}

.detail-card.media-preview-card .field-row {
  grid-template-columns: 1fr;
}

.detail-card.media-preview-card dt {
  display: none;
}

.detail-card.wide dd {
  white-space: normal;
}

.text-field-value {
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.55;
}

.detail-card.wide .text-field-value {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .58);
}

.product-text-tabs {
  display: grid;
  gap: 14px;
}

.product-text-tab-nav {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin-bottom: -16px;
  padding-left: 8px;
}

.product-text-tab-nav button {
  position: relative;
  z-index: 1;
  border: 1px solid var(--line);
  border-bottom-color: var(--line);
  border-radius: 12px 12px 0 0;
  padding: 10px 16px;
  background: rgba(244, 238, 226, .72);
  color: var(--muted);
  font-weight: 800;
}

.product-text-tab-nav button.active {
  z-index: 3;
  border-color: var(--line);
  border-bottom-color: rgba(255, 253, 248, .96);
  background: rgba(255, 253, 248, .96);
  color: var(--accent-dark);
  box-shadow: 0 -8px 20px rgba(31, 41, 51, .05);
}

.product-text-tab-panel {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, .96);
}

.product-text-field {
  display: grid;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid #ece5d8;
}

.product-text-field .product-text-field-label {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
}

.product-text-field .product-text-field-value {
  margin: 0;
}

.product-hashtag-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .58);
}

.calendar-editor {
  display: grid;
  gap: 12px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: minmax(120px, 1.3fr) repeat(12, minmax(44px, 1fr));
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .58);
}

.calendar-cell {
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.calendar-cell:nth-child(13n) {
  border-right: 0;
}

.calendar-head {
  background: #fbf8ef;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 850;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.calendar-cell.activity {
  justify-content: start;
  place-items: center start;
  font-weight: 800;
}

.checkbox-cell input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-dark);
}

.product-hashtag-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
}

.product-hashtag-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  font: inherit;
}

.admin-category-tree {
  display: grid;
  gap: 8px;
}

#categories-card {
  padding: 18px;
}

.admin-category-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.admin-category-row.is-hidden .linkish {
  color: #6b7280;
}

.admin-category-children {
  padding-left: 8px;
  border-left: 2px solid rgba(31, 41, 51, .08);
}

.admin-category-children[hidden] {
  display: none;
}

.muted-inline {
  color: var(--muted);
  font-size: .9rem;
}

button.linkish {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  text-align: left;
}

button.small {
  padding: 6px 10px;
  font-size: .86rem;
}

.compact-actions {
  margin-top: 0;
}

.product-image-usage-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.product-image-usage-row {
  display: grid;
  grid-template-columns: 112px 90px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .58);
}

.product-image-thumb {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,.7);
}

.product-image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.product-image-picker-results {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.product-image-result {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: rgba(255, 253, 248, .82);
  text-align: left;
  color: var(--ink);
}

.product-image-result-thumb {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255,255,255,.7);
  font-size: .8rem;
  font-weight: 800;
}

.product-image-result-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.detail-card.wide .content-html,
.detail-card.wide dd > *:first-child {
  margin-top: 0;
}

.detail-card.wide p,
.detail-card.wide ul,
.detail-card.wide ol,
.detail-card.wide blockquote,
.detail-card.wide figure {
  margin: 0 0 14px;
}

.detail-card.wide h1,
.detail-card.wide h2,
.detail-card.wide h3,
.detail-card.wide h4,
.detail-card.wide h5,
.detail-card.wide h6 {
  margin: 20px 0 8px;
  letter-spacing: -.02em;
  line-height: 1.15;
}

.detail-card.wide li {
  margin: 5px 0;
}

.detail-card.wide blockquote {
  border-left: 3px solid var(--line);
  padding-left: 14px;
  color: var(--muted);
}

.media-preview {
  display: grid;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.media-preview.compact {
  align-content: start;
}

.media-preview img {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 58vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.media-preview.compact img {
  max-height: 280px;
}

.media-preview-caption {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

.media-preview-fallback {
  display: none;
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

.media-preview-unavailable .media-preview-fallback {
  display: block;
}

.media-file-placeholder {
  min-height: 280px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 18px;
  background: rgba(255, 253, 248, .6);
}

.media-file-icon {
  display: grid;
  place-items: center;
  min-height: 180px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(182, 190, 16, .18), rgba(213, 164, 95, .18));
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 850;
  letter-spacing: .04em;
}

.detail-card dl {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(110px, .45fr) 1fr;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid #ece5d8;
}

.field-row dt {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 750;
}

.field-row dd { margin: 0; }

.detail-card,
.detail-card dd,
.detail-card p,
.detail-card a,
.detail-table td,
.table-modal td,
.issue-modal td {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.detail-tables { margin-top: 18px; }
.detail-table { margin-top: 14px; }

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(86vw, 310px);
    transform: translateX(-105%);
    transition: transform .18s ease;
    box-shadow: 20px 0 60px rgba(31, 41, 51, .2);
  }
  .sidebar.open { transform: translateX(0); }
  .page-shell { padding: 24px 12px 42px; }
  .topbar { display: grid; grid-template-columns: auto 1fr auto; align-items: start; }
  .menu-toggle { display: inline-flex; }
  .workspace { grid-template-columns: 1fr; }
  .issue-menu { position: static; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .login-row { display: grid; }
  .toolbar select { flex-basis: 100%; }
  .field-row { grid-template-columns: 1fr; gap: 4px; }
  th, td { padding: 9px 10px; }
}
