:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #dcdfe5;
  --text: #171a20;
  --text-muted: #666d7a;
  --accent: #2f6feb;
  --accent-text: #ffffff;
  --success: #1a7f45;
  --warning: #8a5a00;
  --error: #c02c2c;
  --radius: 12px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #23272f;
    --border: #333944;
    --text: #e8eaee;
    --text-muted: #98a0ae;
    --accent: #4b8bff;
    --accent-text: #0d1117;
    --success: #4ec27f;
    --warning: #e0aa4a;
    --error: #ff6b6b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.9em;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
}

/* Layout ------------------------------------------------------------ */

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 var(--gap) 48px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 12px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 650;
  text-decoration: none;
  color: var(--text);
}

.nav {
  display: flex;
  gap: 4px;
  margin-right: auto;
}

.nav-link {
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-muted);
}

.nav-link:hover {
  background: var(--surface-2);
}

.nav-link.is-active {
  background: var(--accent);
  color: var(--accent-text);
}

.logout {
  margin: 0;
}

.content {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding-top: var(--gap);
}

/* Cards -------------------------------------------------------------- */

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

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

.card-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 620;
}

.card-head .card-title {
  margin: 0;
}

.hint {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.empty {
  margin: 12px 0;
  color: var(--text-muted);
}

.text-error {
  color: var(--error);
}

/* Forms -------------------------------------------------------------- */

.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.input,
.textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.textarea {
  resize: vertical;
  min-height: 160px;
}

.input:focus,
.textarea:focus,
.dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.button:hover {
  border-color: var(--accent);
}

.button:disabled {
  opacity: 0.55;
  cursor: progress;
}

.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.button-danger {
  color: var(--error);
  border-color: var(--error);
  background: transparent;
}

.button-ghost {
  background: transparent;
}

.button-link {
  border: none;
  background: none;
  color: var(--accent);
  padding: 0;
  font-size: 0.88rem;
}

.button-block {
  width: 100%;
}

/* Login -------------------------------------------------------------- */

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--gap);
}

.login-card {
  width: min(380px, 100%);
}

.login-title {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.login-subtitle {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.alert {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.alert-error {
  background: color-mix(in srgb, var(--error) 14%, transparent);
  color: var(--error);
}

.alert-warning {
  background: color-mix(in srgb, var(--warning) 16%, transparent);
  color: var(--warning);
}

/* Composer ----------------------------------------------------------- */

.composer {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
}

.dropzone.is-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
}

.dropzone-icon {
  font-size: 1.5rem;
}

.dropzone-text {
  font-weight: 550;
}

.media-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.media-preview {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex: none;
}

.media-info {
  min-width: 0;
  flex: 1;
}

.media-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
}

.icon-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.progress {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 6px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s linear;
}

/* Targets ------------------------------------------------------------ */

.target-group {
  margin: 0 0 14px;
  padding: 0;
  border: none;
}

.target-legend {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0;
  margin-bottom: 8px;
  font-weight: 600;
}

.target-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.target {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}

.target:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.target input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  flex: none;
}

.target-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.target-kind {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex: none;
}

/* Schedule ------------------------------------------------------------ */

.schedule-modes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.schedule-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}

.schedule-mode:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

.schedule-mode input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
}

.schedule-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.schedule-presets .button {
  padding: 7px 12px;
  font-size: 0.88rem;
}

.schedule-fields .field {
  max-width: 280px;
}

.schedule-planned {
  margin: 0 0 12px;
}

.text-scheduled {
  color: var(--warning);
}

/* Actions ------------------------------------------------------------ */

.composer-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.composer-buttons {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.composer-message {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.composer-message.is-error {
  color: var(--error);
}

.composer-message.is-success {
  color: var(--success);
}

/* History ------------------------------------------------------------ */

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.chip.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.post-list,
.job-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-link {
  display: block;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  background: var(--surface-2);
}

.post-link:hover {
  border-color: var(--accent);
}

.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.post-id {
  margin-left: auto;
}

.post-preview {
  margin: 8px 0;
  overflow-wrap: anywhere;
}

.post-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.post-platforms {
  margin-left: auto;
}

.badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
}

.badge-done {
  color: var(--success);
  border-color: var(--success);
}

.badge-failed {
  color: var(--error);
  border-color: var(--error);
}

.badge-queued,
.badge-pending,
.badge-in_progress,
.badge-scheduled {
  color: var(--warning);
  border-color: var(--warning);
}

.pager {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

/* Post details -------------------------------------------------------- */

.caption {
  margin: 0 0 16px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.media-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
}

.job-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.9rem;
}

.job-platform {
  font-weight: 600;
}

.job-target {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.job-error {
  width: 100%;
  color: var(--error);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

/* Mobile -------------------------------------------------------------- */

@media (max-width: 640px) {
  :root {
    --gap: 12px;
  }

  .card {
    padding: 14px;
  }

  .topbar {
    padding: 10px 0;
  }

  .brand {
    width: 100%;
  }

  .nav {
    flex: 1;
  }

  .nav-link {
    padding: 7px 10px;
    font-size: 0.9rem;
  }

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

  .composer-actions {
    bottom: 0;
    margin: 0 calc(var(--gap) * -1);
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .composer-buttons {
    width: 100%;
  }

  .composer-buttons .button {
    flex: 1;
  }

  .post-platforms,
  .post-id {
    margin-left: 0;
  }
}
