/* ============================================================
   CG Content — Google Docs inspired look.
   Gray canvas, white sheet with a shadow, outline sidebar, pill toolbar.
   ============================================================ */
:root {
  --canvas: #f9fbfd;
  --surface: #ffffff;
  --fg: #1f1f1f;
  --fg2: #444746;
  --muted: #5f6368;
  --faint: #9aa0a6;
  --line: #dadce0;
  --line-strong: #c4c7c5;
  --hover: #f1f3f4;
  --active: #e3e3e3;
  --toolbar: #edf0f3;
  --primary: #1f1f1f;
  --primary-fg: #ffffff;
  --danger: #b3261e;
  --ok: #1e8e3e;
  --ok-bg: #e6f4ea;
  --open: #3b6fb6;
  --open-bg: #e8f0fe;
  --shadow: 0 1px 3px 1px rgba(60, 64, 67, .15), 0 1px 2px 0 rgba(60, 64, 67, .3);
  --shadow-sheet: 0 1px 3px 1px rgba(60, 64, 67, .15);
  --r: 8px;
  --font: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --doc-font: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --canvas: #131314;
  --surface: #1e1f20;
  --fg: #e3e3e3;
  --fg2: #c4c7c5;
  --muted: #9aa0a6;
  --faint: #5f6368;
  --line: #3c4043;
  --line-strong: #5f6368;
  --hover: #2a2b2d;
  --active: #37393b;
  --toolbar: #28292b;
  --primary: #e3e3e3;
  --primary-fg: #131314;
  --danger: #f2b8b5;
  --ok: #6dd58c;
  --ok-bg: #1b3a26;
  --open: #8ab4f8;
  --open-bg: #1f2c44;
  --shadow: 0 1px 3px 1px rgba(0, 0, 0, .5);
  --shadow-sheet: 0 0 0 1px var(--line);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--canvas);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; background: transparent; }
input, select, textarea {
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 8px 12px;
  width: 100%;
  outline: none;
  background: var(--surface);
}
input:focus, select:focus, textarea:focus { border-color: var(--fg); box-shadow: 0 0 0 1px var(--fg); }
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row > .auto { flex: 0 0 auto; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; }
.hidden, [hidden] { display: none !important; }

