/* Social Manager — operator UI. Tokens only (DESIGN.md). No gradients. */

:root {
  --bg: #F4F3F0;
  --surface: #FFFFFF;
  --surface-2: #EBE9E4;
  --ink: #141414;
  --ink-2: #5C5C5C;
  --ink-3: #8A8A8A;
  --border: #DDD9D2;
  --border-2: #C9C4BB;
  --accent: #1F3A34;
  --accent-ink: #F4F3F0;
  --danger: #7A2E2E;
  --success: #2F5D3A;
  --warning: #6B5426;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 0 rgba(20, 20, 20, 0.04);

  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --rail-w: 220px;
  --top-h: 48px;
  --content-max: 1120px;
  --row-h: 40px;
  --transition: 120ms ease;
}

[data-theme="dark"] {
  --bg: #0C0C0C;
  --surface: #121212;
  --surface-2: #1A1A1A;
  --ink: #EDEDED;
  --ink-2: #A0A0A0;
  --ink-3: #6E6E6E;
  --border: #2A2A2A;
  --border-2: #3A3A3A;
  --accent: #9BB5A8;
  --accent-ink: #0C0C0C;
  --danger: #C48A8A;
  --success: #8FBF9A;
  --warning: #C4A96A;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ——— App shell ——— */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  gap: 24px;
  z-index: 20;
}

.rail__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.rail__brand:hover {
  text-decoration: none;
}

.rail__mark {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.rail__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}

.nav-item.is-active {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-item .icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.rail__foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.rail__user {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--ink-3);
  word-break: break-all;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.content {
  padding: 24px;
  max-width: calc(var(--content-max) + 48px);
  width: 100%;
}

.page-head {
  margin-bottom: 20px;
}

.page-head__title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.page-head__sub {
  margin-top: 6px;
  color: var(--ink-2);
  font-size: 13px;
}

/* Signature: status ledger strip */

.ledger {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ledger__cell {
  flex: 1 1 120px;
  padding: 12px 16px;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.ledger__cell:last-child {
  border-right: none;
}

.ledger__label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ledger__value {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* ——— Buttons ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn--primary:hover:not(:disabled) {
  opacity: 0.92;
}

.btn--secondary {
  background: var(--surface);
  border-color: var(--border-2);
  color: var(--ink);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: transparent;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--ink);
}

.btn--danger {
  background: transparent;
  border-color: var(--border-2);
  color: var(--danger);
}

.btn--danger:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn--block {
  width: 100%;
}

.btn--icon {
  padding: 0;
  width: 36px;
  min-height: 36px;
}

.btn--sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

/* ——— Forms ——— */

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row--split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--transition);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--ink-3);
}

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

.select {
  appearance: none;
  background-image: none;
  padding-right: 28px;
}

.field-hint {
  font-size: 12px;
  color: var(--ink-3);
}

