/* ============================================================
   AutoPost – Dark Dashboard CSS
   ============================================================ */

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

:root {
  --bg-base:       #0d1117;
  --bg-surface:    #161b22;
  --bg-elevated:   #1c2333;
  --bg-overlay:    #21262d;
  --border:        #30363d;
  --text-primary:  #e6edf3;
  --text-secondary:#8b949e;
  --text-muted:    #6e7681;
  --accent:        #58a6ff;
  --accent-hover:  #79c0ff;
  --green:         #3fb950;
  --green-bg:      rgba(63,185,80,.15);
  --yellow:        #d29922;
  --yellow-bg:     rgba(210,153,34,.15);
  --red:           #f85149;
  --red-bg:        rgba(248,81,73,.15);
  --purple:        #bc8cff;
  --radius:        8px;
  --radius-sm:     5px;
  --shadow:        0 2px 12px rgba(0,0,0,.3);
}

html { font-size: 16px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; }

/* ── LAYOUT ── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.main-content {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar-logo {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 1.6rem; }
.logo-text { font-size: 1.2rem; font-weight: 700; color: var(--text-primary); }

.nav-links { list-style: none; padding: 12px 0; flex: 1; }
.nav-links li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: .9rem;
  transition: background .15s, color .15s;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-right: 8px;
}
.nav-links li a:hover,
.nav-links li.active a {
  background: var(--bg-elevated);
  color: var(--text-primary);
  text-decoration: none;
}
.nav-links li.active a { color: var(--accent); }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.system-status { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--text-muted); }

/* ── TOPBAR ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 1.25rem; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-stats { display: flex; gap: 8px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: .85rem; font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-overlay); border-color: var(--text-muted); }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--accent); color: #0d1117; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--bg-elevated); border-color: var(--border); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border); }

.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-refresh { background: transparent; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: var(--radius); }
.btn-refresh:hover { color: var(--text-primary); background: var(--bg-elevated); }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── PAGE BODY ── */
.page-body { padding: 24px 28px; flex: 1; }

/* ── KPI GRID ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; gap: 16px; align-items: flex-start;
  transition: border-color .2s;
}
.kpi-card:hover { border-color: var(--accent); }
.kpi-icon { font-size: 1.6rem; }
.kpi-body { display: flex; flex-direction: column; }
.kpi-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 1.8rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; margin: 2px 0; }
.kpi-change { font-size: .78rem; color: var(--text-muted); }
.kpi-change.positive { color: var(--green); }

/* ── PANELS ── */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: .95rem; font-weight: 600; }
.panel-link { font-size: .82rem; color: var(--accent); }

/* ── DASHBOARD GRID ── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ── ACCOUNT CARDS ── */
.account-list { padding: 10px; }
.account-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.account-card:hover { background: var(--bg-elevated); }
.account-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; color: var(--accent);
}
.account-info { flex: 1; }
.account-info strong { display: block; font-size: .88rem; }
.account-stats { text-align: right; }
.account-stats .micro { font-size: .75rem; color: var(--text-muted); }

/* ── ACTIVITY FEED ── */
.activity-feed { padding: 8px 12px; max-height: 320px; overflow-y: auto; }
.activity-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: .82rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-time { color: var(--text-muted); min-width: 42px; }
.activity-type { font-size: .72rem; }
.activity-msg { color: var(--text-secondary); flex: 1; }

/* ── BADGES ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 500;
}
.badge.success   { background: var(--green-bg);  color: var(--green); }
.badge.error     { background: var(--red-bg);    color: var(--red); }
.badge.warning   { background: var(--yellow-bg); color: var(--yellow); }
.badge.muted     { background: var(--bg-elevated); color: var(--text-muted); }

.stat-badge { font-size: .78rem; padding: 3px 10px; border-radius: 12px; }
.stat-badge.pending { background: var(--yellow-bg); color: var(--yellow); }
.stat-badge.active  { background: var(--green-bg);  color: var(--green); }

/* ── PLATFORM TAGS ── */
.platform-tag {
  display: inline-block; padding: 2px 8px;
  border-radius: 4px; font-size: .75rem; font-weight: 600;
}
.platform-tag.threads  { background: #1a1a2e; color: #c9a0dc; }
.platform-tag.facebook { background: #1a2540; color: #6ca0dc; }

/* ── STATUS DOTS ── */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); }

/* ── TABLES ── */
.table-wrap { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse;
  font-size: .85rem;
}
.table th {
  text-align: left; padding: 10px 14px;
  font-weight: 600; font-size: .75rem;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-elevated); }

.table .actions { white-space: nowrap; }
.table strong { color: var(--text-primary); }
.table .muted { color: var(--text-muted); }