/* ---------- buttons (Docs: rounded pills) ---------- */
.btn {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  background: var(--surface);
  color: var(--fg);
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s, box-shadow .12s;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.primary:hover { box-shadow: var(--shadow); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.btn.block { width: 100%; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border-radius: 12px; padding: 36px 32px;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 18px; color: var(--fg); }
.brand .mark { width: 18px; height: 22px; background: var(--fg); display: inline-block; border-radius: 3px; position: relative; }
.brand .mark::after { content: ""; position: absolute; left: 4px; right: 4px; top: 9px; height: 2px; background: var(--surface); box-shadow: 0 4px 0 var(--surface), 0 8px 0 var(--surface); }
.login .brand { margin-bottom: 28px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 1em; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { text-decoration: none; font-size: 17px; }
.topbar nav { display: flex; gap: 4px; margin-left: 12px; flex: 1; overflow-x: auto; }
.topbar nav a {
  text-decoration: none; padding: 7px 14px; color: var(--muted); border-radius: 999px; white-space: nowrap; font-weight: 500;
}
.topbar nav a:hover { background: var(--hover); color: var(--fg); }
.topbar nav a.active { background: var(--active); color: var(--fg); }
.topbar .who { color: var(--muted); font-size: 13px; white-space: nowrap; }
.tb-spacer { flex: 1; }
.icon-btn.on { background: var(--active); }
a.icon-btn { text-decoration: none; }
.role-pill { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; margin-left: 6px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%;
  border: 0; cursor: pointer; background: transparent; color: var(--fg);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 18px; height: 18px; }
.content { flex: 1; display: flex; flex-direction: column; }

/* ---------- generic admin pages: sheets on the canvas ---------- */
.page { padding: 28px 24px 80px; max-width: 1040px; width: 100%; margin: 0 auto; }
.page h1 { font-size: 22px; font-weight: 500; margin: 0 0 4px; }
.page .lead { color: var(--muted); margin: 0 0 22px; }
.card, .preview, table { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-sheet); }
.card { padding: 20px 22px; margin-bottom: 18px; }
.card h3 { margin: 0 0 14px; font-size: 13px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }
table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
table.flat { box-shadow: none; border-radius: 0; }
table.flat th { padding-left: 0; } table.flat td { padding-left: 0; }
td input { padding: 6px 10px; }
tr.archived td { opacity: .5; }
.actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle:last-child { border-bottom: 0; }
.toggle .d { color: var(--muted); font-size: 12px; margin-top: 2px; }
.switch { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--line-strong); cursor: pointer; flex: 0 0 auto; transition: background .12s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: left .12s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch.on { background: var(--fg); }
.switch.on::after { left: 21px; }
.help { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-sheet); padding: 14px 16px; font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.help code { font-family: ui-monospace, Menlo, monospace; color: var(--fg); background: var(--hover); padding: 1px 6px; border-radius: 4px; }
.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.import-grid textarea { min-height: 420px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.preview { min-height: 420px; overflow: hidden; }
.preview .p-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 500; display: flex; justify-content: space-between; background: var(--hover); }
.preview .p-head .badge { font-size: 12px; color: var(--muted); font-weight: 400; }
.preview .p-item { padding: 8px 16px; border-bottom: 1px solid var(--line); }
.preview .p-item .s { color: var(--muted); font-size: 12px; white-space: pre-wrap; margin-top: 2px; }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }
.empty strong { display: block; color: var(--fg); margin-bottom: 6px; font-weight: 500; }

/* ---------- board = outline sidebar + document ---------- */
.board { display: grid; grid-template-columns: 420px 1fr; align-items: start; position: relative; }
.list-pane {
  position: sticky; top: 56px; height: calc(100vh - 56px);
  display: flex; flex-direction: column;
  background: var(--canvas);
  border-right: 1px solid var(--line);
}
.stats { display: flex; gap: 4px; padding: 10px 12px 4px; }
.stat {
  cursor: pointer; border: 0; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; background: transparent; color: var(--muted); font-size: 12px; transition: background .12s;
}
.stat:hover { background: var(--hover); }
.stat.active { background: var(--surface); box-shadow: var(--shadow-sheet); color: var(--fg); }
.stat .n { font-size: 13px; font-weight: 600; }
.stat .l { font-weight: 500; }
.stat.s-open .n { color: var(--open); }
.stat.s-done .n { color: var(--ok); }
.c-open { color: var(--open); font-weight: 500; }
.c-done { color: var(--ok); font-weight: 500; }
.status-open { color: var(--open); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; padding: 2px 14px 6px; }
.chip { border: 0; border-radius: 999px; padding: 2px 9px; font-size: 11px; cursor: pointer; color: var(--muted); background: transparent; }
.chip:hover { background: var(--hover); color: var(--fg); }
.chip.on { background: var(--active); color: var(--fg); }
.list-scroll { overflow-y: auto; flex: 1; padding: 4px 0 60px; }
.group-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px 4px 18px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500;
}
.group-head.clickable { cursor: pointer; user-select: none; }
.group-head.clickable:hover .gname { color: var(--fg); }
.group-head .gmeta { display: flex; gap: 8px; align-items: center; }
.group-head .cnt { color: var(--faint); font-weight: 400; }
.group-head .haslink { color: var(--muted); display: inline-grid; }
.group-head .haslink svg { width: 12px; height: 12px; }
.group-head .pm { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: var(--fg); font-size: 14px; line-height: 1; }
.group-head.clickable:hover .pm { background: var(--hover); }
.item {
  display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 7px 12px 7px 18px; margin: 0 10px 0 0; cursor: pointer;
  border-radius: 0 999px 999px 0; border-left: 3px solid transparent; color: var(--fg2);
}
.item:hover { background: var(--hover); color: var(--fg); }
.item.selected { background: var(--active); color: var(--fg); border-left-color: var(--fg); }
.item.selected .t { font-weight: 500; }
.item .box { width: 16px; height: 16px; border: 1.5px solid var(--open); border-radius: 4px; display: grid; place-items: center; background: var(--open-bg); color: transparent; }
.item.done .box { border-color: var(--ok); background: var(--ok); color: var(--canvas); }
.item .box svg { width: 12px; height: 12px; }
.item .t { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.done .t { color: var(--muted); }
.item .tag { font-size: 9.5px; padding: 1px 7px; color: var(--muted); border-color: var(--line); background: transparent; }
.item.selected .tag { color: var(--fg); }
/* edge arrow that opens / closes the list */
.pane-toggle {
  position: fixed; top: 50%; left: 420px; transform: translate(-50%, -50%); z-index: 7;
  width: 26px; height: 56px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted); cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow-sheet); transition: left .15s, background .12s;
}
.pane-toggle svg { width: 16px; height: 16px; transition: transform .15s; }
.pane-toggle:hover { color: var(--fg); background: var(--hover); }
.board.list-hidden { grid-template-columns: 1fr; }
.board.list-hidden .list-pane { display: none; }
.board.list-hidden .pane-toggle { left: 0; transform: translate(0, -50%); border-radius: 0 999px 999px 0; border-left: 0; }
.board.list-hidden .pane-toggle svg { transform: rotate(180deg); }

