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

:root {
  --bg:       #f3f4f6;
  --surface:  #ffffff;
  --surface2: #f9fafb;
  --border:   #e5e7eb;
  --text:     #111827;
  --muted:    #6b7280;
  --accent:   #2563eb;
  --accent-h: #1d4ed8;
  --danger:   #dc2626;
  --success:  #16a34a;
  --warning:  #d97706;
  --radius:   6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', Menlo, Consolas, monospace;
}

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

a            { color: var(--accent); text-decoration: none; }
a:hover      { text-decoration: underline; }
code, pre    { font-family: var(--mono); }
label        { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); margin-bottom: .9rem; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .5rem .75rem;
  font-size: .9rem;
  font-family: var(--font);
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
legend   { padding: 0 .5rem; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hint    { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.required { color: var(--danger); }

/* ── Nav ─────────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.nav-brand { font-weight: 700; color: var(--text); font-size: .95rem; text-decoration: none; }
.nav-links  { display: flex; gap: 1.25rem; align-items: center; font-size: .875rem; }
.nav-links a { color: var(--muted); }
.nav-links a:hover { color: var(--text); text-decoration: none; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.4rem; }
.header-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.back-link { font-size: .8rem; color: var(--muted); display: block; margin-bottom: .25rem; }
.back-link:hover { color: var(--text); text-decoration: none; }
.muted { color: var(--muted); font-weight: 400; }
.muted-link { font-size: .85rem; color: var(--muted); }

.two-col { display: grid; grid-template-columns: 320px 1fr; gap: 1.5rem; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .45rem .9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .85rem; font-family: var(--font); font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn:hover    { background: #e5e7eb; border-color: #d1d5db; text-decoration: none; }
.btn-primary  { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-danger   { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm       { padding: .3rem .65rem; font-size: .78rem; }
.btn-full     { width: 100%; }
.btn-link     { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: inherit; font-family: inherit; }
.btn-row      { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h2, .card h3 { font-size: 1rem; margin-bottom: 1rem; }

/* ── Alerts / flash ──────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
}
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

/* ── Status badges ───────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block; padding: .2em .7em;
  border-radius: 999px; font-size: .75rem; font-weight: 600;
}
.status-active   { background: #f0fdf4; color: var(--success); }
.status-inactive { background: #f3f4f6; color: var(--muted);   }
.status-failed   { background: #fef2f2; color: var(--danger);  }
.badge-live  { background: #f0fdf4; color: var(--success); padding: .15em .6em; border-radius: 999px; font-size:.75rem; }
.badge-draft { background: #fffbeb; color: var(--warning); padding: .15em .6em; border-radius: 999px; font-size:.75rem; }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-body  { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box   { width: 100%; max-width: 360px; padding: 2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.login-box h1 { font-size: 1.25rem; margin-bottom: 1.5rem; }

/* ── Dashboard site grid ─────────────────────────────────────────────────── */
.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}
.site-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .75rem; }
.site-title    { font-weight: 600; font-size: .95rem; }
.site-domain   { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.site-stats    { font-size: .8rem; color: var(--muted); display: flex; gap: 1rem; margin-bottom: .75rem; }
.site-actions  { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ── Posts table ─────────────────────────────────────────────────────────── */
.post-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.post-table th { text-align: left; padding: .6rem .75rem; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
.post-table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.post-table tr:hover td { background: #f9fafb; }
.row-actions { display: flex; gap: .35rem; }
.tag { display: inline-block; background: var(--surface2); border: 1px solid var(--border); border-radius: 999px; padding: .1em .55em; font-size: .72rem; color: var(--muted); margin-right: .2rem; }

/* ── Post editor ─────────────────────────────────────────────────────────── */
.edit-layout { display: grid; grid-template-columns: 1fr 280px; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .edit-layout { grid-template-columns: 1fr; } }

.title-input {
  width: 100%; font-size: 1.4rem; font-weight: 600;
  background: transparent; border: none; border-bottom: 2px solid var(--border);
  color: var(--text); padding: .5rem 0; margin-bottom: 1rem; outline: none;
  font-family: var(--font);
}
.title-input:focus { border-bottom-color: var(--accent); }

.edit-main .EasyMDEContainer { border-radius: var(--radius); overflow: hidden; }
.CodeMirror { background: #fff !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.editor-toolbar { background: #f9fafb !important; border-color: var(--border) !important; }
.editor-toolbar button { color: #374151 !important; }
.editor-toolbar button:hover { background: #e5e7eb !important; }

.image-input-row { display: flex; gap: .4rem; }
.image-input-row input { flex: 1; }
.cover-preview { margin-top: .5rem; max-height: 100px; border-radius: var(--radius); object-fit: cover; }

.upload-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s;
  font-size: .85rem; color: var(--muted);
}
.upload-drop:hover, .upload-drop.drag-over { border-color: var(--accent); color: var(--text); }
.upload-drop-lg { padding: 2.5rem; }

.uploaded-url  { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
.uploaded-row  { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
.thumb         { width: 40px; height: 40px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }

.checkbox-label { flex-direction: row; align-items: center; gap: .5rem; cursor: pointer; }

/* ── Media grid ──────────────────────────────────────────────────────────── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.media-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.media-thumb { aspect-ratio: 1; overflow: hidden; background: var(--surface2); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .2s; }
.media-thumb img:hover { opacity: .85; }
.media-info { padding: .6rem; }
.media-name { font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: .2rem; }
.media-meta { font-size: .7rem; color: var(--muted); margin-bottom: .5rem; }
.media-actions { display: flex; gap: .3rem; }

/* Mini grid for modal */
.media-grid-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .5rem; max-height: 400px; overflow-y: auto; }
.mini-thumb { cursor: pointer; border: 2px solid transparent; border-radius: 4px; overflow: hidden; }
.mini-thumb:hover { border-color: var(--accent); }
.mini-thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.mini-thumb span { display: block; font-size: .65rem; padding: .2rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 90%; max-width: 600px; max-height: 80vh; overflow: auto; padding: 1.25rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

/* ── Config list ─────────────────────────────────────────────────────────── */
.config-list { display: grid; grid-template-columns: 100px 1fr; gap: .4rem .75rem; font-size: .85rem; }
.config-list dt { color: var(--muted); }
.config-list dd { word-break: break-all; }

/* ── Logs ────────────────────────────────────────────────────────────────── */
.logs-card { height: fit-content; }
.log-output { font-size: .75rem; color: var(--muted); white-space: pre-wrap; word-break: break-all; max-height: 360px; overflow-y: auto; line-height: 1.5; }

/* ── Form footer ─────────────────────────────────────────────────────────── */
.form-footer { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding-top: .5rem; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .65rem 1.1rem;
  font-size: .85rem; z-index: 300; box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.toast-error { border-color: var(--danger); color: var(--danger); }

.empty { color: var(--muted); padding: 2rem 0; }
