@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --color-bg: #fbfaf7;
  --color-surface: #ffffff;
  --color-surface-alt: #f3f1ea;
  --color-border: #e6e2d8;
  --color-border-strong: #d4cfc1;
  --color-ink: #1c2521;
  --color-ink-soft: #4a544e;
  --color-accent: #1f5e4f;
  --color-accent-deep: #163f35;
  --color-accent-soft: #e7efe9;
  --color-accent-contrast: #ffffff;
  --color-gold: #b08d4f;
  --color-focus: #2f7d6a;
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-xl: 22px;
  --radius-full: 999px;
  --shadow-sm: 0 2px 8px rgba(28, 37, 33, 0.06);
  --shadow-md: 0 8px 24px rgba(28, 37, 33, 0.08);
  --shadow-lg: 0 20px 48px rgba(28, 37, 33, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-fast: 140ms var(--ease);
  --transition: 240ms var(--ease);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-focus) 32%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--color-accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.72fr);
  min-height: 100dvh;
}

.login-panel {
  align-self: center;
  width: min(100%, 520px);
  margin-left: clamp(24px, 10vw, 160px);
  padding: 48px 32px 48px 0;
}

.brand-mark {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 32px;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}

.brand-mark svg {
  width: 42px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.login-panel h1,
.workspace h2,
.dialog-head h2 {
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.1;
  letter-spacing: -0.035em;
}

.login-copy {
  max-width: 52ch;
  margin: 20px 0 32px;
  color: var(--color-ink-soft);
  font-size: 16px;
  line-height: 1.7;
}

.login-aside {
  display: flex;
  min-height: 100%;
  padding: 64px;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--color-accent-deep);
  color: var(--color-accent-contrast);
}

.login-aside-line {
  width: 72px;
  height: 2px;
  margin-bottom: 24px;
  background: var(--color-gold);
}

.login-aside p {
  margin: 7px 0;
  color: color-mix(in srgb, var(--color-accent-contrast) 78%, transparent);
  font-size: clamp(22px, 2.4vw, 34px);
  font-weight: 500;
  letter-spacing: -0.025em;
}

.form-stack,
.form-fields {
  display: grid;
  gap: 20px;
}

.field {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  font-weight: 700;
}

.field-help {
  margin-top: -2px;
  color: var(--color-ink-soft);
  font-size: 12px;
  line-height: 1.5;
}

.field input,
.field textarea,
.field select,
.rich-editor {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.field input:hover,
.field textarea:hover,
.field select:hover,
.rich-editor:hover {
  border-color: var(--color-accent);
}

.field textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}

.field input:disabled {
  background: var(--color-surface-alt);
  color: var(--color-ink-soft);
  cursor: not-allowed;
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.checkbox-field input {
  width: 19px;
  height: 19px;
  margin-top: 1px;
  accent-color: var(--color-accent);
}

.button,
.icon-button {
  border: 0;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition-fast), border-color var(--transition);
}

.button {
  display: inline-flex;
  min-height: 42px;
  padding: 10px 17px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
}

.button svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

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

.button:active,
.icon-button:active {
  transform: translateY(1px) scale(0.99);
}

.button:disabled {
  cursor: wait;
  opacity: 0.6;
  transform: none;
}

.button-primary {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.button-primary:hover {
  background: var(--color-accent-deep);
}

.button-quiet {
  border-color: var(--color-border);
  background: var(--color-surface);
  color: var(--color-ink);
}

.button-danger {
  border-color: var(--color-border-strong);
  background: var(--color-surface-alt);
  color: var(--color-accent-deep);
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.icon-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.form-error {
  margin: 0;
  padding: 11px 13px;
  border-left: 3px solid var(--color-accent-deep);
  background: var(--color-surface-alt);
  color: var(--color-ink);
  font-size: 13px;
  line-height: 1.5;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  grid-template-rows: 76px minmax(0, 1fr);
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  grid-column: 1 / -1;
  padding: 0 28px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-bg) 94%, transparent);
  backdrop-filter: blur(18px);
}

