:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --line: #e2e5ea;
    --accent: #2563eb;
    --ok: #15803d;
    --warn: #b45309;
    --err: #b91c1c;
    --info: #1d4ed8;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    background: #111827;
    color: #fff;
    padding: 0.75rem 1.5rem;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar a, .topbar .brand {
    color: #e5e7eb;
    text-decoration: none;
}

.topbar .brand { font-weight: 700; margin-right: auto; }
.topbar a:hover { color: #fff; text-decoration: underline; }

main {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; margin-top: 2rem; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--line);
    font-size: 0.9rem;
    vertical-align: top;
}

th { background: #f0f1f4; font-weight: 600; }
tr:last-child td { border-bottom: none; }

.platforms { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #e5e7eb;
    color: #374151;
}

.st-published { background: #dcfce7; color: var(--ok); }
.st-scheduled { background: #dbeafe; color: var(--info); }
.st-processing { background: #fef9c3; color: var(--warn); }
.st-partial { background: #ffedd5; color: var(--warn); }
.st-failed, .st-error { background: #fee2e2; color: var(--err); }
.st-cancelled, .st-skipped { background: #e5e7eb; color: var(--muted); }

.muted { color: var(--muted); }

.alert { padding: 0.6rem 0.85rem; border-radius: 6px; margin: 1rem 0; }
.alert.error { background: #fee2e2; color: var(--err); white-space: pre-wrap; }
.alert.flash { background: #dcfce7; color: var(--ok); }

.button, button {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
}

.button.secondary { background: #e5e7eb; color: #374151; }
button.danger { background: var(--err); }

.inline { display: inline; }
button.link {
    background: none;
    color: #e5e7eb;
    padding: 0;
}

textarea {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

form label { display: block; margin-bottom: 0.35rem; font-weight: 600; }
.actions { margin-top: 1rem; display: flex; gap: 0.75rem; align-items: center; }

.facts { display: grid; grid-template-columns: 120px 1fr; gap: 0.4rem 1rem; }
.facts dt { font-weight: 600; color: var(--muted); }
.facts dd { margin: 0; }

pre {
    background: #0b1020;
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 8px;
    overflow: auto;
    font-size: 0.8rem;
}

.error-cell { color: var(--err); }

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 2rem;
    width: 320px;
    margin: 0;
}

.login input {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.login button { width: 100%; }

main.wide { max-width: 1400px; }

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: 1rem;
}

.panel h2 { margin-top: 0; }

.panel label { display: block; margin-bottom: 0.6rem; font-weight: 600; }

.panel input[type="text"],
.panel input[type="datetime-local"],
.panel textarea,
.panel select {
    width: 100%;
    padding: 0.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: inherit;
    font-weight: 400;
}

.media-table input, .media-table select { width: 100%; }

fieldset.platform {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin: 0 0 0.9rem;
}

fieldset.platform legend { font-weight: 700; padding: 0 0.4rem; }
fieldset.platform label { font-weight: 400; }

.preview-column { position: sticky; top: 1rem; }
.preview-list { display: flex; flex-direction: column; gap: 0.75rem; }

.preview-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.75rem;
}

.preview-card.disabled { opacity: 0.55; }

.pv-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.pv-count { margin-left: auto; font-size: 0.8rem; color: var(--muted); }
.pv-count.over { color: var(--err); font-weight: 700; }

.pv-text {
    white-space: pre-wrap;
    font-size: 0.9rem;
    background: #f8f9fb;
    border-radius: 6px;
    padding: 0.5rem;
    min-height: 2rem;
}

.pv-media { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }

.pv-media img, .pv-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--line);
}

.pv-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: var(--muted);
    text-align: center;
}

.alert.warn { background: #fef9c3; color: var(--warn); white-space: pre-wrap; }

.actions.sticky {
    position: sticky;
    bottom: 0;
    background: linear-gradient(transparent, var(--bg) 40%);
    padding: 0.75rem 0;
}

button.link { background: none; color: var(--err); padding: 0; font-size: 1rem; }

@media (max-width: 900px) {
    .editor-grid { grid-template-columns: 1fr; }
    .preview-column { position: static; }
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.9rem;
    text-align: center;
}

.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--muted); }

.metrics-cell { white-space: nowrap; }

.connect-form { display: flex; gap: 0.4rem; align-items: center; }
.connect-form input { padding: 0.35rem; border: 1px solid var(--line); border-radius: 6px; }

.upload-form input[type="text"] {
    width: 100%;
    padding: 0.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-weight: 400;
}

.upload-form input[type="file"] { margin-top: 0.2rem; }

/* Drafts are intentionally loud: they are never published until explicitly scheduled. */
.st-draft {
    background: #7c3aed;
    color: #fff;
    letter-spacing: 0.04em;
    box-shadow: 0 0 0 2px #ddd6fe;
}

tr.row-draft { background: #faf5ff; }
tr.row-draft td { border-bottom-color: #e9d5ff; }

.alert.draft {
    background: #f3e8ff;
    color: #6b21a8;
    border-left: 4px solid #7c3aed;
}

.draft-link {
    margin-left: 0.6rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #7c3aed;
    text-decoration: none;
}

.draft-link:hover { text-decoration: underline; }

.schedule-form {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.schedule-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    font-weight: 600;
    font-size: 0.85rem;
}

.schedule-form input[type="datetime-local"] {
    padding: 0.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: inherit;
}

/* Platform settings page */
.platform-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    align-items: start;
}

.platform-grid .panel h3 {
    margin: 0 0 0.75rem;
}

.platform-grid label.check {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 400;
}

.panel input[type="password"],
.panel input[type="number"] {
    width: 100%;
    padding: 0.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: inherit;
    font-weight: 400;
}
