/* ================================================
   Niche Websites Dashboard — Styles
   ================================================ */

:root {
    --bg:            #f5f6f8;
    --surface:       #ffffff;
    --border:        #e3e6eb;
    --text:          #1a1d22;
    --text-muted:    #6b7280;
    --primary:       #1e40af;
    --primary-hover: #1e3a8a;
    --success:       #059669;
    --success-bg:    #d1fae5;
    --warn:          #b45309;
    --warn-bg:       #fef3c7;
    --error:         #b91c1c;
    --error-bg:      #fee2e2;
    --off:           #6b7280;
    --off-bg:        #e5e7eb;
    --shadow-sm:     0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:     0 2px 6px rgba(0,0,0,0.06);
    --radius:        6px;
}

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

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

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

code {
    background: var(--off-bg);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* ---------- Layout ---------- */

.wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    box-shadow: var(--shadow-sm);
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; }

.brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
}
.brand:hover { text-decoration: none; }

.topnav {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 0.9rem;
}
.topnav a { color: var(--text); }
.topnav .user { color: var(--text-muted); }
.topnav .logout { color: var(--primary); }

.main {
    padding: 32px 0 48px;
    min-height: calc(100vh - 120px);
}

.footer {
    padding: 24px 0;
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---------- Page head ---------- */

.page-head { margin-bottom: 24px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.6rem; }
.page-head .muted { margin: 0; }
.crumbs { margin: 0 0 8px; font-size: 0.9rem; }

/* ---------- Stat grid ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
}
.stat-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.1;
}
.stat-value.stat-small { font-size: 1rem; font-weight: 500; }
.stat-danger { color: var(--error); font-size: 0.9rem; font-weight: 500; margin-left: 4px; }

/* ---------- Sections ---------- */

.section { margin-bottom: 32px; }
.section h2 {
    margin: 0 0 12px;
    font-size: 1.15rem;
    font-weight: 600;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 32px;
}

/* ---------- Tables ---------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.table thead {
    background: #fafbfc;
    border-bottom: 1px solid var(--border);
}
.table th, .table td {
    padding: 12px 14px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}
.table tbody tr:last-child td { border-bottom: none; }
.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .center { text-align: center; padding: 32px 14px; }
.table .muted-cell { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: 4px; }
.table.table-tight { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table.table-tight th, .table.table-tight td { padding: 10px 12px; font-size: 0.88rem; }

.site-name { font-weight: 600; }
.site-domain { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }
.query { max-width: 280px; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.3;
}
.badge-ok    { background: var(--success-bg); color: var(--success); }
.badge-warn  { background: var(--warn-bg);    color: var(--warn); }
.badge-error { background: var(--error-bg);   color: var(--error); }
.badge-off   { background: var(--off-bg);     color: var(--off); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-block;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: #f9fafb; text-decoration: none; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-outline { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }

/* ---------- Alerts ---------- */

.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin: 12px 0;
    font-size: 0.92rem;
}
.alert-error   { background: var(--error-bg);   color: var(--error);   border: 1px solid #fca5a5; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #6ee7b7; }
.alert-warn    { background: var(--warn-bg);    color: var(--warn);    border: 1px solid #fcd34d; }

/* ---------- Auth pages ---------- */

.auth-card {
    max-width: 400px;
    margin: 80px auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow-md);
}
.auth-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.auth-card .muted { margin: 0 0 20px; }

.auth-card label {
    display: block;
    margin-bottom: 14px;
    font-weight: 500;
    font-size: 0.92rem;
}
.auth-card input[type=email],
.auth-card input[type=password],
.auth-card input[type=text] {
    display: block;
    width: 100%;
    padding: 10px 12px;
    margin-top: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
}
.auth-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}
.auth-card .btn-primary {
    width: 100%;
    padding: 11px;
    font-size: 0.95rem;
    margin-top: 4px;
}
.auth-card small.muted {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: normal;
}
.auth-links {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
}

