:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-sidebar: #1f2430;
  --text: #1a1d24;
  --text-muted: #6b7280;
  --text-on-dark: #e6e8ee;
  --text-on-dark-muted: #9099a8;
  --border: #e3e5ea;
  --primary: #2c54e4;
  --primary-hover: #1f43c4;
  --primary-soft: #e8eefb;
  --danger: #c83a3a;
  --success: #1f8a4e;
  --warning: #b46812;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 36, 0.06);
  --shadow-md: 0 4px 14px rgba(20, 24, 36, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(44, 84, 228, 0.08), transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(31, 36, 48, 0.05), transparent 60%),
    var(--bg);
}
.login-shell { width: 100%; max-width: 420px; padding: 24px; }
.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-brand h1 {
  margin: 8px 0 2px;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.brand-sub { margin: 0; color: var(--text-muted); font-size: 13px; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 auto;
  box-shadow: var(--shadow-sm);
}
.login-footer {
  margin-top: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Forms ---------- */
.field, label.field { display: block; margin-bottom: 14px; }
.field > span, .field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
input[type="text"], input[type="password"], input[type="email"], textarea, select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 90px; font-family: inherit; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-error {
  margin: 8px 0 0;
  background: #fdecec;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
}
.form-success {
  margin: 8px 0 0;
  background: #e7f5ec;
  color: var(--success);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: white;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: #c4c8d0; }
.btn-ghost {
  background: transparent;
  color: var(--text-on-dark-muted);
  border-color: rgba(255,255,255,0.12);
}
.btn-ghost:hover { color: var(--text-on-dark); border-color: rgba(255,255,255,0.25); }
.btn-text {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}
.btn-text:hover { color: var(--text); }
.btn-text.btn-danger { color: var(--danger); }
.btn-text.btn-danger:hover { color: #8c2929; background: #fdecec; }

/* ---------- App Shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr 480px;
  min-height: 100vh;
}
.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  padding: 4px 8px;
}
.sidebar-brand .brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  font-size: 13px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; }
.brand-text span { color: var(--text-on-dark-muted); font-size: 12px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  font: inherit;
  background: transparent;
  border: none;
  color: var(--text-on-dark-muted);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--text-on-dark); }
.nav-item.active {
  background: rgba(44, 84, 228, 0.18);
  color: white;
}
.nav-icon { font-size: 14px; opacity: 0.85; }

.sidebar-footer {
  margin-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-footer #siteInfo { color: var(--text-on-dark-muted); }
.sidebar-footer .btn-text { color: var(--text-on-dark-muted); }
.sidebar-footer .btn-text:hover { color: white; }
.logout-form { margin: 0; }

/* ---------- Content ---------- */
.content {
  padding: 28px 36px;
  max-width: 920px;
  width: 100%;
}
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.content-header h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.01em;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.save-status {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 140px;
  text-align: right;
}
.save-status.success { color: var(--success); }
.save-status.error { color: var(--danger); }
.save-status.saving { color: var(--warning); }

.content-body { display: flex; flex-direction: column; gap: 18px; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -0.005em; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card p.muted:first-of-type { margin-top: 0; }
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-row h2, .card-row h3 { margin: 0; }

/* ---------- Image upload ---------- */
.image-upload {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  background: #fafbfc;
}
.image-preview {
  max-width: 320px;
  max-height: 180px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  object-fit: cover;
}
.image-empty { margin: 0; }

/* ---------- KV list ---------- */
.kv-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  margin: 0;
}
.kv-list dt { color: var(--text-muted); font-size: 13px; }
.kv-list dd { margin: 0; }

/* ---------- Preview Pane ---------- */
.preview-pane {
  background: #e8eaed;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
}
.preview-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-height: 48px;
}
.preview-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.preview-device-btns {
  display: flex;
  gap: 4px;
}
.preview-device-btns .btn-text {
  padding: 4px 8px;
  font-size: 14px;
  color: var(--text-muted);
}
.preview-device-btns .btn-text.active {
  color: var(--primary);
  background: var(--primary-soft);
}
.preview-outer {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: #d0d3d9;
  padding: 16px 0 0;
}
.preview-browser-chrome {
  background: #fff;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  overflow: hidden;
  width: 100%;
  max-width: 448px;
  height: calc(100vh - 48px - 16px);
  display: flex;
  flex-direction: column;
}
.preview-chrome-bar {
  background: #f1f3f5;
  border-bottom: 1px solid #dde0e5;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.preview-chrome-dots {
  display: flex;
  gap: 5px;
}
.preview-chrome-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d0d3d6;
  display: block;
}
.preview-chrome-bar-url {
  flex: 1;
  background: #fff;
  border: 1px solid #dde0e5;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.preview-reload-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.preview-reload-btn:hover { color: var(--text); background: #e5e7eb; }
.preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
  display: block;
}
.preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(232, 234, 237, 0.85);
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.preview-loading.visible { opacity: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; }
  .preview-pane { display: none; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    flex-wrap: wrap;
  }
  .sidebar-brand { margin-bottom: 0; }
  .sidebar-nav {
    flex-direction: row;
    flex: 1 1 100%;
    overflow-x: auto;
    margin: 12px -16px 0;
    padding: 0 16px;
    gap: 6px;
  }
  .sidebar-nav .nav-item { white-space: nowrap; }
  .sidebar-footer { width: 100%; margin-top: 12px; padding-top: 12px; }
  .content { padding: 20px 18px; }
}
