:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --panel: #ffffff;
  --ink: #1f2523;
  --muted: #66706b;
  --line: #d9ded8;
  --accent: #1f6f5b;
  --accent-dark: #164f41;
  --danger: #b4322b;
  --warn: #ad6b16;
  --soft: #e9f1ed;
  --shadow: 0 18px 50px rgba(31, 37, 35, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

label span,
.field-xl label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel h1,
.topbar h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.eyebrow,
.muted {
  color: var(--muted);
  font-size: 14px;
}

.error {
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.auth-copy {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
}

.workspace {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 22px;
}

.week-status {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-button {
  background: #e6ece9;
  color: var(--ink);
  min-height: 38px;
}

.ollama-url-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #64748b;
}

.ollama-url-field input {
  width: 160px;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid #d8d4cc;
  border-radius: 8px;
}

.ollama-status {
  font-weight: 700;
  font-size: 13px;
}

.ollama-status.ok {
  color: var(--accent);
}

.ollama-status.warn {
  color: var(--warn);
}

.ollama-status.bad {
  color: var(--danger);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: 18px;
  align-items: start;
}

.editor-column {
  display: grid;
  gap: 16px;
}

.channels-column {
  display: grid;
  gap: 12px;
}

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

.channels-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.composer {
  display: grid;
  gap: 16px;
}

.field-xl,
.side-fields,
.photo-strip,
.targets,
.bottom-actions {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.side-fields {
  display: grid;
  gap: 14px;
  align-content: start;
}

.photo-strip {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
}

.upload-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  padding: 0 14px;
}

.upload-button input {
  display: none;
}

.checkbox-line {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.checkbox-line input {
  width: auto;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
  min-height: 72px;
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--soft);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-item button {
  position: absolute;
  right: 6px;
  top: 6px;
  min-height: 28px;
  width: 28px;
  padding: 0;
  background: rgba(31, 37, 35, 0.82);
}

.targets {
  display: grid;
  gap: 12px;
}

.target-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  background: #fbfcfb;
  cursor: grab;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.target-item.dragging {
  opacity: 0.55;
  border-color: var(--accent);
  box-shadow: 0 10px 26px rgba(31, 37, 35, 0.12);
}

.target-item.disabled {
  opacity: 0.68;
  background: #f3f5f3;
  border-style: dashed;
}

.target-item.disabled .target-logo {
  background: #8a948f;
}

.target-top {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.target-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
}

.target-name {
  min-width: 0;
}

.target-name strong {
  display: block;
  overflow-wrap: anywhere;
}

.target-name small,
.target-health {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  display: grid;
  gap: 3px;
  line-height: 1.35;
}

.target-health span,
.target-health small {
  display: block;
}

.target-health small {
  font-weight: 600;
  opacity: 0.86;
}

.target-health.ok {
  color: var(--accent);
}

.target-health.bad {
  color: var(--danger);
}

.target-health.warn {
  color: var(--warn);
}

.target-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.target-check-button {
  min-height: 40px;
  padding: 0 12px;
  background: #e6ece9;
  color: var(--ink);
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 84px;
  height: 38px;
  flex: 0 0 auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.switch input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #edf0ed, #d7ded9);
  border: 1px solid #c5cec8;
  box-shadow:
    inset 0 1px 3px rgba(31, 37, 35, 0.16),
    0 1px 0 rgba(255, 255, 255, 0.9);
  overflow: hidden;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.switch span::before {
  content: attr(data-off);
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: #67736e;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  z-index: 1;
  letter-spacing: 0;
}

.switch span::after {
  content: "×";
  position: absolute;
  width: 32px;
  height: 32px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 38%),
    #ffffff;
  box-shadow:
    0 3px 10px rgba(31, 37, 35, 0.3),
    0 0 0 1px rgba(31, 37, 35, 0.08);
  color: #7a8580;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  z-index: 2;
  transition: transform 0.22s cubic-bezier(.2, .8, .2, 1), color 0.18s ease;
}

.switch input:checked + span {
  background: linear-gradient(180deg, #2b8a72, var(--accent));
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.18),
    inset 0 -8px 14px rgba(22, 79, 65, 0.18),
    0 1px 0 rgba(255, 255, 255, 0.9);
}

.switch input:checked + span::before {
  content: attr(data-on);
  left: 13px;
  right: auto;
  color: #fff;
}

.switch input:checked + span::after {
  content: "✓";
  color: var(--accent);
  transform: translateX(46px);
}

.switch input:focus-visible + span {
  outline: 3px solid rgba(31, 111, 91, 0.24);
  outline-offset: 2px;
}

.target-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  font-weight: 800;
}

.target-head input {
  width: auto;
  margin-top: 3px;
}

.target-title small {
  display: block;
  color: var(--muted);
  font-weight: 600;
}

.generate-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0;
}

.ollama-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-weight: 800;
}