/* add videos */
.add-btn {
  display: flex; align-items: center; gap: 10px; margin: 0 12px 14px; padding: 12px 16px;
  border: 1px dashed var(--line-strong); border-radius: 12px; background: transparent; color: var(--muted);
  cursor: pointer; font-weight: 500; font-size: 14px;
}
.add-btn svg { width: 18px; height: 18px; }
.add-btn:hover { background: var(--surface); color: var(--fg); border-style: solid; box-shadow: var(--shadow-sheet); }
.composer { margin: 0 12px 14px; padding: 12px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer select, .composer input, .composer textarea { font-size: 13px; padding: 7px 10px; }
.composer select { flex: 1; }
.composer .c-type { flex: 0 0 120px; }
.composer textarea { min-height: 0; resize: none; line-height: 1.5; }
.list-scroll { padding-bottom: 8px; }

/* tags */
.tag { display: inline-block; border: 1px solid var(--line-strong); border-radius: 999px; padding: 1px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; line-height: 1.6; color: var(--fg2); white-space: nowrap; background: var(--surface); }
.tag.lg { font-size: 11px; padding: 2px 10px; }
.type-select { width: auto; padding: 2px 22px 2px 10px; border-radius: 999px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; cursor: pointer; appearance: none; -webkit-appearance: none; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa0a6' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 6px center / 12px; }
.type-select.unset { color: var(--faint); border-style: dashed; }

/* ---------- document pane ---------- */
.detail-pane { min-width: 0; }
.detail-empty { min-height: calc(100vh - 56px); display: grid; place-items: center; color: var(--muted); }
.empty-doc svg { width: 56px; height: 56px; color: var(--faint); margin-bottom: 8px; }
.detail { padding: 10px 24px 80px; }
.doc-col { max-width: 816px; margin: 0 auto; }
.back-btn { display: none; }

.dochead { display: flex; align-items: center; gap: 14px; padding: 14px 0 14px; flex-wrap: wrap; }
.docicon { width: 40px; height: 40px; color: var(--fg); flex: 0 0 auto; }
.docicon svg { width: 100%; height: 100%; }
.dochead-main { min-width: 0; flex: 1 1 260px; }
.doctitle { font-size: 20px; font-weight: 400; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docmeta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 3px; flex-wrap: wrap; }
.docmeta .dot { color: var(--faint); }
.status-done { color: var(--ok); }
.dochead-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.dochead-actions .btn { display: inline-flex; align-items: center; gap: 8px; }
.dochead-actions .btn svg { width: 16px; height: 16px; }
.done-chip { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-weight: 500; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.done-chip svg { width: 16px; height: 16px; }

/* overflow menu */
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary svg { width: 18px; height: 18px; }
details.menu[open] > summary { background: var(--active); }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 8; min-width: 210px;
  background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
}
.menu-list button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; border-radius: 6px; padding: 9px 12px; cursor: pointer; background: transparent; color: var(--fg); font-size: 13.5px;
}
.menu-list button:hover { background: var(--hover); }
.menu-list button svg { width: 16px; height: 16px; color: var(--muted); }
.menu-list button.danger, .menu-list button.danger svg { color: var(--danger); }

/* one-line link field */
.linkline { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; }
.ll-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--hover); color: var(--muted); flex: 0 0 auto; }
.ll-icon.has { background: var(--ok-bg); color: var(--ok); }
.ll-icon svg { width: 14px; height: 14px; }
.linkline input { flex: 1; border-radius: 999px; padding: 7px 14px; font-size: 13px; }
.ll-open { color: var(--muted); text-decoration: none; padding: 4px 6px; font-size: 15px; }
.ll-open:hover { color: var(--fg); }

