/* ==========================================================================
   Pro Calculator AI — admin
   ========================================================================== */

:root {
  --ink: #0b1220; --paper: #ffffff; --surface: #f5f7fb; --surface-2: #eef1f7;
  --line: #dfe4ee; --muted: #5b6678; --text: #18202e;
  --brand: #1d4ed8; --brand-ink: #1640b0; --accent: #0d9488;
  --danger: #c0392b; --ok: #15803d; --warn: #b45309;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px -12px rgba(16,24,40,.18);
  --sidebar: 248px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}
[data-theme="dark"] {
  --ink: #e8edf6; --paper: #0d1320; --surface: #121a29; --surface-2: #18202f;
  --line: #26303f; --muted: #8a96a8; --text: #e8edf6; --brand: #5b8bff; --brand-ink: #7aa2ff; --accent: #2dd4bf;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px -14px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
body.admin-body {
  margin: 0; display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh;
  font-family: var(--font-body); color: var(--text); background: var(--paper); font-size: 15px;
}
h1,h2,h3 { font-family: var(--font-display); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- sidebar ---------- */
.admin-sidebar {
  background: var(--surface); border-right: 1px solid var(--line); padding: 1.25rem 1rem;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.admin-brand { display: block; margin: .25rem .5rem 1.5rem; }
.admin-brand img { height: 28px; width: auto; }
.logo-dark { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark { display: block; }

.admin-nav { display: flex; flex-direction: column; gap: .15rem; }
.admin-nav a { padding: .55rem .75rem; border-radius: var(--radius-sm); color: var(--ink); font-weight: 500; }
.admin-nav a:hover { background: var(--surface-2); text-decoration: none; }
.admin-nav a.is-active { background: var(--brand); color: #fff; }
.admin-nav-label { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 1.1rem .75rem .35rem; }

.admin-user { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: .1rem; }
.admin-user-name { font-weight: 600; }
.admin-role { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); text-transform: capitalize; }
.admin-logout { margin-top: .4rem; font-size: .85rem; }

/* ---------- main ---------- */
.admin-main { display: flex; flex-direction: column; min-width: 0; }
.admin-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 2rem; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(8px); z-index: 20;
}
.admin-title { font-size: 1.35rem; margin: 0; }
.admin-topbar-actions { display: flex; align-items: center; gap: .6rem; }
.admin-content { padding: 1.75rem 2rem 4rem; max-width: 1280px; width: 100%; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; cursor: pointer; padding: .55rem 1.1rem; border-radius: var(--radius-sm); border: 1px solid transparent; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--brand); }
.btn-block { width: 100%; }

/* ---------- panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin-bottom: 1.5rem; }
.panel h2 { font-size: 1.15rem; margin: 0 0 1rem; }
.panel h3 { font-size: .95rem; margin: 0 0 .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-family: var(--font-mono); }
.panel-danger { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.settings-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-family: var(--font-mono); }
.table .num { text-align: right; font-family: var(--font-mono); }
.table-list .list-title { font-weight: 600; }
.list-slug { display: block; font-family: var(--font-mono); font-size: .76rem; color: var(--muted); }
.row-actions { display: flex; gap: .8rem; align-items: center; justify-content: flex-end; }
.row-actions form { margin: 0; }
.link-danger { background: none; border: 0; color: var(--danger); cursor: pointer; font: inherit; padding: 0; }
.link-danger:hover { text-decoration: underline; }

.badge { display: inline-block; font-family: var(--font-mono); font-size: .72rem; padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: capitalize; }
.badge--published { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge--draft { background: var(--surface-2); color: var(--muted); }
.badge--scheduled { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: .4rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.activity li:last-child { border-bottom: 0; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .2rem; }
.stat-num { font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700; color: var(--ink); }
.stat-label { font-size: .82rem; color: var(--muted); }

/* ---------- list head ---------- */
.list-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.25rem; }
.list-search { display: flex; gap: .5rem; flex: 1; }
.list-search input { flex: 1; max-width: 360px; }

/* ---------- forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
.field-hint { font-size: .8rem; color: var(--muted); margin: .35rem 0 0; }
.field-hint code, .mono { font-family: var(--font-mono); }
.field-narrow { max-width: 160px; }

input[type=text], input[type=email], input[type=url], input[type=search],
input[type=password], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--paper); color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }

.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; font-weight: 500; cursor: pointer; }
.check input[type=checkbox] { width: auto; }

.form-actions { display: flex; gap: .75rem; margin: 1.5rem 0; }

/* ---------- CMS two-column layout ---------- */
.cms-grid { display: grid; grid-template-columns: 1fr 320px; gap: 1.5rem; align-items: start; }
.cms-main { min-width: 0; }
.cms-side { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 86px; }
.side-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.side-panel h3 { font-size: .8rem; margin: 0 0 .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-family: var(--font-mono); }
.side-panel .btn + .btn { margin-top: .5rem; }

.slug-row { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--paper); }
.slug-prefix { display: inline-flex; align-items: center; padding: 0 .6rem; background: var(--surface-2); color: var(--muted); font-family: var(--font-mono); font-size: .8rem; white-space: nowrap; }
.slug-row input { border: 0; border-radius: 0; }
.slug-row input:focus { box-shadow: none; }