.field-error {
  font-size: 12px;
  color: var(--danger);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.checkbox-row:hover {
  background: var(--surface-2);
}

.checkbox-row input {
  margin-top: 3px;
  accent-color: var(--accent);
}

.checkbox-row__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.checkbox-row__title {
  font-size: 13px;
  font-weight: 500;
}

.checkbox-row__sub {
  font-size: 12px;
  color: var(--ink-3);
}

/* Chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.chips:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chips input {
  flex: 1;
  min-width: 120px;
  border: none;
  background: transparent;
  padding: 2px 4px;
  outline: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
}

.chip button {
  border: none;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  font-size: 12px;
}

.chip button:hover {
  color: var(--ink);
}

/* Drop zone */

.dropzone {
  border: 1px dashed var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 32px 16px;
  text-align: center;
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.dropzone:hover,
.dropzone.is-active {
  background: var(--surface-2);
  border-color: var(--ink-3);
}

.dropzone__title {
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 4px;
}

.dropzone__hint {
  font-size: 12px;
  color: var(--ink-3);
}

.dropzone__file {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
}

/* ——— Panels / cards ——— */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel__title {
  font-size: 13px;
  font-weight: 600;
}

.panel__body {
  padding: 16px;
}

.panel__body--flush {
  padding: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stack--sm {
  gap: 12px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar .select,
.toolbar .input {
  width: auto;
  min-width: 140px;
}

/* ——— Tables ——— */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

.table td {
  padding: 0 14px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--ink);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background: var(--surface-2);
}

.table__row--clickable {
  cursor: pointer;
}

.table__row--clickable.is-selected td {
  background: var(--surface-2);
}

.table td.actions,
.table th.actions {
  text-align: right;
  white-space: nowrap;
}

.cell-strong {
  font-weight: 500;
}

.cell-sub {
  display: block;
  font-size: 12px;
  color: var(--ink-3);
}

/* Badges — neutral fills */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  line-height: 1.4;
}

/* Status tint = token text color on neutral fill only. */
.badge--active,
.badge--published,
.badge--success {
  color: var(--success);
  background: var(--surface-2);
  border-color: var(--border);
}

.badge--failed,
.badge--error,
.badge--revoked,
.badge--canceled {
  color: var(--danger);
  background: var(--surface-2);
  border-color: var(--border);
}

.badge--expired,
.badge--quota_error,
.badge--pending_upload,
.badge--queued,
.badge--uploading {
  color: var(--warning);
  background: var(--surface-2);
  border-color: var(--border);
}

.badge--youtube,
.badge--instagram {
  color: var(--ink-2);
  background: var(--surface-2);
}

/* Empty / loading */

.empty {
  padding: 40px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty__text {
  color: var(--ink-2);
  font-size: 13px;
}

.skeleton {
  padding: 8px 0;
}

.skeleton__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.skeleton__cell {
  height: 12px;
  border-radius: 3px;
  background: var(--surface-2);
}

/* Side panel (library editor) */

.split {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}

.split--single {
  grid-template-columns: 1fr;
}

.side-panel {
  position: sticky;
  top: calc(var(--top-h) + 24px);
}

/* Upload progress rows */

.progress-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.progress-row__name {
  font-size: 13px;
  font-weight: 500;
}

.progress-row__status {
  font-size: 12px;
  color: var(--ink-2);
  justify-self: end;
}

.progress-row__bar {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-row__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width var(--transition);
}

/* Toasts */

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-2);
  opacity: 1;
  transition: opacity var(--transition);
}

.toast--error {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.toast--success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.toast--out {
  opacity: 0;
}

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal {
  width: min(480px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  font-size: 14px;
  font-weight: 600;
}

.modal__body {
  padding: 16px;
}

.modal__text {
  color: var(--ink-2);
  font-size: 13px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* Login */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.login-card__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-weight: 600;
  font-size: 15px;
}

.login-card__title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.login-card__sub {
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 20px;
}

.login-card__switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-2);
}

.login-card__switch button {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  padding: 0;
}

.login-card__switch button:hover {
  text-decoration: underline;
}

.theme-toggle-mobile {
  display: none;
}

/* Keys list */

.key-prefix {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
}

.key-once {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.key-once__value {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--ink);
  margin-bottom: 8px;
}

/* Platform filter pills — still monochrome */

.filters {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.filters button {
  border: none;
  background: transparent;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: background var(--transition), color var(--transition);
}

.filters button:last-child {
  border-right: none;
}

.filters button.is-active {
  background: var(--surface-2);
  color: var(--ink);
}

.filters button:hover {
  color: var(--ink);
}

/* ——— Responsive ——— */

.rail-toggle {
  display: none;
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .rail {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow);
  }

  .rail.is-open {
    transform: translateX(0);
  }

  .rail-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 20, 0.28);
    z-index: 15;
  }

  .rail-overlay.is-open {
    display: block;
  }

  .rail-toggle {
    display: inline-flex;
  }

  .content {
    padding: 16px;
  }

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

  .side-panel {
    position: static;
  }

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

  .page-head__title {
    font-size: 20px;
  }

  .btn {
    min-height: 44px;
  }

  .btn--sm {
    min-height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
