/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #181d27;
  --surface2: #1e2535;
  --border: #252e42;
  --border-light: #2a3550;
  --text: #e8edf5;
  --text-dim: #8a97b0;
  --text-muted: #4e5f7a;
  --accent: #6C63FF;
  --accent2: #3ECFCF;
  --accent-dim: rgba(108,99,255,0.15);
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --ig: #E1306C;
  --fb: #1877F2;
  --tt: #010101;
  --li: #0A66C2;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ────────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  color: var(--text);
  margin-bottom: 32px;
  padding: 0 8px;
}
.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}
.logo-brand {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logo-app {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 32px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 500;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}

.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent-dim); color: var(--accent); }
.nav-btn.active svg { stroke: var(--accent); }

/* Platform status */
.platform-status { margin-top: auto; }
.status-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 0 4px;
}
.status-items { display: flex; flex-direction: column; gap: 6px; }
.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
  padding: 6px 8px;
  border-radius: 6px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-dot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.missing { background: var(--text-muted); }

/* ─── Main ──────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 40px 48px;
  max-width: 900px;
  overflow-x: hidden;
}

/* ─── Panel ─────────────────────────────────────────────────────────────────── */
.panel-header { margin-bottom: 32px; }
.panel-header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.panel-subtitle { color: var(--text-dim); font-size: 15px; }

/* ─── Step Cards ────────────────────────────────────────────────────────────── */
.step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
}

.step-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ─── Upload Zone ───────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-sm);
  padding: 40px 20px;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-icon { color: var(--text-muted); margin-bottom: 12px; }
.upload-hint { color: var(--text-dim); font-size: 15px; margin-bottom: 6px; }
.upload-types { color: var(--text-muted); font-size: 13px; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  text-decoration: underline;
}

.upload-progress { margin-top: 20px; }
.progress-bar {
  background: var(--surface2);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  width: 0%;
  transition: width 0.3s;
}
#progressText { font-size: 13px; color: var(--text-dim); }

/* ─── Media Grid ────────────────────────────────────────────────────────────── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.media-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 1;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  background: var(--surface2);
}
.media-item:hover { border-color: var(--accent); }
.media-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.media-item.selected::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-item img,
.media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-type-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.media-remove {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  color: white;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.media-item:hover .media-remove { opacity: 1; }

/* Selection bar */
.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-dim);
}
.selection-actions { display: flex; gap: 8px; }

/* ─── Caption ───────────────────────────────────────────────────────────────── */
.caption-wrap { position: relative; }
.caption-wrap textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  padding: 16px;
  resize: vertical;
  transition: border-color 0.15s;
  min-height: 120px;
}
.caption-wrap textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.caption-wrap textarea::placeholder { color: var(--text-muted); }

.caption-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.char-count { font-size: 13px; color: var(--text-muted); }

/* ─── Platform Grid ─────────────────────────────────────────────────────────── */
.platform-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.platform-card {
  position: relative;
  cursor: pointer;
}
.platform-card input[type="checkbox"] { display: none; }

.platform-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  border: 2px solid var(--border-light);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  position: relative;
  background: var(--surface2);
}

.platform-card input:checked ~ .platform-inner {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.platform-card:hover .platform-inner { border-color: var(--border); }

.platform-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}
.platform-logo.sm { width: 36px; height: 36px; border-radius: 10px; }