/* ---------- Utilities ---------- */

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }


/* ================================================
   Blog post editor + section head styles
   Append to the existing styles.css
   ================================================ */

/* Section head with inline action button (e.g. "+ New post") */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.section-head h2 { margin: 0; }

/* Post editor form */
.post-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    box-shadow: var(--shadow-sm);
    max-width: 900px;
}

.form-row {
    margin-bottom: 18px;
}

.form-row label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
}

.form-row .req { color: var(--error); }

.form-row input[type=text],
.form-row textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}

.form-row input[type=text]:focus,
.form-row textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.form-row small.muted {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.form-row small code {
    background: transparent;
    padding: 0;
    color: var(--text-muted);
}

/* Markdown body — monospace, larger height */
.body-editor {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.88rem;
    line-height: 1.55;
    min-height: 500px;
    resize: vertical;
}

/* Inline row (checkbox + published-at note) */
.form-row-inline {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0 !important;
    font-weight: 500 !important;
    cursor: pointer;
}
.checkbox-row input[type=checkbox] {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
}

/* Form actions row */
.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 24px;
    flex-wrap: wrap;
}

.form-actions-spacer { flex: 1; }

.btn-danger {
    background: var(--error);
    border-color: var(--error);
    color: white;
}
.btn-danger:hover {
    background: #991b1b;
    border-color: #991b1b;
}

/* ================================================
   Blog editor v2 — matches the engine's admin styling
   REPLACES the previous styles-additions.css append
   Append this block to your existing assets/styles.css
   ================================================ */

/* Section head with inline action button (e.g. "Write new post") */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.section-head h2 { margin: 0; }

/* Card container for form sections */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

/* Post editor form wrapper */
.post-editor { max-width: 1100px; }

/* Form fields inside cards */
.field { display: block; margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }

.field-label {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 6px;
    color: var(--text);
}
.field-label small {
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 6px;
}

.field input[type=text],
.field textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
}
.field input[type=text]:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.field-help {
    display: block;
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.field-help code {
    background: transparent;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.85em;
}

/* Two-column: body textarea + cheatsheet */
.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 32px;
}
@media (max-width: 900px) {
    .editor-grid { grid-template-columns: 1fr; }
}

.body-editor {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    min-height: 520px;
    resize: vertical;
}

/* Cheatsheet panel */
.cheatsheet {
    position: sticky;
    top: 1rem;
}
.cheatsheet h3 {
    margin: 0 0 12px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}
.cheat-code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    color: #334155;
}
.cheat-code code {
    background: transparent;
    padding: 0;
    font-size: inherit;
}
.cheat-gap { margin-top: 0.6rem; }
.cheat-note {
    margin: 0.6rem 0 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}
.cheat-note code {
    background: var(--off-bg);
    padding: 1px 4px;
    font-size: 0.85em;
}
.cheat-note-dim { color: #94a3b8; }

/* Checkbox row (publish toggle) */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
}
.checkbox-row input[type=checkbox] {
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
}

/* Action bar at bottom of editor */
.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
    flex-wrap: wrap;
}
.form-actions-spacer { flex: 1; }

/* Inline form used inside table rows for publish/delete buttons */
.inline-form {
    display: inline-flex;
    gap: 4px;
    margin: 0;
    padding: 0;
}

/* Danger button */
.btn-danger {
    background: var(--error);
    border-color: var(--error);
    color: white;
}
.btn-danger:hover {
    background: #991b1b;
    border-color: #991b1b;
}


/* ================================================
   Fix for narrower Actions column in side-by-side layout
   Append this to your existing assets/styles.css
   ================================================ */

/* Wrap action buttons in a flex container so they wrap onto multiple lines */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: flex-end;
}

.action-buttons .btn,
.action-buttons .inline-form {
    margin: 0;
}

.action-buttons .inline-form {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* Make the Actions column not fight for space */
.table .actions { min-width: 0; }