.app-name {
  font-size: 17px;
  letter-spacing: -0.02em;
}

.menu-button {
  display: none;
}

.header-actions,
.dialog-actions,
.dialog-actions-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.publish-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-ink-soft);
  font-size: 12px;
  font-weight: 600;
}

.publish-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
}

.publish-state[data-state="success"] .publish-dot {
  background: var(--color-accent);
}

.publish-state[data-state="building"] .publish-dot,
.publish-state[data-state="publishing"] .publish-dot {
  background: var(--color-gold);
  animation: breathe 1.6s var(--ease) infinite;
}

.publish-state[data-state="error"] .publish-dot {
  background: var(--color-accent-deep);
}

@keyframes breathe {
  50% { transform: scale(1.45); opacity: 0.55; }
}

.sidebar {
  position: sticky;
  top: 76px;
  display: flex;
  height: calc(100dvh - 76px);
  padding: 24px 16px;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  overflow-y: auto;
}

.collection-nav {
  display: grid;
  gap: 5px;
}

.collection-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-ink-soft);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.collection-button:hover {
  background: var(--color-surface-alt);
  color: var(--color-ink);
}

.collection-button[aria-current="page"] {
  background: var(--color-accent-soft);
  color: var(--color-accent-deep);
}

.collection-count {
  min-width: 26px;
  padding: 3px 7px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, currentColor 10%, transparent);
  font-size: 11px;
  text-align: center;
}

.sidebar-note {
  display: grid;
  padding: 16px 12px 4px;
  gap: 3px;
  border-top: 1px solid var(--color-border);
  font-size: 12px;
}

.sidebar-note span {
  color: var(--color-ink-soft);
  overflow-wrap: anywhere;
}

.workspace {
  width: min(100%, 1260px);
  padding: clamp(28px, 5vw, 64px);
}

.workspace-head {
  display: flex;
  margin-bottom: 34px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.workspace h2 {
  font-size: clamp(27px, 3vw, 38px);
}

.dialog-head h2 {
  max-width: 34ch;
  font-size: clamp(24px, 2.2vw, 32px);
  overflow-wrap: anywhere;
}

.section-description {
  max-width: 68ch;
  margin: 12px 0 0;
  color: var(--color-ink-soft);
  font-size: 14px;
  line-height: 1.65;
}

.notice {
  margin-bottom: 22px;
  padding: 13px 16px;
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: 13px;
}

.notice[data-kind="error"] {
  border-left-color: var(--color-accent-deep);
  color: var(--color-ink);
}

.record-list {
  border-top: 1px solid var(--color-border-strong);
}

.record-row {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 78px;
  padding: 17px 4px;
  align-items: center;
  gap: 20px;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: padding var(--transition), background var(--transition-fast);
  animation: enter 320ms var(--ease) both;
  animation-delay: calc(var(--index) * 35ms);
}

.record-row:hover {
  padding-right: 12px;
  padding-left: 12px;
  background: var(--color-surface);
}

@keyframes enter {
  from { transform: translateY(7px); opacity: 0; }
}

.record-main {
  min-width: 0;
}

.record-title {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-meta {
  display: flex;
  margin-top: 7px;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 12px;
  color: var(--color-ink-soft);
  font-size: 11px;
}

.record-badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--color-accent-soft);
  color: var(--color-accent-deep);
  font-weight: 700;
}

.record-badge.draft {
  background: var(--color-gold);
  color: var(--color-accent-contrast);
}

.row-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-accent);
  font-size: 12px;
  font-weight: 700;
}

.row-action svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.empty-state {
  max-width: 580px;
  padding: 54px 0;
  border-top: 1px solid var(--color-border);
}

