:root {
  --bg: #12100d;
  --panel: #1c1915;
  --panel-2: #242018;
  --line: rgba(255, 244, 222, 0.12);
  --text: #f6efe2;
  --muted: #b8aa95;
  --red: #d84a63;
  --teal: #35a47c;
  --gold: #c8973f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(135deg, #12100d, #191510 52%, #10120f);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-pending .admin-shell { display: none; }

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

select { color-scheme: dark; }
select option { color: var(--text); background: #171410; }

.admin-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  overflow: auto;
  background: rgba(18, 16, 13, 0.86);
}

.brand {
  display: flex;
  align-items: center;
  width: 100%;
  margin-bottom: 24px;
  color: var(--text);
  text-decoration: none;
}

.brand-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(216, 74, 99, 0.42);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(216, 74, 99, 0.28), rgba(53, 164, 124, 0.18));
  font-weight: 900;
}

.brand strong, .brand small { display: block; }
.brand small, .eyebrow, .account-box span, .status, .post-id {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.account-box, .filters, .editor label {
  display: grid;
  gap: 8px;
}

.account-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 244, 222, 0.04);
}

.account-box strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filters {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
  color: var(--text);
  background: rgba(255, 244, 222, 0.06);
}

select {
  appearance: none;
  padding-right: 38px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 19px) 50% / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 13px) 50% / 6px 6px no-repeat,
    rgba(255, 244, 222, 0.06);
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(53, 164, 124, 0.68);
}

.primary, .secondary, .danger {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(255, 244, 222, 0.04);
}

.primary {
  border-color: transparent;
  background: var(--red);
  color: white;
  font-weight: 900;
}

.secondary:hover, .danger:hover { background: rgba(255, 244, 222, 0.08); }
.danger { border-color: rgba(216, 74, 99, 0.38); color: #ffd4dc; }

#adminLogout, #newPost { width: 100%; margin-top: 10px; }

#reloadAll { width: 100%; margin-top: 10px; }

.admin-nav {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.admin-tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  text-align: left;
  background: rgba(255, 244, 222, 0.04);
}

.admin-tab.active, .admin-tab:hover {
  border-color: rgba(216, 74, 99, 0.52);
  background: rgba(216, 74, 99, 0.14);
}

.admin-main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 3vw, 34px) 52px;
}

.admin-topbar {
  display: flex;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(28, 25, 21, 0.86);
}

.stat-card strong {
  display: block;
  font-size: 1.5rem;
}

.admin-view { display: none; }
.active-admin-view { display: block; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2.2rem, 5vw, 4rem); line-height: 0.95; }
h2 { margin-bottom: 0; }

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.post-list, .editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 25, 21, 0.86);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
}

.table-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.table-tools input, .table-tools select { max-width: 280px; }

.data-list {
  display: grid;
  gap: 10px;
}

.data-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(28, 25, 21, 0.86);
}

.data-row h3 {
  margin: 0 0 6px;
}

.data-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.ticket-message {
  white-space: pre-wrap;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions select { min-width: 128px; }

.chat-admin-list .data-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.post-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 10px;
}

.post-item {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px;
  color: var(--text);
  text-align: left;
  background: rgba(255, 244, 222, 0.04);
}

.post-item.active, .post-item:hover {
  border-color: rgba(216, 74, 99, 0.52);
  background: rgba(216, 74, 99, 0.13);
}

.thumb {
  width: 74px;
  height: 56px;
  border-radius: 7px;
  object-fit: cover;
  background: linear-gradient(145deg, #4d3130, #15372f 62%, #0f0d0b);
}

.post-item strong, .post-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-item small { color: var(--muted); line-height: 1.45; }

.badge-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.badge {
  min-height: 22px;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  background: rgba(255, 244, 222, 0.08);
}
.badge.warn { color: #ffd29e; background: rgba(255, 178, 92, 0.16); }

.editor {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.editor-head {
  display: flex;
  gap: 12px;
  align-items: end;
  justify-content: space-between;
}

.field-grid { display: grid; gap: 12px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field-grid.compact input { min-height: 40px; }

.flag-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 244, 222, 0.04);
}

.flag-panel span {
  margin-right: auto;
  color: var(--muted);
  font-weight: 900;
}

.flag-panel label {
  display: inline-flex;
  width: auto;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.flag-panel input { width: auto; min-height: 0; }

.tag-picker {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 244, 222, 0.04);
}

.tag-picker-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 900;
}

.tag-add-row {
  display: grid;
  grid-template-columns: minmax(140px, 220px) auto;
  gap: 8px;
}

.tag-add-row input { min-height: 38px; }

.tag-pool {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(246, 239, 226, 0.22) transparent;
}

.tag-pool::-webkit-scrollbar {
  height: 7px;
}

.tag-pool::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(246, 239, 226, 0.2);
}

.tag-option {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(255, 244, 222, 0.05);
}

.tag-option span {
  color: var(--muted);
  font-size: 0.75rem;
}

.tag-option.active {
  border-color: rgba(216, 74, 99, 0.58);
  background: rgba(216, 74, 99, 0.18);
}

.empty-tags {
  color: var(--muted);
  font-size: 0.9rem;
}

.preview-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

figure { margin: 0; }
figure span { display: block; margin-bottom: 8px; color: var(--muted); font-weight: 800; }

.preview-frame {
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 244, 222, 0.04);
}

.categories-editor {
  max-width: 980px;
}

.category-editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.category-editor-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 244, 222, 0.04);
}

.category-preview-frame {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  aspect-ratio: 4 / 3;
  color: var(--muted);
  background: rgba(18, 16, 13, 0.65);
}

.category-preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.preview-frame img[src] { display: block; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions .primary { min-width: 160px; }

@media (max-width: 1050px) {
  .admin-shell { display: block; }
  .admin-sidebar { position: static; height: auto; }
  .workspace { grid-template-columns: 1fr; }
  .post-list { max-height: 420px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .field-grid.two, .field-grid.three, .field-grid.four, .preview-row { grid-template-columns: 1fr; }
  .admin-topbar, .editor-head { display: grid; align-items: start; }
  .stat-grid, .data-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
}
