:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #eff4f2;
  --text: #15201d;
  --muted: #66736e;
  --line: #dbe3df;
  --accent: #e94f37;
  --accent-2: #0f8b8d;
  --good: #23865f;
  --warn: #b66a00;
  --bad: #b42318;
  --shadow: 0 16px 40px rgba(21, 32, 29, 0.08);
  --radius: 8px;
  font-family: "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 0%, rgba(233, 79, 55, 0.14), transparent 30%),
    radial-gradient(circle at 92% 10%, rgba(15, 139, 141, 0.12), transparent 28%),
    var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 0;
  padding: 24px;
  border: 1px solid rgba(219, 227, 223, 0.78);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(239, 244, 242, 0.76));
  box-shadow: 0 18px 50px rgba(21, 32, 29, 0.07);
  backdrop-filter: blur(10px);
}

.app-header h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
}

.app-header p,
.section-head p,
.notice p {
  margin: 8px 0 0;
  color: var(--muted);
}

.header-actions,
.button-row,
.draft-actions,
.tool-strip,
.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 40px;
}

.tabs {
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}

.tab {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 6px 16px rgba(21, 32, 29, 0.08);
}

.tab span {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  min-height: 22px;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
}

.panel {
  display: none;
  margin-top: 18px;
}

.panel.is-active {
  display: block;
}

.quick-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
}

.form-stack,
.preview-pane,
.notice,
.settings-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-stack,
.preview-pane,
.settings-grid,
.notice {
  padding: 20px;
}

.form-stack,
.preview-pane,
.draft-card,
.history-card,
.settings-grid,
.notice {
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.form-stack:hover,
.preview-pane:hover,
.draft-card:hover,
.history-card:hover,
.settings-grid:hover,
.notice:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 139, 141, 0.28);
  box-shadow: 0 20px 46px rgba(21, 32, 29, 0.11);
}

.form-stack,
.settings-grid {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(15, 139, 141, 0.64);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

textarea {
  min-height: 128px;
  resize: vertical;
  line-height: 1.55;
}

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

.settings-grid button,
.settings-grid .notice {
  grid-column: 1 / -1;
}

.backend-connect {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.backend-connect h2 {
  margin: 0;
}

.connected-pages {
  margin-bottom: 16px;
}

.page-token-head,
.page-token-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-token-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.page-token-head h2 {
  margin: 0;
}

.page-token-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.page-token-list {
  display: grid;
  gap: 12px;
}

.page-token-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.page-token-card.is-selected {
  border-color: rgba(35, 134, 95, 0.45);
  background: linear-gradient(135deg, rgba(35, 134, 95, 0.08), rgba(255, 255, 255, 0.96));
}

.page-token-card strong {
  display: block;
  font-size: 16px;
}

.page-token-card span {
  color: var(--muted);
  font-size: 13px;
}

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

.copy-row input {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.copy-row button:disabled,
.page-token-card button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 15px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
  text-decoration: none;
}

.quick-guide {
  border: 1px solid rgba(15, 139, 141, 0.18);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(15, 139, 141, 0.08), rgba(233, 79, 55, 0.06));
  overflow: hidden;
}

.advanced-settings {
  grid-column: 1 / -1;
  border: 1px solid rgba(15, 139, 141, 0.18);
  border-radius: var(--radius);
  background: rgba(239, 244, 242, 0.72);
  padding: 0;
  overflow: hidden;
}

.advanced-settings summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  list-style: none;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings summary::after {
  content: "+";
  color: var(--accent);
  font-size: 18px;
}

.advanced-settings[open] summary::after {
  content: "×";
}

.advanced-settings p {
  margin: 0;
  padding: 0 14px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.advanced-settings .field-row {
  padding: 0 14px 14px;
}

.quick-guide summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  list-style: none;
}

.quick-guide summary::-webkit-details-marker {
  display: none;
}

.quick-guide summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--line);
}

.quick-guide[open] summary::after {
  content: "×";
}

.quick-guide-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 14px 14px;
}

.quick-guide-grid > div {
  padding: 14px;
  border: 1px solid rgba(219, 227, 223, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
}

.quick-guide-grid strong {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.quick-guide-grid h3 {
  margin: 10px 0 6px;
  font-size: 15px;
}

.quick-guide-grid p,
.quick-guide-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}

.quick-guide-note {
  padding: 0 14px 14px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(233, 79, 55, 0.22);
}

.secondary-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}

button:disabled,
.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.primary-button,
.secondary-button,
.danger-button,
.tab,
.icon-button {
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.tab:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: rgba(15, 139, 141, 0.34);
  box-shadow: 0 8px 20px rgba(21, 32, 29, 0.08);
}

.danger-button {
  background: #fff3f1;
  color: var(--bad);
  border-color: #ffd0c9;
}

.preview-pane {
  display: grid;
  align-content: start;
  gap: 18px;
}

.preview-image {
  min-height: 260px;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(233, 79, 55, 0.08), rgba(15, 139, 141, 0.08)),
    var(--surface-2);
  border: 1px solid var(--line);
}

.preview-image img,
.draft-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#liveCaption {
  margin: 8px 0 0;
  line-height: 1.65;
  white-space: pre-line;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 6px 0 16px;
}

.draft-list,
.history-list {
  display: grid;
  gap: 14px;
}

.draft-card,
.history-card {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.history-card {
  grid-template-columns: 1fr;
}

.draft-image {
  min-height: 150px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.draft-body {
  display: grid;
  gap: 10px;
}

.draft-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.status.approved,
.status.published,
.status.copied,
.status.scheduled {
  background: #e7f6ef;
  color: var(--good);
}

.status.rejected {
  background: #fff1df;
  color: var(--warn);
}

.status.publish_failed {
  background: #fff3f1;
  color: var(--bad);
}

.error-text {
  margin: 0;
  color: var(--bad);
  font-size: 13px;
  line-height: 1.5;
}

.settings-status {
  grid-column: 1 / -1;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(380px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 820px) {
  .app-header,
  .section-head,
  .backend-connect,
  .page-token-head {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-grid,
  .field-row,
  .settings-grid,
  .draft-card {
    grid-template-columns: 1fr;
  }

  .quick-guide-grid {
    grid-template-columns: 1fr;
  }

  .draft-image {
    min-height: 210px;
  }

  .copy-row {
    grid-template-columns: 1fr;
  }
}
