/* Content editor controls. Workspace shell is shared with Analytics. */

:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --ink: #203039;
  --ink-muted: #78838b;
  --border: #e3e9ec;
  --accent: #078d85;
  --accent-tint: #e8f5f2;
  --ok: #2e7d32;
  --focus: #078d85;
  --radius: 6px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

h1, h2 { font-family: inherit; font-weight: 650; }

/* [hidden] must always win, no matter what specificity a later rule for
   the same element has -- see the sibling attribute-visibility check in
   controlled-chaos-pro for this exact bug class (an #id rule setting
   `display` beats a `.class[hidden]` rule, so the hidden element never
   actually hides). */
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- login --- */

.login-view:not([hidden]) {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 24px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-box h1 { margin: 0 0 4px; font-size: 21px; }

/* --- shared form controls --- */

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-muted);
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink);
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  font: inherit;
  font-size: 16px; /* 16px floor keeps iOS Safari from zooming on focus */
  padding: 10px 12px;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; min-height: 0; }

input:focus, select:focus, textarea:focus {
  border-color: var(--focus);
}

.body-field { display: flex; flex-direction: column; gap: 12px; font-size: 13px; color: var(--ink-muted); margin-top: 4px; }
.body-field-label { font-weight: 600; color: var(--ink); font-size: 14px; }
.body-field-heading { display:flex; align-items:flex-end; justify-content:space-between; gap:16px; }
.body-field-heading .hint { margin-top:3px; }