.empty-state svg {
  width: 46px;
  margin-bottom: 18px;
  fill: none;
  stroke: var(--color-accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.empty-state h3 {
  margin: 0 0 10px;
  font-size: 20px;
}

.empty-state p {
  max-width: 48ch;
  margin: 0;
  color: var(--color-ink-soft);
  line-height: 1.65;
}

.loading-list {
  display: grid;
  gap: 1px;
  background: var(--color-border);
}

.loading-list span {
  height: 78px;
  background: linear-gradient(90deg, var(--color-surface) 0%, var(--color-surface-alt) 45%, var(--color-surface) 90%);
  background-size: 240% 100%;
  animation: shimmer 1.5s var(--ease) infinite;
}

@keyframes shimmer {
  to { background-position: -140% 0; }
}

.editor-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-bg);
  box-shadow: var(--shadow-lg);
}

.editor-dialog::backdrop {
  background: color-mix(in srgb, var(--color-accent-deep) 38%, transparent);
  backdrop-filter: blur(6px);
}

.editor-dialog[open] {
  animation: dialog-in 240ms var(--ease) both;
}

@keyframes dialog-in {
  from { transform: translateY(14px) scale(0.985); opacity: 0; }
}

.editor-form {
  display: flex;
  max-height: calc(100dvh - 34px);
  flex-direction: column;
}

.dialog-head,
.dialog-actions {
  flex: 0 0 auto;
  padding: 22px 26px;
  background: var(--color-surface);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--color-border);
}

.form-fields {
  padding: 28px 26px 38px;
  overflow-y: auto;
}

.dialog-actions {
  justify-content: space-between;
  border-top: 1px solid var(--color-border);
}

.dialog-error {
  margin: 0 26px 16px;
}

.rich-shell {
  overflow: hidden;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.rich-toolbar {
  display: flex;
  padding: 7px;
  gap: 5px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-alt);
}

.rich-toolbar button {
  min-width: 34px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.rich-toolbar button:hover {
  border-color: var(--color-border-strong);
  background: var(--color-surface);
}

.rich-editor {
  min-height: 210px;
  border: 0;
  border-radius: 0;
  line-height: 1.7;
  overflow-y: auto;
}

.rich-editor:empty::before {
  color: var(--color-ink-soft);
  content: attr(data-placeholder);
  pointer-events: none;
}

.file-current {
  display: flex;
  padding: 10px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  font-size: 12px;
}

.file-current a {
  color: var(--color-accent);
  overflow-wrap: anywhere;
}

.stats-editor {
  display: grid;
  gap: 10px;
}

.stats-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 38px;
  gap: 8px;
}

.stats-row input {
  min-width: 0;
}

.stats-remove {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-accent-deep);
  cursor: pointer;
}

@media (max-width: 820px) {
  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-panel {
    width: auto;
    margin: auto;
    padding: 42px 22px;
  }

  .login-aside {
    display: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-header {
    padding: 0 14px;
  }

  .menu-button {
    display: grid;
  }

  .app-header > div:nth-child(2) {
    display: none;
  }

  .publish-state {
    max-width: 150px;
  }

  .publish-state span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar {
    position: fixed;
    top: 76px;
    bottom: 0;
    left: 0;
    z-index: 15;
    width: min(84vw, 300px);
    height: auto;
    transform: translateX(-105%);
    box-shadow: var(--shadow-md);
    transition: transform var(--transition);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .workspace {
    padding: 28px 18px 54px;
  }

  .workspace-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-row {
    gap: 10px;
  }

  .row-action span {
    display: none;
  }

  .editor-dialog {
    width: 100vw;
    max-width: none;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .editor-form {
    max-height: 100dvh;
  }

  .dialog-head,
  .form-fields,
  .dialog-actions {
    padding-right: 18px;
    padding-left: 18px;
  }

  .dialog-head h2 {
    font-size: 24px;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .dialog-actions-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .stats-row {
    grid-template-columns: 84px minmax(0, 1fr) 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