.ig-logo { background: linear-gradient(135deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%); }
.fb-logo { background: #1877F2; }
.tt-logo { background: #010101; }
.li-logo { background: #0A66C2; }

.platform-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.platform-card input:checked ~ .platform-inner .platform-name { color: var(--text); }

.platform-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 8px;
  color: var(--text-muted);
}
.platform-badge.configured { color: var(--green); }

/* ─── Post Actions ──────────────────────────────────────────────────────────── */
.post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
}

.post-summary {
  font-size: 14px;
  color: var(--text-dim);
  flex: 1;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn-publish {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-publish:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(108,99,255,0.35); }
.btn-publish:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-publish.loading { opacity: 0.7; cursor: wait; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-ghost.danger:hover { border-color: var(--red); color: var(--red); }

/* ─── Settings ──────────────────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.settings-card.full-width { grid-column: 1 / -1; }

.settings-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.settings-card-header h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

.field-group { margin-bottom: 16px; }
.field-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 14px;
  transition: border-color 0.15s;
}
.field-group input:focus { outline: none; border-color: var(--accent); }
.field-group input::placeholder { color: var(--text-muted); }

.settings-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; }

/* ─── Post time slots (per-post scheduler times) ───────────────────────────── */
.post-times-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.post-time-slot {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.post-time-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.post-time-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 12px;
  transition: border-color 0.15s;
  color-scheme: dark;
}
.post-time-input:focus { outline: none; border-color: var(--accent); }

.settings-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  bottom: 0;
  margin-top: 24px;
  padding: 16px 20px;
  background: var(--surface, #14161f);
  border-top: 1px solid var(--border-light);
  border-radius: 0 0 12px 12px;
  z-index: 5;
}
.save-feedback { font-size: 14px; color: var(--green); transition: color 0.15s; }
.save-feedback.success { color: var(--green); }
.save-feedback.error { color: #ff6b6b; }
.btn-publish.is-saving { opacity: 0.7; cursor: wait; }

/* ─── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
.modal h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}
#modalBody { margin-bottom: 24px; }

.result-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; }
.result-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.result-icon.ok { background: rgba(34,197,94,0.15); color: var(--green); }
.result-icon.err { background: rgba(239,68,68,0.15); color: var(--red); }
.result-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  text-transform: capitalize;
}
.result-msg { font-size: 13px; color: var(--text-dim); }

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 16px; }
  .logo { margin-bottom: 0; }
  .nav { flex-direction: row; margin-bottom: 0; }
  .platform-status { display: none; }
  .main { padding: 20px 16px; }
  .settings-grid { grid-template-columns: 1fr; }
  .post-actions { flex-direction: column; align-items: stretch; }
}

/* ─── Inventory Dashboard ───────────────────────────────────────────────────── */
.inv-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 4px;
}

@media (max-width: 700px) { .inv-cards { grid-template-columns: repeat(2, 1fr); } }

.inv-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 16px;
  text-align: center;
}
.inv-card-value {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}
.inv-card-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.inv-card-total    { border-top: 3px solid var(--accent); }
.inv-card-posted   { border-top: 3px solid var(--fb); }
.inv-card-remaining{ border-top: 3px solid var(--accent2); }
.inv-card-balance  { border-top: 3px solid var(--green); }

.inv-card-total    .inv-card-value { color: var(--accent); }
.inv-card-posted   .inv-card-value { color: var(--fb); }
.inv-card-remaining.inv-card-value { color: var(--accent2); }
.inv-card-balance  .inv-card-value { color: var(--green); }
.inv-card-remaining .inv-card-value { color: var(--accent2); }

.inv-folder-info {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.8;
}
.inv-folder-info strong { color: var(--text); }
.inv-folder-info code {
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent2);
}

.inv-error {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 8px;
  color: var(--red);
  font-size: 13px;
}

.inv-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

/* ─── Scheduler status grid ─────────────────────────────────────────────────── */
.sched-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.sched-stat {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px 14px;
}
.sched-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.sched-stat-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.sched-stat-value.ok    { color: var(--green); }
.sched-stat-value.warn  { color: var(--orange); }
.sched-stat-value.error { color: var(--red); }

/* ─── Scheduler log ─────────────────────────────────────────────────────────── */
.sched-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 320px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
}
.log-line {
  display: flex;
  gap: 8px;
  padding: 2px 0;
}
.log-ts   { color: var(--text-muted); flex-shrink: 0; }
.log-info  { color: var(--accent2); }
.log-error { color: var(--red); }
.log-msg  { color: var(--text-dim); }

/* ─── Settings section dividers ─────────────────────────────────────────────── */
.settings-section-divider {
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  padding: 16px 0 4px;
  margin-top: 8px;
}
.settings-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

/* Drive logo */
.drive-logo { background: #fff; }
