:root {
  --background: #ffffff;
  --foreground: #111827;
  --card: #ffffff;
  --card-foreground: #111827;
  --popover: #ffffff;
  --popover-foreground: #111827;
  --primary: #d87943;
  --primary-foreground: #ffffff;
  --secondary: #527575;
  --secondary-foreground: #ffffff;
  --muted: #f3f4f6;
  --muted-foreground: #6b7280;
  --accent: #eeeeee;
  --accent-foreground: #111827;
  --destructive: #ef4444;
  --destructive-foreground: #fafafa;
  --border: #e5e7eb;
  --input: #e5e7eb;
  --ring: #d87943;
  --sidebar: #f3f4f6;
  --sidebar-foreground: #111827;
  --sidebar-primary: #d87943;
  --sidebar-primary-foreground: #ffffff;
  --sidebar-accent: #ffffff;
  --sidebar-accent-foreground: #111827;
  --sidebar-border: #e5e7eb;
  --sidebar-ring: #d87943;
  --publish-green: #84cc16;
  --publish-green-hover: #65a30d;
  --font-sans: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --radius: 0.75rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--background);
  color: var(--foreground);
  margin: 0;
}

#sidebar {
  background-color: #212121 !important;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

[data-shared-header] {
  background-color: var(--muted) !important;
}

.btn-publish {
  background-color: var(--publish-green) !important;
  color: #ffffff !important;
}

.btn-publish:hover {
  background-color: var(--publish-green-hover) !important;
}

.btn-dark-action {
  background-color: #212121 !important;
  color: #ffffff !important;
  border: 1px solid #212121 !important;
}

.btn-dark-action:hover {
  background-color: #2d2d2d !important;
  border-color: #2d2d2d !important;
}

.glass-panel {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.editor-scroll::-webkit-scrollbar {
  width: 6px;
}

.editor-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.editor-scroll::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 9999px;
}

.kpi-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ascii-diagram {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  white-space: pre;
  overflow-x: auto;
  font-size: 0.75rem;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: #fbfbfb;
  padding: 1rem;
}

body.cms-media-modal-open {
  overflow: hidden;
}

.cms-rich-text {
  outline: none;
  line-height: 1.6;
  word-break: break-word;
}

.cms-rich-text:empty::before {
  content: attr(data-placeholder);
  color: var(--muted-foreground);
  pointer-events: none;
}

.cms-rich-text:focus {
  box-shadow: 0 0 0 2px var(--ring);
  border-radius: 0.5rem;
}

.cms-rich-text h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0.75rem 0 0.5rem;
}

.cms-rich-text h2 {
  font-size: 1.375rem;
  font-weight: 700;
  margin: 0.75rem 0 0.5rem;
}

.cms-rich-text h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0.5rem 0 0.35rem;
}

.cms-rich-text p {
  margin: 0.5rem 0;
}

.cms-rich-text blockquote {
  border-left: 3px solid var(--border);
  margin: 0.75rem 0;
  padding-left: 0.75rem;
  color: var(--muted-foreground);
}

.cms-rich-text ul,
.cms-rich-text ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.cms-rich-text a {
  color: var(--primary);
  text-decoration: underline;
}

.cms-rich-text img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
}

.cms-media-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.cms-media-modal.hidden {
  display: none;
}

.cms-media-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
}

.cms-media-modal__panel {
  position: relative;
  width: min(960px, 100%);
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.cms-media-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.cms-media-modal__close {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--background);
  color: var(--muted-foreground);
  cursor: pointer;
}

.cms-media-modal__close:hover {
  background: var(--muted);
  color: var(--foreground);
}

.cms-media-modal__toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
}

.cms-media-modal__search {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--background);
  font-size: 0.875rem;
}

.cms-media-modal__upload {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
}

.cms-media-modal__upload input {
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--background);
  font-size: 0.875rem;
}

.cms-media-modal__grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  align-content: start;
}

.cms-media-modal__item {
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--background);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cms-media-modal__item:hover {
  border-color: var(--primary);
}

.cms-media-modal__item.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(216, 121, 67, 0.25);
}

.cms-media-modal__item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--muted);
}

.cms-media-modal__item-label {
  padding: 0.5rem;
  font-size: 0.6875rem;
  line-height: 1.2;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cms-media-modal__empty {
  grid-column: 1 / -1;
  font-size: 0.875rem;
  color: var(--muted-foreground);
  padding: 2rem 1rem;
  text-align: center;
}

.cms-media-modal__count {
  margin: 0;
  padding: 0.75rem 1.5rem 1rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  .cms-media-modal {
    padding: 0.75rem;
  }

  .cms-media-modal__upload {
    grid-template-columns: 1fr;
  }
}