.stage-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 12px;
  border-bottom: 1px solid var(--line);
}

.stage-tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 11px 12px;
  min-height: 42px;
}

.stage-tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.stage-panel {
  display: none;
}

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

.primary-action {
  background: var(--accent);
  min-width: 190px;
}

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

.draft-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

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

.draft-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.counter {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.counter.over {
  color: var(--danger);
}

.hashtags {
  min-height: 46px;
}

.blog-category-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.blog-category-field small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-weight: 600;
}

.manual-source {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f8f5;
  padding: 10px 12px;
  color: var(--muted);
}

.manual-source strong {
  display: block;
  color: var(--ink);
  margin-bottom: 6px;
}

.manual-source p {
  margin: 0;
  white-space: pre-wrap;
}

.attached-photos {
  display: flex;
  gap: 8px;
  overflow: auto;
}

.attached-photos img {
  width: 68px;
  height: 68px;
  border-radius: 8px;
  object-fit: cover;
}

.card-actions,
.bottom-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.card-actions button {
  background: #e6ece9;
  color: var(--ink);
}

.card-actions button[data-action="approve"] {
  background: var(--accent);
  color: #fff;
}

.card-actions button[data-action="skip"] {
  background: #f4e5e3;
  color: var(--danger);
}

.draft-card.approved {
  border-color: var(--accent);
  background: #f7fbf9;
}

.draft-card.translated {
  border-color: #3f6f95;
  background: #f6f9fc;
}

.draft-card.pending {
  border-color: var(--warn);
  background: #fffaf1;
}

.draft-card.error-card {
  border-color: var(--danger);
  background: #fff7f6;
}

.draft-card.skipped {
  opacity: 0.58;
}

.draft-progress {
  margin: 0;
  color: var(--warn);
  font-weight: 800;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.bottom-actions {
  margin-top: 18px;
}

.bottom-actions button:first-child {
  background: var(--accent-dark);
}

.publish-status {
  width: 100%;
  color: var(--muted);
  font-weight: 700;
}

.section-heading {
  margin: 18px 0 12px;
}

.section-heading h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.section-heading p {
  color: var(--muted);
  font-weight: 700;
  margin: 0;
}

.token-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
}

.token-dashboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.token-section-title {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin-top: 6px;
}

.token-section-title h3 {
  margin: 0;
  font-size: 18px;
}

.token-section-title span {
  color: var(--muted);
  font-weight: 700;
}

.token-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.token-card.active {
  border-color: var(--accent);
}

.token-card.expiring {
  border-color: #d59b2d;
}

.token-card.expired,
.token-card.missing {
  border-color: var(--danger);
}

.token-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.token-card h2,
.token-card p {
  margin: 0;
}

.token-card-head p,
.token-card dl,
.token-card-status {
  color: var(--muted);
}

.token-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.token-card dl div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
}

.token-card dt {
  font-weight: 800;
  color: var(--ink);
}

.token-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.scope-list,
.token-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.token-actions.compact {
  justify-content: start;
}

.scope-list span {
  background: #eef3f1;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

.token-actions input {
  flex: 1 1 260px;
}

.token-card-status {
  min-height: 20px;
  font-weight: 700;
}

@media (max-width: 980px) {
  .main-grid,
  .photo-strip {
    grid-template-columns: 1fr;
  }

  .results,
  .token-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .week-status {
    text-align: left;
  }

  .results,
  .token-dashboard {
    grid-template-columns: 1fr;
  }

  .target-controls {
    grid-template-columns: 1fr;
  }

  .generate-row,
  .card-actions,
  .bottom-actions,
  .token-toolbar,
  .token-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .stage-tabs {
    display: grid;
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
