:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1c1a;
  --muted: #6d6a64;
  --line: #e4e1da;
  --accent: #1f4d3a;
  --accent-soft: #e3ede8;
  --danger: #b3261e;
  --today: #fff7df;
  --radius: 10px;
  --st-doing: #d97706;
  --st-review: #7c3aed;
  --st-scheduled: #2563eb;
  --st-posted: #16a34a;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45;
}
a { color: inherit; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.logo { font-weight: 600; text-decoration: none; font-size: 16px; letter-spacing: .02em; }
.logo span { color: var(--muted); font-weight: 500; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.me { color: var(--muted); font-size: 13px; }

main { padding: 16px 20px 60px; max-width: 1400px; margin: 0 auto; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c9c5bc; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: #efc9c6; }
.btn.ghost { background: transparent; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- brand tabs ---------- */
.brand-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.brand-tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); text-decoration: none; white-space: nowrap;
}
.brand-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.month-nav { display: flex; align-items: center; gap: 6px; margin-right: auto; }
.month-title { font-size: 20px; font-weight: 600; min-width: 170px; }
.toolbar select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }

/* ---------- calendar ---------- */
.cal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head div { padding: 8px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); text-align: center; }
.cell {
  min-height: 118px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 4px; cursor: pointer; position: relative; min-width: 0;
}
.cell:nth-child(7n) { border-right: none; }
.cell.other { background: #faf9f7; }
.cell.other .daynum { color: #b5b1a8; }
.cell.today { background: var(--today); }
.cell.drop { outline: 2px dashed var(--accent); outline-offset: -3px; background: var(--accent-soft); }
.cell:hover .add-hint { opacity: 1; }
.daynum { font-size: 12px; color: var(--muted); padding: 2px 4px; display: flex; justify-content: space-between; }
.add-hint { opacity: 0; color: var(--accent); font-weight: 600; }

.chip {
  display: flex; align-items: center; gap: 5px; margin: 3px 0; padding: 3px 6px;
  border-radius: 6px; background: #f3f1ec; border-left: 4px solid var(--brand, #999);
  font-size: 12px; cursor: grab; overflow: hidden;
}
.chip:hover { background: #ebe8e1; }
.chip .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chip .cc { color: var(--muted); font-size: 11px; }
.chip.dragging { opacity: .4; }
.sdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.st-doing { background: var(--st-doing); }
.st-review { background: var(--st-review); }
.st-scheduled { background: var(--st-scheduled); }
.st-posted { background: var(--st-posted); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- mobile list ---------- */
.mlist { display: none; }
.mday { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.mday h3 { margin: 0; padding: 8px 12px; font-size: 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.mday.today h3 { background: var(--today); }
.mday .chip { margin: 6px 10px; padding: 8px 10px; font-size: 14px; cursor: pointer; }
.empty { color: var(--muted); text-align: center; padding: 30px; }
.fab {
  position: fixed; right: 18px; bottom: 18px; border-radius: 999px; padding: 12px 18px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); display: none;
}

@media (max-width: 760px) {
  main { padding: 12px 12px 90px; }
  .cal, .legend { display: none; }
  .mlist { display: block; }
  .fab { display: inline-flex; }
  .month-title { font-size: 17px; min-width: 0; }
  .month-nav { width: 100%; }
  #new-item, .me, .logo span { display: none; }
  .topbar { padding: 10px 12px; }
}

/* ---------- modal ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(20,18,15,.45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto;
}
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 620px; padding: 20px; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text], .field input[type=date], .field input[type=email], .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.field textarea { min-height: 70px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; color: var(--ink); font-size: 13px; margin: 0; cursor: pointer;
}
.checks input:checked + span { font-weight: 600; color: var(--accent); }
.links-view a { display: block; color: var(--accent); word-break: break-all; font-size: 13px; }
.meta { font-size: 12px; color: var(--muted); margin: 4px 0 14px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.actions .left { margin-right: auto; }

.comments { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.comments h3 { font-size: 14px; margin: 0 0 8px; }
.comment { padding: 8px 10px; background: #f6f5f2; border-radius: 8px; margin-bottom: 6px; }
.comment .who { font-size: 12px; color: var(--muted); }
.comment .body { white-space: pre-wrap; word-break: break-word; }
.comment-form { display: flex; gap: 8px; margin-top: 8px; }
.comment-form textarea { flex: 1; min-height: 40px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- settings ---------- */
.settings h1 { font-size: 20px; margin: 0 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card p.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.srow { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid #f0eee9; flex-wrap: wrap; }
.srow:last-child { border-bottom: none; }
.srow input[type=text], .srow input[type=email] { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; flex: 1; min-width: 140px; }
.srow input[type=color] { width: 40px; height: 32px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; }
.srow .email { flex: 1; min-width: 180px; color: var(--muted); word-break: break-all; }
.srow label { display: inline-flex; gap: 4px; align-items: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: 90vw;
}
.toast.err { background: var(--danger); }
.notice { background: #fff7df; border: 1px solid #f1dfa6; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
