:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6a6f76;
  --line: #e3e3df;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --error: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- Login page ---------- */

.login {
  max-width: 360px;
  margin: 15vh auto 0;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 20px; color: var(--muted); }
.login input {
  width: 100%;
  padding: 10px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 12px;
}
.login button { width: 100%; }
.login .error { color: var(--error); margin-bottom: 12px; }

/* ---------- App layout ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand { font-weight: 700; padding: 0 10px 16px; }

.sidebar a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: var(--accent); color: var(--accent-text); }

.sidebar-bottom { margin-top: auto; }
.sidebar form button {
  width: 100%;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 8px 10px;
}

main { flex: 1; padding: 32px 40px; min-width: 0; }
main h1 { margin-top: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); }

a.button {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  border-radius: 6px;
  padding: 10px 16px;
}
button.link {
  background: none;
  color: var(--accent);
  padding: 4px 0;
  text-decoration: underline;
}
button.small { padding: 6px 10px; font-size: 13px; }

/* Phones: sidebar becomes a top bar */
@media (max-width: 700px) {
  .layout { flex-direction: column; }
  .sidebar { position: static; height: auto; width: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand { width: 100%; }
  .sidebar-bottom { margin-top: 0; display: flex; }
  main { padding: 24px 16px; }
}

/* ---------- Content Board ---------- */

.board-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.board-header h1 { margin: 0; margin-right: auto; }

.filters { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.filters .filter {
  border-radius: 0;
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
}
.filters .filter.on { background: var(--accent); color: var(--accent-text); }

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(200px, 1fr));
  gap: 16px;
  align-items: start;
}

.column {
  background: #ecece8;
  border-radius: 10px;
  padding: 12px;
  min-height: 120px;
}
.column h2 { font-size: 15px; margin: 4px 4px 12px; }
.column .count { color: var(--muted); font-weight: 400; margin-left: 4px; }
.column .empty { color: var(--muted); font-size: 14px; margin: 4px; }

.card {
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.card:hover { border-color: var(--accent); }
.card .snippet {
  color: var(--muted);
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
  overflow: hidden;
}
.card .when { font-size: 13px; color: var(--accent); }

.badge {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge.li { background: #dce8f5; color: #1d4f80; }
.badge.x { background: #e6e6e6; color: #222; }

/* ---------- Post editor ---------- */

dialog {
  width: min(680px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin-top: 0; }
dialog label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
dialog input, dialog select, dialog textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px;
  font: inherit;
  font-weight: 400;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
dialog textarea { resize: vertical; }
dialog .row { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 12px; }
dialog .counter { font-size: 13px; color: var(--muted); margin: -8px 0 12px; text-align: right; }
dialog .counter.over { color: var(--error); font-weight: 600; }
dialog .error { color: var(--error); }
dialog .actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
dialog .actions a { margin-right: auto; color: var(--accent); }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: 0.6; cursor: default; }

@media (max-width: 1000px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .board { grid-template-columns: 1fr; }
  dialog .row { grid-template-columns: 1fr; }
}

/* ---------- Editor ---------- */

.editor-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.editor-top .back { color: var(--muted); text-decoration: none; margin-right: 4px; }
.editor-top input, .editor-top select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
.editor-top .title-input { flex: 1; min-width: 220px; font-weight: 600; }

.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 20px;
  align-items: start;
}

.writing {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.toolbar button {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 5px 9px;
  font-size: 14px;
}
.toolbar button:hover { border-color: var(--line); background: var(--bg); }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.toolbar .label { font-size: 13px; color: var(--muted); margin-left: 2px; }

.writing textarea {
  flex: 1;
  border: 0;
  resize: none;
  padding: 18px 20px;
  font: 16px/1.6 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: transparent;
  outline: none;
  min-height: 55vh;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.stats-bar .over { color: var(--error); font-weight: 600; }

.side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none;
  color: var(--muted);
  border-radius: 0;
  padding: 8px 10px;
  border-bottom: 2px solid transparent;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

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

/* Preview */
.preview-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.preview-controls .filter { padding: 6px 10px; font-size: 13px; }
.preview-frame { border-radius: 10px; padding: 14px; background: #f4f2ee; margin: 0 auto; }
.preview-frame.phone { max-width: 360px; }
.preview-frame.desktop { max-width: 560px; }
.preview-frame.dark { background: #000; }
.post-card { background: #fff; color: #1d1d1d; border-radius: 8px; padding: 14px; font-size: 14px; }
.preview-frame.dark .post-card { background: #1b1f23; color: #e8e8e8; }
.post-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; line-height: 1.3; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}
.faint { color: #777; font-size: 12px; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.see-more { background: none; color: #777; padding: 0 0 0 4px; font-size: 14px; }

/* Hooks and endings */
.lib-controls { display: flex; gap: 8px; margin-bottom: 8px; }
.lib-controls input, .lib-controls select {
  font: inherit; font-size: 14px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text);
}
.lib-controls input { flex: 1; min-width: 0; }
.lib-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.lib-template, .lib-example {
  display: block; width: 100%; text-align: left;
  background: none; color: var(--text); padding: 4px 6px; border-radius: 6px;
}
.lib-template { font-weight: 600; }
.lib-template:hover, .lib-example:hover { background: var(--bg); }
.lib-example { font-size: 14px; color: var(--muted); border-left: 2px solid var(--line); margin: 6px 0 0 4px; }
.lib-tags { margin: 4px 6px; }
.tag { display: inline-block; font-size: 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-right: 4px; color: var(--muted); }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); margin: 4px 6px; }

/* Snippets */
#snip-save { width: 100%; }
.snip { display: flex; gap: 6px; align-items: stretch; margin-bottom: 8px; }
.snip-use {
  flex: 1; text-align: left; background: none; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.snip-use span { font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.snip-use:hover { border-color: var(--accent); }

/* Import */
.import-box { width: 100%; min-height: 300px; font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }

@media (max-width: 1000px) {
  .editor-body { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
}

/* ---------- Writer ---------- */

.writer { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.writer-form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.writer-form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.writer-form textarea, .writer-form select {
  display: block; width: 100%; margin-top: 6px; padding: 9px; font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); resize: vertical;
}
.checks-row { display: flex; gap: 18px; margin-bottom: 14px; }
.writer-form label.check { display: flex; gap: 6px; align-items: center; margin: 0; font-weight: 400; }
.writer-form #w-go { width: 100%; }
.draft-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.draft-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 13px; }
.draft-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; margin-bottom: 14px; }
.alt-hooks { border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 14px; font-size: 14px; }
.alt { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; }
.alt span { white-space: pre-wrap; }
.alt button { flex-shrink: 0; }
.notes ul { margin: 6px 0 12px; padding-left: 20px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 1000px) { .writer { grid-template-columns: 1fr; } }