/* project link in the sidebar */
.glink { display: inline-flex; align-items: center; gap: 4px; border: 0; background: transparent; color: var(--faint); font-size: 10px; text-transform: none; letter-spacing: 0; cursor: pointer; padding: 2px 6px; border-radius: 999px; }
.glink svg { width: 11px; height: 11px; }
.glink:hover { background: var(--hover); color: var(--fg); }
.glink.has { color: var(--ok); }
.glink-edit { display: flex; gap: 6px; align-items: center; padding: 2px 12px 8px 18px; }
.glink-edit input { flex: 1; font-size: 12px; padding: 5px 10px; border-radius: 999px; }

/* the sheet */
.canvas { display: block; padding: 0; }
.sheet {
  position: relative;
  background: var(--surface);
  width: 816px; max-width: 100%;
  min-height: 1056px;
  padding: 96px 96px 120px;
  box-shadow: var(--shadow-sheet);
  border-radius: 2px;
  font-family: var(--doc-font);
  color: var(--fg);
}
.sheet-copy {
  position: absolute; top: 14px; right: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer;
  background: var(--surface); color: var(--muted); font-family: var(--font); font-size: 12px; font-weight: 500;
}
.sheet-copy:hover { color: var(--fg); background: var(--hover); }
.sheet-copy.ok { color: var(--ok); border-color: var(--ok); }
.sheet-copy svg { width: 14px; height: 14px; }
.sheet-copy:disabled { opacity: .35; cursor: not-allowed; }
.sheet-title { font-family: var(--doc-font); font-size: 26px; font-weight: 400; margin: 0 0 24px; line-height: 1.25; }
.script { font-size: 14.7px; line-height: 1.7; white-space: pre-wrap; word-wrap: break-word; }
.script.empty-script { color: var(--faint); font-style: italic; }
.admin-tools, .toolbar, .hint { display: none; }

/* editing form on the doc pane */
.detail .field textarea { font-family: var(--doc-font); font-size: 14.7px; line-height: 1.7; background: var(--surface); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f1f1f; color: #fff; padding: 12px 20px; font-size: 14px; border-radius: 6px;
  z-index: 50; max-width: 90vw; box-shadow: var(--shadow);
}
:root[data-theme="dark"] .toast { background: #e3e3e3; color: #131314; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .board { grid-template-columns: 360px 1fr; } .pane-toggle { left: 360px; } }
@media (max-width: 900px) {
  .board { grid-template-columns: 1fr; }
  .list-pane { position: static; height: auto; border-right: 0; }
  .board.showing-detail .list-pane { display: none; }
  .board:not(.showing-detail) .detail-pane { display: none; }
  .board.list-hidden .list-pane { display: flex; }
  .board.list-hidden.showing-detail .list-pane { display: none; }
  .pane-toggle { display: none; }
  .back-btn { display: inline-flex; margin-bottom: 10px; }
  .detail { padding: 12px 12px 60px; }
  .dochead-actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .sheet { padding: 56px 24px 80px; min-height: 60vh; }
  .import-grid { grid-template-columns: 1fr; }
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .who { display: none; }
}
