:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #176b5b;
  --primary-dark: #0f4d42;
  --danger: #b42318;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
.legal-page {
  min-height: 100vh;
  padding: 32px 18px;
  background: #f6f7f9;
}
.legal-document {
  max-width: 860px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #d9dee7;
  border-radius: 8px;
  padding: 28px;
}
.legal-document h1 { margin: 0 0 8px; font-size: 30px; }
.legal-document h2 { margin: 24px 0 8px; font-size: 18px; }
.legal-document p { color: #344054; line-height: 1.65; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand h1 { font-size: 24px; margin: 0; }

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #ffffff;
  color: #1d2430;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  margin-bottom: 28px;
  min-width: 0;
}
.brand span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  overflow: hidden;
}
.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: block;
  object-fit: cover;
  border-radius: 10px;
}
.nav { display: grid; gap: 4px; }
.nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #1d2430;
}
.nav a.active, .nav a:hover { background: #243342; color: #fff; }
.sidebar-footer {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.sidebar-user {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #d9dee7;
  border-radius: 6px;
  color: #1d2430;
  background: #fff;
}
.sidebar-user:hover {
  border-color: #b8c0cc;
  background: #f8fafc;
}
.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background: #78d2df;
  color: #15515d;
  font-weight: 800;
}
.sidebar-user-name {
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-logout {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
  color: #1d2430;
  border-color: transparent;
  background: #edf1f5;
  justify-self: stretch;
}
.sidebar-logout:hover {
  color: #fff;
  background: #243342;
}

.main { min-width: 0; padding: 24px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header h1 { margin: 0; font-size: 28px; }
.page-header p { margin: 5px 0 0; color: var(--muted); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.metric { padding: 18px; }
.metric span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metric strong { font-size: 30px; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.two { align-items: start; }
.compact-panel {
  align-self: start;
  height: auto;
}
.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.panel { padding: 18px; }
.panel h2 { margin: 0 0 16px; font-size: 18px; }
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-title h2 { margin: 0; }
.panel-title a { color: var(--primary); font-weight: 700; }

.list { display: grid; gap: 8px; }
.list-row, .calendar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.list-row span, .list-row small, .calendar-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}
.list-row small.connection-success {
  color: #166534;
  font-weight: 800;
}
.chevron { font-size: 24px; color: var(--muted); }
.empty { color: var(--muted); margin: 12px 0 0; }

.button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 700;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.disabled, .button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  background: #d0d5dd;
  border-color: #d0d5dd;
  color: #475467;
}
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); border-color: #f2b8b5; background: #fff6f5; }
.button.full { width: 100%; }
.actions, .inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pagination {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.form { display: grid; gap: 14px; }
.form.compact { margin-top: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
label { display: grid; gap: 6px; color: #344054; font-weight: 700; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.section-title { font-weight: 800; margin-top: 4px; }
.destination-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.destination {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 400;
}
.destination input { width: auto; margin-top: 3px; }
.destination small { color: var(--muted); display: block; margin-top: 3px; }
.destination-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.destination-table {
  min-width: 1120px;
  table-layout: fixed;
}
.destination-table .destination-col-brand {
  width: 280px;
}
.destination-table .destination-col-instagram {
  width: 340px;
}
.destination-table .destination-col-youtube,
.destination-table .destination-col-tiktok {
  width: 250px;
}
.destination-table th,
.destination-table td {
  vertical-align: top;
}
.destination-row.inactive td {
  background: #f8fafc;
  opacity: 0.72;
}
.destination-logo {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #176b5b, #78d2df);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
}
.destination-logo.provider-instagram {
  background: linear-gradient(135deg, #f58529, #dd2a7b 48%, #515bd4);
}
.destination-logo.provider-youtube {
  background: #ff0033;
}
.destination-logo.provider-tiktok {
  background: linear-gradient(135deg, #00f2ea, #111 52%, #ff0050);
}
.destination-logo .network-icon {
  background: transparent;
}
.network-icon {
  position: relative;
  width: 22px;
  height: 22px;
  display: inline-block;
  flex: 0 0 22px;
}
.network-icon.provider-instagram {
  border-radius: 7px;
  background: linear-gradient(135deg, #f58529, #dd2a7b 48%, #515bd4);
}
.network-icon.provider-instagram::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px solid #fff;
  border-radius: 50%;
}
.network-icon.provider-instagram::after {
  content: "";
  position: absolute;
  right: 5px;
  top: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
}
.network-icon.provider-youtube {
  border-radius: 6px;
  background: #ff0033;
}
.network-icon.provider-youtube::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 6px;
  border-left: 8px solid #fff;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}
.network-icon.provider-tiktok {
  border-radius: 7px;
  background: #111;
}
.network-icon.provider-tiktok::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 4px;
  width: 4px;
  height: 11px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 3px 1px 0 #00f2ea, -2px 0 0 #ff0050;
}
.network-icon.provider-tiktok::after {
  content: "";
  position: absolute;
  left: 5px;
  bottom: 4px;
  width: 9px;
  height: 9px;
  border: 3px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
}
.destination-brand {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.destination-brand strong {
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.destination-brand span,
.muted-text {
  color: var(--muted);
  font-size: 13px;
}
.destination-provider-cell {
  display: grid;
  gap: 8px;
  min-width: 170px;
}
.destination-account {
  display: grid;
  gap: 7px;
}
.destination-account-name {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: 0;
}
.destination-account-name .network-icon {
  width: 18px;
  height: 18px;
  flex-basis: 18px;
}
.destination-account-name small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.destination-options {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.destination-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.destination-option input {
  width: auto;
  margin: 0;
}
.destination-option:has(input:checked) {
  border-color: var(--primary);
  background: #ecf8f5;
}
.destination-option.muted,
.destination-option:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.66;
  background: #f8fafc;
}

.upload-field {
  display: grid;
  gap: 8px;
}
.upload-progress {
  display: grid;
  grid-template-columns: 1fr 52px;
  align-items: center;
  gap: 10px;
}
.upload-progress.optional {
  opacity: 0.85;
}
.upload-progress-bar {
  height: 10px;
  overflow: hidden;
  background: #eef2f6;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.upload-progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 160ms ease;
}
.upload-progress strong {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.upload-message {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.upload-message.success { color: #166534; font-weight: 700; }
.upload-message.error { color: var(--danger); font-weight: 700; }

.account-branding {
  margin-top: 18px;
  max-width: 520px;
}
.branding-preview {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.branding-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flash {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-weight: 700;
}
.flash.success { background: #e9f7ef; color: #166534; border: 1px solid #b7e4c7; }
.flash.error { background: #fff1f0; color: #b42318; border: 1px solid #f2b8b5; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  background: #eef2f6;
  color: #344054;
}
.badge.scheduled, .badge.open { background: #fff7df; color: #8a5a00; }
.badge.processing { background: #e8f1ff; color: #194185; }
.badge.published, .badge.paid, .badge.connected { background: #e9f7ef; color: #166534; }
.badge.partial { background: #f3e8ff; color: #6b21a8; }
.badge.failed, .badge.overdue { background: #fff1f0; color: #b42318; }
.badge.blocked, .badge.needs_reconnect, .badge.disconnected, .badge.cancelled { background: #eef2f6; color: #475467; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #fafafa; }
.post-list-title,
.post-list-file {
  display: block;
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.post-list-file {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.row-actions {
  justify-content: flex-end;
}

.calendar-board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
}
.calendar-weekdays span {
  padding: 11px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.calendar-day {
  min-height: 138px;
  padding: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  min-width: 0;
}
.calendar-day:nth-child(7n) { border-right: 0; }
.calendar-day.muted-day { background: #fafafa; color: #98a2b3; }
.calendar-day.today .calendar-day-number {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
}
.calendar-day-number {
  font-weight: 800;
  margin-bottom: 6px;
}
.calendar-events {
  display: grid;
  gap: 5px;
}
.calendar-event {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 6px;
  border-left: 3px solid var(--primary);
  background: #eef8f5;
  border-radius: 6px;
  padding: 6px;
  color: var(--text);
  min-width: 0;
}
.calendar-event strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.calendar-event small {
  grid-column: 1 / -1;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calendar-event .event-time {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}
.calendar-event.blocked, .calendar-event.failed { background: #fff1f0; border-left-color: var(--danger); }
.calendar-event.processing { background: #e8f1ff; border-left-color: #194185; }
.calendar-event.published { background: #e9f7ef; border-left-color: #166534; }
.calendar-event.partial { background: #f3e8ff; border-left-color: #6b21a8; }
.details { display: grid; grid-template-columns: 140px 1fr; gap: 12px; margin: 0; }
.details dt { color: var(--muted); font-weight: 700; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.missing-media {
  display: block;
  margin-top: 4px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}
.missing-media-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  margin-bottom: 16px;
  border: 1px solid #f2b8b5;
  border-radius: var(--radius);
  background: #fff6f5;
}
.missing-media-box p {
  margin: 0;
  color: #7a271a;
}
.reupload-form {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 18px; }
  .metrics, .grid.two, .form-grid, .destination-grid, .integration-grid { grid-template-columns: 1fr; }
  .destination-table { min-width: 940px; }
  .destination-table .destination-col-brand {
    width: 220px;
  }
  .destination-provider-cell { min-width: 145px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 12px; }
  .list-row, .calendar-item { align-items: flex-start; flex-direction: column; }
  .calendar-weekdays { display: none; }
  .calendar-grid { grid-template-columns: 1fr; }
  .calendar-day { min-height: auto; border-right: 0; }
  .calendar-day.muted-day:not(:has(.calendar-event)) { display: none; }
  .details { grid-template-columns: 1fr; }
}