button {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 11px 18px;
  min-height: var(--tap);
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #971f18; }
.btn-block { width: 100%; }
.btn-plain { background: transparent; color: var(--ink-muted); border: 1px solid var(--border); min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn-video { display:inline-flex; align-items:center; gap:7px; flex:none; min-height:38px; padding:7px 12px; color:#057d75; background:#fff; border:1px solid #b9ddd6; }
.btn-video:hover { background:#eff8f6; border-color:#80c4ba; }
.btn-video span { display:grid; place-items:center; width:20px; height:20px; border-radius:5px; color:#fff; background:#e24b3d; font-size:9px; }
.btn-danger { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-danger:hover { background: var(--accent-tint); }

.error { color: var(--accent); font-size: 13px; margin: 0; }

/* file input disguised as a plain button -- native file inputs can't be
   styled directly, so the label IS the visible control and the input
   underneath is visually hidden but still keyboard- and tap-reachable. */
.file-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: var(--tap);
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.file-btn:hover { border-color: var(--ink-muted); }
.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* --- app shell --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 16px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-muted); }
.whoami { display: none; }
.workspace-switcher { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.workspace-btn { min-height: 34px; padding: 5px 9px; border-radius: 4px; background: transparent; color: var(--ink-muted); font-size: 12px; }
.workspace-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px #d8d2c6; }

.layout {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 57px);
  min-height: calc(100svh - 57px);
}

.sidebar {
  border-bottom: 1px solid var(--border);
  padding: 14px;
  background: var(--surface);
}

.draft-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.draft-list li {
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.draft-list li:hover { background: var(--bg); }
.draft-list li.active { background: var(--ink); color: #fff; }
.draft-list .draft-title { display: block; font-weight: 600; }
.draft-list .draft-meta { display: block; font-size: 11px; opacity: 0.7; margin-top: 2px; }

.editor-pane { flex: 1; min-width: 0; }

.empty-state { padding: 32px 16px; color: var(--ink-muted); text-align: center; }

/* padding-bottom reserves room for .editor-actions, which is sticky to
   the viewport bottom on mobile (see below) and would otherwise sit on
   top of -- and hide -- the last of the body editor's content. */
.editor { padding: 16px; padding-bottom: 92px; max-width: 780px; margin: 0 auto; }

.back-btn {
  display: block;
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 0;
  margin-bottom: 4px;
  cursor: pointer;
  min-height: var(--tap);
}

.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.editor-head h2 { font-size: 17px; margin: 0; word-break: break-word; }

.save-status { flex: 1; font-size: 13px; color: var(--ok); min-height: 18px; margin: 0; }
.save-status.pending { color: var(--ink-muted); }
.save-status.error { color: var(--accent); }

#editor-form { display: flex; flex-direction: column; gap: 16px; margin-top: 14px; }

.row { display: flex; flex-direction: column; gap: 12px; }
.row-tight { flex-direction: row; align-items: center; gap: 20px; }

.status-pill {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-muted);
  border: 1px solid var(--border);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
}
legend { font-size: 12px; font-weight: 600; color: var(--ink-muted); padding: 0 4px; }

.hint { font-size: 12px; color: var(--ink-muted); margin: 0; }

.image-preview img { max-width: 100%; max-height: 220px; border-radius: 4px; display: block; }
.image-preview:empty { display: none; }

/* Video controls stay outside Toast UI so an embedded iframe is never a
   dead end. Every video remains visible in the article canvas, while its
   source URL is editable here as an ordinary form field. */
.youtube-manager { border:1px solid #d7e8e4; border-radius:8px; background:#f8fbfa; overflow:hidden; }
.youtube-manager-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; padding:13px 15px; }
.youtube-manager-head h3 { margin:0; color:var(--ink); font-size:13px; letter-spacing:-.1px; }
.youtube-manager-head p { margin:2px 0 0; font-size:11px; }
.video-count { min-width:24px; padding:2px 7px; border-radius:999px; background:#e5f3f0; color:#08776f; font-size:10px; font-weight:700; text-align:center; }
.youtube-list { display:grid; gap:1px; background:#dfeae7; }
.youtube-empty { margin:0; padding:14px 15px; color:#6e7f86; background:#fff; font-size:12px; }
.youtube-item { display:grid; grid-template-columns:132px minmax(0,1fr); gap:14px; padding:14px 15px; background:#fff; }
.youtube-thumbnail { position:relative; align-self:start; display:block; aspect-ratio:16/9; overflow:hidden; border-radius:6px; background:#16201f; }
.youtube-thumbnail img { width:100%; height:100%; object-fit:cover; display:block; }
.youtube-thumbnail::after { content:'▶'; position:absolute; left:50%; top:50%; translate:-50% -50%; display:grid; place-items:center; width:32px; height:23px; padding-left:2px; border-radius:7px; background:#e3241b; color:#fff; font-size:10px; box-shadow:0 2px 8px rgb(0 0 0 / .24); }
.youtube-item-fields { min-width:0; display:flex; flex-direction:column; gap:7px; }
.youtube-item-title { display:flex; align-items:center; justify-content:space-between; gap:10px; color:var(--ink); font-size:11px; font-weight:700; }
.youtube-item-title a { color:#5c727a; font-weight:500; }
.youtube-input-row { display:flex; align-items:center; gap:7px; }
.youtube-input-row input { min-width:0; min-height:38px; padding:8px 10px; font-size:12px; }
.youtube-input-row button { min-height:38px; padding:7px 11px; white-space:nowrap; }
.youtube-remove { align-self:flex-start; min-height:28px; padding:2px 0; border:0; background:none; color:#a94d40; font-size:11px; font-weight:600; }
.youtube-remove:hover { text-decoration:underline; }
.youtube-add-form { padding:14px 15px; border-top:1px solid #dfeae7; background:#fff; }
.youtube-add-form label { margin-bottom:6px; color:var(--ink); font-weight:600; }
.youtube-add-form .hint { margin-top:6px; }
.field-error { margin:6px 0 0; color:#b34d39; font-size:11px; }

/* live YouTube preview inside the WYSIWYG body editor, matching the
   embed the real post renders -- see admin.js's widgetRules. */
.yt-widget {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 16 / 9;
  margin: 6px 0;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  isolation: isolate;
}
.yt-widget iframe { position: absolute; z-index:0; inset: 0; width: 100%; height: 100%; border: 0; }
.yt-widget-edit { position:absolute; z-index:2; right:10px; top:10px; min-height:34px; padding:6px 10px; border:1px solid rgb(255 255 255 / .55); border-radius:6px; background:rgb(24 38 37 / .9); color:#fff; font-size:11px; box-shadow:0 4px 14px rgb(0 0 0 / .22); }
.yt-widget-edit:hover { background:#087f77; }

.editor-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  margin: 20px -16px -92px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}
.editor-actions .btn-primary { flex: 1; }
.editor-actions .save-status:empty { display: none; }

/* --- mobile: one screen at a time (drafts list, or the open draft) --- */

#app-view.editor-active .sidebar { display: none; }
#app-view:not(.editor-active) .editor-pane { display: none; }

@media (min-width: 840px) {
  .topbar h1 { font-size: 18px; }
  .whoami { display: inline; }

  .layout { flex-direction: row; align-items: flex-start; }
  .sidebar {
    display: block !important;
    width: 280px;
    flex: none;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 20px;
    /* Independent scroll, capped to the viewport below the sticky topbar --
       otherwise a long draft list stretches the whole page (flex stretch
       makes .editor-pane match it too), forcing a scroll past a wall of
       titles to reach the editor's Save button. */
    position: sticky;
    top: 57px;
    max-height: calc(100vh - 57px);
    max-height: calc(100svh - 57px);
    overflow-y: auto;
  }
  .editor-pane { display: block !important; }
  .empty-state { padding-top: 64px; }
  .editor { padding: 28px 36px; }
  .back-btn { display: none; }

  .row-tight { gap: 24px; }
  .row { flex-direction: row; align-items: flex-end; }
  .row > label { flex: 1; }

  .editor-actions {
    margin: 24px 0 0;
    padding: 0;
    background: none;
    border-top: none;
    position: static;
  }
  .editor-actions .btn-primary { flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* Content uses the same panels, typography and spacing as Analytics. */
body { font-size:13px; line-height:1.5; }
.login-box { padding:30px; max-width:380px; border-radius:9px; gap:18px; }
.login-box h1 { font-size:18px; letter-spacing:-.3px; margin-top:10px; }
.topbar { position:static; }
.whoami { display:inline; font-size:11px; color:var(--ink-muted); }
.content-heading { max-width:1640px; margin:0 auto; padding:25px 30px 19px; }
.content-heading h1 { font-size:25px; letter-spacing:-.8px; margin:0 0 4px; }
.content-heading p { margin:0; color:var(--ink-muted); font-size:12px; }
.layout { min-height:0; gap:18px; margin:0 auto; padding:0 30px 35px; max-width:1640px; }
.sidebar { border:1px solid var(--border); border-radius:9px; padding:16px 12px; }
.library-heading { display:flex; align-items:center; justify-content:space-between; padding:0 4px 14px; }
.library-heading h2 { margin:0; font-size:14px; }
.library-heading .status-pill { font-size:10px; border:0; background:#f1f4f6; padding:3px 7px; border-radius:4px; }
.draft-list { gap:4px; margin-top:12px; }
.draft-list li { border:1px solid transparent; font-size:12px; padding:11px 10px; }
.draft-list li.active { color:#057d75; background:#e8f5f2; border-color:#d2e9e3; }
.draft-list li:focus-visible { outline:2px solid var(--focus); outline-offset:1px; }
.draft-list .draft-title { line-height:1.5; }
.draft-list .draft-meta { opacity:1; color:#78838b; font-size:10px; overflow-wrap:anywhere; }
.editor-pane { border:1px solid var(--border); background:#fff; border-radius:9px; overflow:hidden; }
.empty-state { min-height:430px; display:flex; flex-direction:column; justify-content:center; align-items:center; padding:45px 20px; }
.empty-state h2 { font-size:18px; letter-spacing:-.3px; color:var(--ink); margin:18px 0 6px; }
.empty-state p { margin:0; font-size:12px; line-height:1.8; }
.empty-mark { display:grid; place-items:center; font-size:29px; width:60px; height:60px; border:1px solid #dcebe7; border-radius:15px; background:#eff7f5; color:#078d85; }
.editor { max-width:1000px; padding:24px; }
.editor-head { border-bottom:1px solid var(--border); padding-bottom:15px; }
.editor-head h2 { font-size:17px; letter-spacing:-.3px; }
.status-pill { border-radius:4px; background:#eaf6ef; color:#338364; border-color:#dceee3; text-transform:none; letter-spacing:0; }
#editor-form { gap:18px; margin-top:16px; }
label { color:#52626b; font-size:12px; gap:6px; }
textarea { font-family:inherit; }
input[type="text"],input[type="password"],input[type="number"],select,textarea { background:#fff; border-radius:6px; }
input:focus,select:focus,textarea:focus { outline:2px solid #d1ede7; outline-offset:0; }
button { font-size:12px; padding:8px 12px; font-weight:600; }
.btn-primary:hover { background:#067970; }
.btn-danger { color:#b34d39; border-color:#e6c8c1; }
.btn-danger:hover { background:#fff2ee; }
.error,.save-status.error { color:#b34d39; }
fieldset { padding:17px; background:#fafcfc; border-radius:7px; }
legend { color:#52626b; font-size:12px; }
.body-field { margin-top:24px; }
.body-field-label { font-size:14px; }
.hint { font-size:11px; line-height:1.7; }
.toastui-editor-defaultUI { border-color:var(--border); border-radius:7px; overflow:hidden; }
.toastui-editor-defaultUI-toolbar { background:#f8fafb; border-color:var(--border); }
.editor-actions { z-index:4; margin:24px -24px -24px; padding:16px 24px; border-top:1px solid var(--border); background:#fff; position:sticky; bottom:0; }
.editor-actions .btn-primary { flex:none; min-width:100px; }
.editor-actions .save-status { min-width:140px; }
@media(min-width:840px) {
  .layout { align-items:flex-start; }
  .sidebar { width:240px; top:20px; max-height:calc(100svh - 40px); }
  .editor-pane { min-height:500px; }
  input[type="text"],input[type="password"],input[type="number"],select,textarea { font-size:13px; min-height:40px; padding:9px 11px; }
}
@media(min-width:840px) and (max-width:1100px) {
  .layout { padding:0 20px 25px; gap:12px; }
  .content-heading { padding-left:20px; padding-right:20px; }
  .sidebar { width:210px; }
  .editor { padding:18px; }
  .row:not(.row-tight) { flex-direction:column; align-items:stretch; }
  .editor-actions { margin-left:-18px; margin-right:-18px; margin-bottom:-18px; padding:14px 18px; }
}
@media(max-width:839px) {
  .layout { padding:0 20px 24px; }
  .content-heading { padding:22px 20px 17px; }
  .sidebar { padding:16px; }
  .editor { padding:18px; }
  .editor-actions { margin:24px -18px -18px; padding:14px 18px; }
  .editor-actions .btn-primary { flex:1; }
  textarea { font-size:16px; }
}
@media(max-width:760px) {
  .layout { padding:0 16px 24px; }
  .content-heading { padding:20px 16px 16px; }
  .content-heading h1 { font-size:23px; }
  .row-tight { flex-wrap:wrap; gap:14px; }
  .row-tight > label { min-width:0; }
  .toastui-editor-toolbar-icons { min-height:0; }
  .body-field-heading { align-items:flex-start; flex-direction:column; gap:10px; }
  .youtube-item { grid-template-columns:1fr; }
  .youtube-thumbnail { max-width:240px; }
  .youtube-input-row { align-items:stretch; flex-wrap:wrap; }
  .youtube-input-row input { flex-basis:100%; font-size:16px; }
}
