:root {
  --bg: #faf7f1;
  --surface: #ffffff;
  --ink: #1f1a14;
  --muted: #6e685f;
  --border: #eae5dd;
  --gold: #e5a82b;
  --gold-soft: #fdf3d7;
  --gold-ink: #7a5306;
  --danger: #dc2626;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--gold);
  color: var(--ink);
}

.btn-primary:hover {
  background: #d89b1e;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.btn-secondary:hover {
  background: #f5f0e6;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: rgba(31, 26, 20, 0.06);
  color: var(--ink);
}

.btn-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.btn-danger:hover {
  background: #fee2e2;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold-ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(31, 26, 20, 0.07);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.auth-card p {
  margin: 0 0 20px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
}

.auth-form label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

.auth-form input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: inherit;
  font-size: 14px;
  margin-bottom: 14px;
}

.error-text {
  color: var(--danger);
  font-size: 12.5px;
  margin: -6px 0 12px !important;
}

/* Studio Shell */
.studio-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.save-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

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

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  gap: 18px;
  padding: 18px 20px 32px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
}

/* Left Sidebar */
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 94px);
  position: sticky;
  top: 76px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.sidebar-filters input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 10px;
}

.filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--bg);
  padding: 3px;
  border-radius: 10px;
  margin-bottom: 12px;
}

.filter-tab {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.filter-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(31, 26, 20, 0.08);
}

.posts-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-item {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.14s ease;
}

.post-item:hover {
  border-color: #d7ccb8;
  background: #fcfaf5;
}

.post-item.is-selected {
  border-color: var(--gold);
  background: var(--gold-soft);
}

.post-item-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 5px;
  line-height: 1.35;
}

.post-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.status-dot.is-published {
  color: var(--success);
}

.status-dot.is-draft {
  color: var(--gold-ink);
}

/* Main Editor */
.editor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 94px);
}

.title-wrap {
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.title-input {
  width: 100%;
  border: 0;
  outline: none;
  font-family: inherit;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  background: transparent;
  margin-bottom: 8px;
}

.slug-row {
  display: flex;
  align-items: center;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
}

.slug-input {
  flex: 1;
  min-width: 80px;
  border: 0;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 16px;
  background: #fcfaf6;
  border-bottom: 1px solid var(--border);
}

.toolbar button {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.toolbar button:hover {
  background: var(--gold-soft);
  border-color: #f2dc9b;
}

.toolbar button.is-active {
  background: var(--ink);
  color: #ffffff;
}

.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

.tb-spacer {
  flex: 1;
}

.rich-editor {
  flex: 1;
  padding: 24px;
  outline: none;
  font-size: 15.5px;
  line-height: 1.75;
  color: #262018;
  min-height: 440px;
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: #a69c8e;
}

.rich-editor h2 {
  font-size: 21px;
  margin: 22px 0 10px;
}

.rich-editor h3 {
  font-size: 17px;
  margin: 18px 0 8px;
}

.rich-editor blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--gold);
  background: var(--bg);
  border-radius: 0 10px 10px 0;
}

.rich-editor img {
  max-width: 100%;
  border-radius: 12px;
  margin: 12px 0;
}

.html-editor {
  flex: 1;
  width: 100%;
  min-height: 440px;
  border: 0;
  outline: none;
  padding: 20px 24px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

/* Right Inspector */
.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inspector-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
}

.inspector-card h3 {
  margin: 0 0 14px;
  font-size: 14.5px;
  font-weight: 700;
}

.field {
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
}

.seo-preview {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.seo-preview-url {
  font-size: 11px;
  color: #166534;
  margin-bottom: 3px;
  word-break: break-all;
}

.seo-preview-title {
  font-size: 14px;
  font-weight: 600;
  color: #1a0dab;
  margin-bottom: 3px;
}

.seo-preview-desc {
  font-size: 12px;
  line-height: 1.45;
  color: #4d5156;
}

/* Preview Modal */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(18, 15, 11, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.preview-dialog {
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
}

.preview-body {
  padding: 28px 32px;
  overflow-y: auto;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 12px;
}

.preview-body h1 {
  margin: 0 0 18px;
  font-size: 30px;
  line-height: 1.2;
}

.preview-cover {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 20px;
}

.preview-content {
  font-size: 15.5px;
  line-height: 1.75;
  color: #262018;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  background: var(--ink);
  color: #ffffff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: 300px;
  }
}
