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

:root {
  --bg: #f5f5f5;
  --surface: #fff;
  --fg: #1a1a1a;
  --muted: #777;
  --border: #ddd;
  --accent: #2a5298;
  --accent-h: #1a3d7a;
  --danger: #c0392b;
  --success: #27ae60;
  --sidebar-bg: #1a1a2e;
  --sidebar-fg: #ccc;
  --sidebar-active: #fff;
  --sidebar-hover: rgba(255,255,255,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg); color: var(--fg); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── Sidebar ── */
.sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand a {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.sidebar-nav {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
}
.nav-section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.3);
  padding: 0.5rem 1rem 0.25rem;
}
.sidebar-nav a {
  color: var(--sidebar-fg);
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar-nav a.active { color: var(--sidebar-active); border-left-color: #6c8ebf; background: rgba(255,255,255,0.05); }
.sidebar-nav a.logout { color: #e57373; margin-top: auto; }
.sidebar-nav a.logout:hover { background: rgba(229, 115, 115, 0.1); }

/* ── Content area ── */
.content { margin-left: 200px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* ── Topbar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-size: 1rem; font-weight: 600; }

main { padding: 1.5rem; flex: 1; }

/* ── Dashboard cards ── */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.site-card-header { display: flex; align-items: center; justify-content: space-between; }
.site-card-header h3 { font-size: 1rem; font-weight: 600; }
.site-card-header h3 a { color: var(--fg); text-decoration: none; }
.site-card-header h3 a:hover { color: var(--accent); }
.ext-link { color: var(--muted); font-size: 1rem; }
.site-stats { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--muted); }
.site-stats span { background: var(--bg); padding: 0.2em 0.5em; border-radius: 3px; }
.recent-list { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; }
.recent-list li { font-size: 0.82rem; display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.recent-list a { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list a:hover { color: var(--accent); }
.item-date { color: var(--muted); font-size: 0.75rem; white-space: nowrap; font-family: var(--mono); }
.site-card-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; padding-top: 0.25rem; border-top: 1px solid var(--border); }
.empty-sm { font-size: 0.82rem; color: var(--muted); font-style: italic; }

/* ── Buttons ── */
.btn-primary {
  background: var(--accent); color: #fff; padding: 0.45em 1em;
  border-radius: 5px; font-size: 0.85rem; border: none; cursor: pointer;
  font-family: var(--font); font-weight: 500; text-decoration: none; display: inline-block;
}
.btn-primary:hover { background: var(--accent-h); text-decoration: none; color: #fff; }
.btn-secondary {
  background: var(--bg); color: var(--fg); padding: 0.45em 1em;
  border-radius: 5px; font-size: 0.85rem; border: 1px solid var(--border);
  cursor: pointer; font-family: var(--font); text-decoration: none; display: inline-block;
}
.btn-secondary:hover { background: var(--border); text-decoration: none; color: var(--fg); }
.btn-sm {
  font-size: 0.75rem; padding: 0.2em 0.55em; border-radius: 4px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
  cursor: pointer; font-family: var(--font); text-decoration: none; display: inline-block;
}
.btn-sm:hover { background: var(--border); color: var(--fg); text-decoration: none; }
.btn-sm.danger { color: var(--danger); border-color: #f5c6c4; background: #fdf5f5; }
.btn-sm.danger:hover { background: #fde8e7; }
.btn-sm-primary {
  font-size: 0.75rem; padding: 0.25em 0.65em; border-radius: 4px;
  background: var(--accent); color: #fff; border: none;
  cursor: pointer; font-family: var(--font); text-decoration: none; display: inline-block;
}
.btn-sm-primary:hover { background: var(--accent-h); text-decoration: none; color: #fff; }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; font-size: 0.88rem; }
.data-table th { text-align: left; padding: 0.6rem 1rem; background: #f5f5f5; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafafa; }
.data-table a { color: var(--fg); font-weight: 500; }
.data-table a:hover { color: var(--accent); text-decoration: none; }
.actions { display: flex; gap: 0.35rem; align-items: center; }
.status { font-size: 0.72rem; font-family: var(--mono); padding: 0.2em 0.5em; border-radius: 3px; }
.status.published { background: #e8f5e9; color: var(--success); }
.status.draft { background: #fff8e7; color: #b7860c; }

/* ── Editor ── */
.editor-wrap { display: flex; flex-direction: column; }
.editor-meta { background: var(--surface); border: 1px solid var(--border); border-radius: 8px 8px 0 0; padding: 1rem 1.25rem; border-bottom: none; }
.title-input { width: 100%; font-size: 1.4rem; font-weight: 600; border: none; background: transparent; color: var(--fg); font-family: var(--font); padding: 0; margin-bottom: .75rem; outline: none; }
.title-input::placeholder { color: #bbb; }
.meta-row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.meta-row input[type=date], .meta-row input[type=text], .meta-row input[type=number] { padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 4px; font-size: .8rem; font-family: var(--mono); background: var(--bg); color: var(--fg); }
.meta-row input[type=text] { flex: 1; min-width: 150px; }
.meta-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.toggle-label { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); cursor: pointer; }
.editor-body { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-bottom: none; height: 60vh; min-height: 340px; }
.editor-pane { display: flex; flex-direction: column; overflow: hidden; }
.editor-pane + .editor-pane { border-left: 1px solid var(--border); }
.pane-label { font-size: .7rem; font-family: var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: .4rem 1rem; background: #f5f4f1; border-bottom: 1px solid var(--border); }
#md-input { flex: 1; resize: none; border: none; padding: 1rem 1.25rem; font-family: var(--mono); font-size: .83rem; line-height: 1.7; background: var(--surface); color: var(--fg); outline: none; }
.preview-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; font-size: .92rem; line-height: 1.75; }
.preview-body h1,.preview-body h2,.preview-body h3 { font-weight:600; margin:1.25rem 0 .4rem; }
.preview-body p { margin:.65rem 0; }
.preview-body code { font-family:var(--mono); font-size:.82em; background:#f0ede8; padding:.1em .3em; border-radius:3px; }
.preview-body pre { background:#1e1e1e; color:#d4d4d4; padding:.75rem 1rem; border-radius:4px; overflow-x:auto; margin:.75rem 0; font-size:.78rem; }
.preview-body pre code { background:none; padding:0; color:inherit; }
.preview-body ul,.preview-body ol { margin:.5rem 0 .5rem 1.25rem; }
.preview-body blockquote { border-left:3px solid var(--border); padding-left:.75rem; color:var(--muted); font-style:italic; }
.preview-body a { color:var(--accent); }
.preview-body img { max-width:100%; }
.editor-actions { display: flex; gap: .6rem; align-items: center; padding: .75rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 8px 8px; }

/* ── Images ── */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-top: 1rem; }
.img-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.img-card img { width: 100%; height: 120px; object-fit: cover; display: block; background: var(--bg); }
.img-meta { padding: .5rem; }
.img-actions { display: flex; gap: .3rem; flex-wrap: wrap; }
#upload-status { font-size: .85rem; margin-bottom: .75rem; }
.img-grid.drag-over { outline: 2px dashed var(--accent); border-radius: 6px; background: #f0f4fc; }

/* ── Settings ── */
.settings-form { max-width: 600px; }
.settings-group { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem; }
.settings-group h3 { font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 1rem; }
.settings-row { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.settings-row:last-child { margin-bottom: 0; }
.settings-row label { font-size: .75rem; font-weight: 600; color: var(--muted); font-family: var(--mono); }
.settings-row input { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 5px; font-size: .88rem; font-family: var(--font); background: var(--bg); color: var(--fg); width: 100%; }
.settings-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.secret-input { font-family: var(--mono); }
.settings-actions { display: flex; flex-direction: column; gap: .5rem; }
.settings-note { font-size: .78rem; color: var(--muted); }
.flash { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .88rem; }
.flash.success { background: #e8f5e9; color: var(--success); border: 1px solid #c8e6c9; }

/* ── Login ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar-bg); }
.login-box { background: var(--surface); border-radius: 10px; padding: 2rem; width: 320px; }
.login-box h2 { font-size: 1.1rem; margin-bottom: 1.25rem; color: var(--fg); }
.login-box label { display: flex; flex-direction: column; gap: .35rem; font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .85rem; }
.login-box input { padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 5px; font-size: .9rem; background: var(--bg); color: var(--fg); width: 100%; }
.login-box input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-box button { width: 100%; margin-top: .25rem; }
.error { color: var(--danger); font-size: .85rem; margin-bottom: 1rem; }

/* ── Misc ── */
.empty { color: var(--muted); font-style: italic; font-size: .88rem; }
code { font-family: var(--mono); font-size: .82em; background: #f0ede8; padding: .1em .3em; border-radius: 3px; }

@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: unset; position: relative; height: auto; flex-direction: row; flex-wrap: wrap; }
  .content { margin-left: 0; }
  .editor-body { grid-template-columns: 1fr; height: auto; }
  .editor-body .editor-pane:last-child { display: none; }
  #md-input { height: 50vh; }
}

/* ── Subnav ── */
.subnav {
  display: flex;
  flex-direction: column;
  margin: 0.1rem 0 0.5rem 0;
  border-left: 2px solid rgba(255,255,255,0.08);
  margin-left: 1rem;
}
.subnav a {
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
  color: rgba(255,255,255,0.5);
  border-left: 2px solid transparent;
  margin-left: -2px;
}
.subnav a:hover { color: #fff; background: var(--sidebar-hover); text-decoration: none; }
.subnav a.active { color: #fff; border-left-color: #6c8ebf; }

/* ── CSS Editor ── */
main.full-width { padding: 0; max-width: none; }

.css-editor-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 52px);
}

.css-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.css-pane.preview-pane { border-right: none; }

#css-input {
  flex: 1;
  resize: none;
  border: none;
  padding: 1rem 1.25rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.6;
  background: #1e1e1e;
  color: #d4d4d4;
  outline: none;
  tab-size: 2;
}

.css-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.css-note { font-size: 0.75rem; color: var(--muted); margin-left: auto; font-family: var(--mono); }

#preview-frame {
  flex: 1;
  border: none;
  width: 100%;
  height: 100%;
  background: #fff;
}

@media (max-width: 900px) {
  .css-editor-wrap { grid-template-columns: 1fr; }
  .css-pane.preview-pane { display: none; }
}

/* ── Redirect setting ── */
.redirect-group { border: 1px solid var(--border); }
.redirect-group h3 { color: var(--fg); }
.redirect-active { border-color: #f5a623; background: #fffbf0; }
.redirect-active h3 { color: #b7680c; }
.redirect-status {
  font-size: 0.82rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #e8f5e9;
  color: var(--success);
  border-radius: 4px;
}
.redirect-status.inactive { background: var(--bg); color: var(--muted); }
.redirect-active .redirect-status { background: #fff3cd; color: #856404; }
.settings-desc { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.75rem; }

/* ── Flash messages ── */
.flash.error { background: #fdf5f5; color: var(--danger); border: 1px solid #f5c6c4; padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .88rem; }

/* ── Select field ── */
.settings-row select { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 5px; font-size: .88rem; font-family: var(--font); background: var(--bg); color: var(--fg); width: 100%; }
.settings-row select:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ── Service / Apache preview ── */
.service-preview {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: .75rem 1rem;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  margin-top: .5rem;
}

/* ── Mobile editor ── */
body.mobile .shell { flex-direction: column; }
body.mobile .sidebar { width: 100%; min-width: unset; position: relative; flex-direction: row; flex-wrap: wrap; height: auto; }
body.mobile .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 0.25rem 0.5rem; gap: 0.25rem; }
body.mobile .sidebar-nav a { padding: 0.35rem 0.6rem; font-size: 0.78rem; border-left: none; border-radius: 4px; }
body.mobile .sidebar-nav .nav-section-label { display: none; }
body.mobile .subnav { flex-direction: row; margin: 0; border-left: none; }
body.mobile .content { margin-left: 0; }
body.mobile main { padding: 0.75rem; }

.mobile-editor-wrap { padding: 0; }
.mobile-title-input {
  display: block; width: 100%; font-size: 1.2rem; font-weight: 600;
  border: none; border-bottom: 2px solid var(--border); background: transparent;
  color: var(--fg); font-family: var(--font); padding: 0.75rem 1rem 0.5rem;
  margin-bottom: 0; outline: none;
}
.mobile-title-input:focus { border-color: var(--accent); }

.mobile-toolbar {
  display: flex; flex-wrap: nowrap; overflow-x: auto;
  gap: 0.2rem; padding: 0.4rem 0.75rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.mobile-toolbar button {
  min-width: 44px; height: 44px; font-size: 0.9rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--fg); cursor: pointer;
  font-family: var(--font); padding: 0 0.5rem; touch-action: manipulation;
  white-space: nowrap; flex-shrink: 0;
}
.mobile-toolbar button:active { background: var(--border); }

.mobile-body-wrap { position: relative; }
.mobile-body-wrap #md-input {
  width: 100%; min-height: 50vh; padding: 0.75rem 1rem;
  border: none; border-bottom: 1px solid var(--border);
  font-size: 1rem; font-family: var(--mono); line-height: 1.7;
  background: var(--surface); color: var(--fg); outline: none; resize: none;
}
.mobile-preview {
  min-height: 50vh; padding: 0.75rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.hidden { display: none !important; }

.mobile-meta-details {
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.mobile-meta-details summary {
  padding: 0.75rem 1rem; cursor: pointer; font-size: 0.88rem;
  font-weight: 500; color: var(--muted); list-style: none; user-select: none;
}
.mobile-meta-details summary::-webkit-details-marker { display: none; }
.mobile-meta-fields {
  padding: 0.75rem 1rem; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.75rem;
}
.mobile-meta-fields label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.8rem; color: var(--muted); font-weight: 500;
}
.mobile-meta-fields input[type=text],
.mobile-meta-fields input[type=date] {
  padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: 5px;
  font-size: 0.95rem; font-family: var(--font); background: var(--bg); color: var(--fg); width: 100%;
}
.draft-toggle-mobile { flex-direction: row !important; align-items: center; gap: 0.5rem; }
.draft-toggle-mobile input { width: auto; }

.mobile-actions {
  display: flex; gap: 0.75rem; padding: 0.75rem 1rem;
  background: var(--surface); border-top: 1px solid var(--border);
}
.mobile-save-btn {
  flex: 1; padding: 0.85rem; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; font-size: 1rem; font-weight: 600;
  cursor: pointer; font-family: var(--font); touch-action: manipulation;
}
.mobile-save-btn:active { background: var(--accent-h); }
.mobile-cancel-btn {
  padding: 0.85rem 1.25rem; background: var(--bg); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px; font-size: 1rem;
  cursor: pointer; font-family: var(--font); text-decoration: none;
  display: flex; align-items: center; touch-action: manipulation;
}
.upload-status-mobile { font-size: 0.78rem; padding: 0.3rem 0.75rem; background: #e8f5e9; color: var(--success); }
.upload-status-mobile.error { background: #fdf5f5; color: var(--danger); }
.toolbar-img-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; font-size: 1.1rem; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0 0.4rem; flex-shrink: 0;
}

#css-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  height: 100%;
}