:root {
  --bg: #faf8f5; --panel: #ffffff; --ink: #2a2622; --muted: #756e66; --line: #e6e0d8;
  --accent: #7a4fd0; --accent-ink: #ffffff;
  --draft: #8a847b; --scheduled: #2f6fdb; --queued: #c47a12; --posted: #2a8a4a; --failed: #c4362f; --cancelled: #9a948b;
  --radius: 10px; --shadow: 0 8px 30px rgba(40, 30, 20, .18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171513; --panel: #211e1b; --ink: #f0ebe4; --muted: #a39b91; --line: #37332e;
    --accent: #a785ee; --accent-ink: #171513;
    --draft: #a39b91; --scheduled: #6ea0ff; --queued: #e8a53c; --posted: #56c179; --failed: #ef6b64; --cancelled: #7d766d;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login { max-width: 360px; margin: 14vh auto; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 18px; color: var(--muted); }
.login input { width: 100%; }
.err { color: var(--failed); margin: 8px 0 0; min-height: 1.2em; }

.topbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 17px; margin: 0 8px 0 0; }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.warn { border-color: var(--failed); color: var(--failed); }
.pill.ok::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--posted); margin-right: 6px; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 8px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--failed); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 3px 9px; font-size: 13px; }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; background: #fdeceb; color: #8e1f19; border: 1px solid #f3b9b5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3a1c1a; color: #ffb3ae; border-color: #6b2c28; } }

main { padding: 16px 20px 40px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; background: currentColor; }

.chip { display: block; width: 100%; text-align: left; border: 1px solid var(--line); border-left: 4px solid var(--draft); background: var(--panel); border-radius: 6px; padding: 2px 6px; margin: 2px 0; font-size: 12.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip .t { color: var(--muted); margin-right: 5px; }
.st-draft { border-left-color: var(--draft); border-style: dashed; border-left-style: solid; }
.st-scheduled { border-left-color: var(--scheduled); }
.st-queued { border-left-color: var(--queued); }
.st-posted { border-left-color: var(--posted); opacity: .85; }
.st-failed { border-left-color: var(--failed); background: color-mix(in srgb, var(--failed) 10%, var(--panel)); }
.st-cancelled { border-left-color: var(--cancelled); text-decoration: line-through; opacity: .6; }
.st-projected { border-left-color: var(--scheduled); border-style: dashed; opacity: .6; }
.ext { font-style: italic; }
.lg-draft { color: var(--draft); } .lg-scheduled { color: var(--scheduled); } .lg-queued { color: var(--queued); }
.lg-posted { color: var(--posted); } .lg-failed { color: var(--failed); } .lg-projected { color: var(--scheduled); opacity: .6; }

.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.month .dow { padding: 6px 8px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--bg); }
.cell { min-height: 108px; padding: 4px 5px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; }
.cell:nth-child(7n+7) { border-right: 0; }
.cell.other { background: color-mix(in srgb, var(--bg) 70%, var(--panel)); color: var(--muted); }
.cell.today .num { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 7px; }
.cell.dragover { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell .num { font-size: 12.5px; display: inline-block; margin-bottom: 2px; }
.more { font-size: 12px; color: var(--muted); padding: 0 4px; }

.week { display: grid; grid-template-columns: 56px repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.week .head { padding: 8px; font-size: 13px; border-bottom: 1px solid var(--line); background: var(--bg); text-align: center; }
.week .head.today { color: var(--accent); font-weight: 600; }
.weekscroll { max-height: 66vh; overflow-y: auto; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.weekbody { display: grid; grid-template-columns: 56px repeat(7, minmax(0, 1fr)); background: var(--panel); position: relative; }
.hour { height: 46px; border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted); padding: 2px 6px; text-align: right; }
.col { position: relative; border-left: 1px solid var(--line); }
.slot { height: 46px; border-bottom: 1px solid var(--line); cursor: pointer; }
.slot:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.col .chip { position: absolute; height: 40px; margin: 2px 0; white-space: normal; line-height: 1.2; }

.list h3 { margin: 18px 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.row { display: grid; grid-template-columns: 78px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--draft); border-radius: 8px; padding: 9px 12px; margin: 5px 0; }
.row:hover { border-color: var(--accent); }
.row .sub { color: var(--muted); font-size: 13px; }
.row .badge { font-size: 12px; padding: 2px 9px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.overlay { position: fixed; inset: 0; background: rgba(20, 15, 10, .5); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 14px; overflow-y: auto; z-index: 20; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(720px, 100%); }
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 17px; flex: 1; }
.modal .body { padding: 16px 20px; display: grid; gap: 14px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field label.l { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.field input[type=text], .field textarea, .field select { width: 100%; }
textarea { min-height: 150px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.preview { border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow-y: auto; }
.preview .mention { color: var(--accent); font-weight: 600; }
.warn { color: var(--queued); font-size: 13px; margin-top: 4px; }
.thumb { max-width: 180px; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); display: block; margin-bottom: 6px; }
.wd { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: transparent; }
.wd.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.notice { padding: 9px 12px; border-radius: 8px; background: color-mix(in srgb, var(--queued) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--queued) 40%, var(--line)); font-size: 13.5px; }
.notice.bad { background: color-mix(in srgb, var(--failed) 12%, var(--panel)); border-color: color-mix(in srgb, var(--failed) 40%, var(--line)); }
.confirm { padding: 12px 14px; border-radius: 10px; border: 2px solid var(--accent); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 40; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: var(--shadow); }
.toast.bad { background: var(--failed); color: #fff; }

@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; }
  .cell { min-height: 78px; }
  .row { grid-template-columns: 62px 1fr; }
  .row .badge { grid-column: 2; justify-self: start; }
  main { padding: 12px 10px 40px; }
}

.editor { min-height: 170px; padding: 10px 12px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; white-space: pre-wrap; word-break: break-word; outline: none; }
.editor:focus { border-color: var(--accent); }
.editor:empty::before { content: attr(data-ph); color: var(--muted); }
.editor a { color: var(--accent); text-decoration: underline; }
.editor .mention { color: var(--accent); font-weight: 600; }

.tray { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 2px; }
.tile { position: relative; flex: 0 0 120px; height: 120px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; }
.tile-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.file { padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.tile .ftype { align-self: flex-start; background: var(--failed); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 6px; }
.tile .fname { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-all; }
.tile .fsize { font-size: 11.5px; color: var(--muted); }
.tile-x { position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; line-height: 1; font-size: 16px; }
.tile.add { border-style: dashed; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.tile.add:hover { border-color: var(--accent); color: var(--accent); }
.tray-wrap .notice { margin-top: 6px; }

.ed-wrap { position: relative; }
.mention-pop { position: absolute; z-index: 30; width: 260px; max-height: 300px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.mention-pop.hidden { display: none; }
.mention-item { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; cursor: pointer; font-size: 14px; }
.mention-item.on, .mention-item:hover { background: var(--accent-bg, rgba(99,102,241,.14)); }
.mention-item .slug { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-foot { padding: 5px 10px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); }