/* ── POST TITLE CELL ── */
.post-title-cell { display: flex; flex-direction: column; gap: 2px; }
.post-original { font-size: .87rem; }
.post-rewritten { font-size: .79rem; }

/* ── QUALITY BAR ── */
.quality-bar { display: flex; align-items: center; gap: 8px; }
.quality-bar .quality-fill {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  width: 60px; /* base; overridden by inline style */
  max-width: 80px;
}
/* wrapper sets actual width via inline style on child */
.quality-bar { width: 100px; }
.quality-label { font-size: .75rem; color: var(--text-muted); }

/* ── SOURCE CARDS ── */
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.source-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.source-card:hover { border-color: var(--accent); }
.source-header { display: flex; justify-content: space-between; align-items: center; }
.source-header h3 { font-size: .95rem; }
.source-url { font-size: .78rem; word-break: break-all; }
.source-meta { display: flex; flex-direction: column; gap: 3px; font-size: .8rem; color: var(--text-muted); }
.source-meta span strong { color: var(--text-secondary); }
.source-actions { display: flex; gap: 8px; margin-top: auto; }
.source-error { font-size: .78rem; color: var(--red); background: var(--red-bg); padding: 6px 10px; border-radius: var(--radius-sm); }

/* ── FILTER BAR ── */
.filter-bar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label { font-size: .82rem; color: var(--text-muted); }

/* ── FORM CONTROLS ── */
.form-control {
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-primary); padding: 8px 12px;
  border-radius: var(--radius); font-size: .85rem;
  width: 100%; font-family: inherit;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }
.form-control-sm { padding: 5px 10px; font-size: .78rem; width: auto; }

select.form-control { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: .82rem; color: var(--text-muted); margin-bottom: 5px; }

/* ── SECTION HEADER ── */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.section-header p { font-size: .85rem; }

/* ── ACTIONS BAR ── */
.actions-bar {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  margin-top: 8px;
}
.actions-bar h3 { font-size: .9rem; margin-bottom: 12px; }

/* ── EMPTY STATE ── */
.empty-state {
  padding: 40px 20px; text-align: center;
  color: var(--text-muted); font-size: .88rem;
}
.empty-state.full-width { grid-column: 1 / -1; }

/* ── POST DETAIL (modal body) ── */
.post-detail .detail-row { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.post-detail .detail-row:last-child { border-bottom: none; }
.post-detail label { min-width: 100px; font-size: .78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.post-detail span, .post-detail a { font-size: .88rem; color: var(--text-secondary); word-break: break-word; }

/* ── POST PREVIEW (scheduled table) ── */
.post-preview { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── BAR CHART (analytics) ── */
.chart-placeholder { padding: 20px; min-height: 160px; display: flex; align-items: flex-end; }
.chart-loading { color: var(--text-muted); font-size: .85rem; align-self: center; width: 100%; text-align: center; }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; width: 100%; height: 120px; }
.bar-item { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; justify-content: flex-end; }
.bar { background: var(--accent); border-radius: 3px 3px 0 0; width: 100%; min-width: 8px; max-width: 40px; transition: background .15s; }
.bar:hover { background: var(--accent-hover); }
.bar-label { font-size: .68rem; color: var(--text-muted); margin-top: 4px; }

/* ── FLASH / TOAST ── */
.flash-messages { padding: 0 28px; }
.flash { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 10px; font-size: .85rem; animation: slideDown .25s ease; }
.flash-success  { background: var(--green-bg);  color: var(--green);  border: 1px solid var(--green); }
.flash-error    { background: var(--red-bg);    color: var(--red);    border: 1px solid var(--red); }
.flash-info     { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }

.toast-container { position: fixed; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-primary); padding: 12px 18px;
  border-radius: var(--radius); font-size: .84rem;
  box-shadow: var(--shadow);
  animation: slideIn .25s ease;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); color: var(--red); }
.toast.info    { border-color: var(--accent); }

@keyframes slideDown { from { opacity:0; transform: translateY(-8px); } to { opacity:1; transform: translateY(0); } }
@keyframes slideIn   { from { opacity:0; transform: translateX(30px); } to { opacity:1; transform: translateX(0); } }

/* ── MODALS ── */
.modal { display: none; position: fixed; inset: 0; z-index: 500; }
.modal.open { display: block; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal-box {
  position: relative; z-index: 1;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 12px; width: 90%; max-width: 460px;
  margin: 12vh auto 0;
  padding: 28px;
  box-shadow: var(--shadow);
  max-height: 80vh; overflow-y: auto;
}
.modal-box.modal-lg { max-width: 640px; }
.modal-title { font-size: 1.1rem; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar .logo-text, .nav-links li a span:not(.nav-icon) { display: none; }
  .main-content { margin-left: 60px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .source-grid { grid-template-columns: 1fr; }
}