/* ---------- editor blocks ---------- */
.editor-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin-bottom: 1.5rem; }
.editor-block-head { margin-bottom: 1rem; }
.editor-block-head h2 { font-size: 1.1rem; margin: 0 0 .25rem; }

/* ---------- code editor ---------- */
.code-editor { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--paper); }
.code-tabs { display: flex; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.code-tab { font: inherit; font-family: var(--font-mono); font-size: .82rem; padding: .55rem 1rem; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; }
.code-tab.is-active { color: var(--ink); border-bottom-color: var(--brand); background: var(--paper); }
.code-area { width: 100%; min-height: 240px; border: 0; border-radius: 0; font-family: var(--font-mono); font-size: 13px; line-height: 1.55; padding: 1rem; background: var(--paper); color: var(--text); resize: vertical; tab-size: 2; }
.code-area:focus { box-shadow: none; }
/* CodeMirror, when enhanced */
.code-editor .CodeMirror { height: auto; min-height: 260px; font-family: var(--font-mono); font-size: 13px; }
.code-editor .cm-editor { min-height: 260px; }
.code-editor .cm-editor .cm-scroller { font-family: var(--font-mono); }

/* ---------- FAQ builder ---------- */
.faq-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.faq-builder { display: flex; flex-direction: column; gap: .75rem; }
.faq-item { display: grid; grid-template-columns: 28px 1fr 32px; gap: .6rem; align-items: start; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .75rem; }
.faq-item.is-dragging { opacity: .5; }
.faq-item.drop-target { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 30%, transparent); }
.faq-drag { cursor: grab; color: var(--muted); font-size: 1.1rem; text-align: center; padding-top: .4rem; user-select: none; }
.faq-fields { display: flex; flex-direction: column; gap: .5rem; }
.faq-remove { background: none; border: 0; color: var(--danger); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: .2rem; }

/* ---------- toggles grid ---------- */
.toggle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; }

/* ---------- redirect form ---------- */
.redirect-row { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: .75rem; align-items: end; }
.redirect-row .field { margin: 0; }

/* ---------- pager ---------- */
.pager { display: flex; gap: .35rem; margin-top: 1.25rem; }
.pager-link { display: inline-flex; min-width: 36px; height: 36px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: .85rem; color: var(--ink); }
.pager-link.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- flash ---------- */
.flash { padding: .8rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid var(--line); }
.flash--success { background: color-mix(in srgb, var(--ok) 12%, var(--paper)); border-color: var(--ok); }
.flash--error { background: color-mix(in srgb, var(--danger) 12%, var(--paper)); border-color: var(--danger); }

/* ---------- auth ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; background: var(--surface); font-family: var(--font-body); color: var(--text); }
.auth-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-logo { display: block; height: 32px; width: auto; margin: 0 auto 1.5rem; }
.auth-title { font-size: 1.4rem; margin: 0 0 .25rem; text-align: center; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 1.5rem; font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .9rem; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .cms-grid { grid-template-columns: 1fr; }
  .cms-side { position: static; flex-direction: row; flex-wrap: wrap; }
  .cms-side .side-panel { flex: 1 1 240px; }
}
@media (max-width: 900px) {
  body.admin-body { grid-template-columns: 1fr; }
  .admin-sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; }
  .admin-nav-label { display: none; }
  .admin-user { margin: 0 0 0 auto; border: 0; padding: 0; }
  .grid-2, .settings-cols, .redirect-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
