/* คลังไอเดีย — โทนอบอุ่น สีจีวรเป็นสีเน้น */
:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --surface-2: #faf7f3;
  --border: #e7dfd5;
  --text: #2a241f;
  --muted: #7a6e63;
  --accent: #b4531a;
  --accent-ink: #ffffff;
  --accent-soft: #fbeadb;
  --idea: #6d4bd1;
  --idea-soft: #efe9fc;
  --know: #1f7a6d;
  --know-soft: #e3f3f0;
  --ok: #2f7d3b;
  --ok-soft: #e5f4e7;
  --warn: #a35c00;
  --warn-soft: #fdf0dc;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412;
    --surface: #211d1a;
    --surface-2: #1b1816;
    --border: #3a332d;
    --text: #f1ebe4;
    --muted: #a99d91;
    --accent: #e8874a;
    --accent-ink: #1b1209;
    --accent-soft: #3a2618;
    --idea: #b6a0ff;
    --idea-soft: #2a2340;
    --know: #6fd1c0;
    --know-soft: #17302b;
    --ok: #7fd08a;
    --ok-soft: #1c3020;
    --warn: #f0b45c;
    --warn-soft: #362812;
    --danger: #ff8a80;
    --danger-soft: #3a1c1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[v-cloak] { display: none; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "IBM Plex Sans Thai", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── ปุ่ม ─────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 40px; padding: .45em 1.05em; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 500; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.sm { min-height: 32px; padding: .2em .75em; font-size: .875rem; }

/* ── หน้า login ───────────────────────── */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 40px 28px 28px; box-shadow: var(--shadow);
}
.login-mark { font-size: 44px; line-height: 1; }
.login-card h1 { margin: 12px 0 4px; font-size: 1.6rem; }
.login-sub { margin: 0 0 24px; color: var(--muted); }
.login-error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; margin: 0 0 16px; font-size: .925rem; }
.btn.google { width: 100%; min-height: 48px; background: var(--surface); font-weight: 600; }
.login-note { margin: 16px 0 0; font-size: .85rem; color: var(--muted); }

/* ── โครงหน้า ─────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, calc((100vw - 960px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 34px; height: 34px; }
.brand h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.brand p { margin: 0; font-size: .78rem; color: var(--muted); }
.user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user img { width: 30px; height: 30px; border-radius: 50%; }
.user .name { font-size: .9rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }

.wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 80px; }

/* ── กล่องเก็บไอเดีย ──────────────────── */
.capture {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 12px 10px; margin-bottom: 20px;
}
.capture textarea {
  width: 100%; border: 0; background: transparent; resize: vertical; min-height: 56px;
  padding: 4px 6px; outline: none; font-size: 1rem;
}
.capture textarea::placeholder { color: var(--muted); }
.capture-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 6px; border-top: 1px dashed var(--border); }
.hint { font-size: .82rem; color: var(--muted); }

/* ── แท็บ + ตัวกรอง ───────────────────── */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active { background: var(--text); color: var(--bg); }
.tab .count { font-size: .78rem; padding: 0 7px; border-radius: 999px; background: var(--border); color: var(--text); min-width: 22px; text-align: center; }
.tab.active .count { background: color-mix(in srgb, var(--bg) 25%, transparent); color: var(--bg); }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select {
  min-height: 40px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 0 12px;
}
.filters input { flex: 1 1 220px; }
.filters select { flex: 1 1 160px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 0 12px; min-height: 38px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ── การ์ด ─────────────────────────────── */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); transform: translateY(-1px); }
.card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.card-top time { margin-left: auto; }
.card h3 { margin: 6px 0 2px; font-size: 1.05rem; line-height: 1.45; }
.card .sum { margin: 0; color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.chip.idea { background: var(--idea-soft); color: var(--idea); border-color: transparent; }
.chip.knowledge { background: var(--know-soft); color: var(--know); border-color: transparent; }
.chip.suggest { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.decided { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.link { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.processing { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .92rem; margin: 4px 0 0; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── สถานะว่าง / โหลด ─────────────────── */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 40px; }
.empty h3 { color: var(--text); margin: 8px 0 4px; }
.empty p { margin: 0 auto; max-width: 420px; }
.skeleton { height: 92px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── แผงรายละเอียด ────────────────────── */
.backdrop { position: fixed; inset: 0; background: rgba(20, 14, 8, .38); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(560px, 100vw); background: var(--bg); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .12);
}
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.drawer-head .id { color: var(--muted); font-size: .9rem; }
.drawer-head .spacer { flex: 1; }
.drawer-body { overflow-y: auto; padding: 18px 16px 40px; display: grid; gap: 18px; align-content: start; }
.title-input {
  width: 100%; border: 1px solid transparent; background: transparent; border-radius: 8px;
  font-size: 1.3rem; font-weight: 700; line-height: 1.4; padding: 2px 6px; margin-left: -6px;
}
.title-input:hover { border-color: var(--border); }
.title-input:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: .85rem; }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.section h4 { margin: 0 0 10px; font-size: .9rem; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.summary p { margin: 0 0 6px; }
.source-link { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); text-decoration: none; word-break: break-all; font-size: .9rem; }
.shot { width: 100%; border-radius: 10px; border: 1px solid var(--border); display: block; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
details.raw pre { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: .9rem; margin: 8px 0 0; padding: 10px; background: var(--surface-2); border-radius: 8px; }

.suggest-box { border-left: 3px solid var(--warn); background: var(--warn-soft); }
.suggest-box p { margin: 0; }
.suggest-box .step { margin-top: 8px; }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.choice {
  min-height: 46px; text-align: left; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); position: relative;
}
.choice:hover { border-color: var(--accent); }
.choice.on { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.choice .star { position: absolute; top: -8px; right: 8px; font-size: .7rem; background: var(--warn); color: #fff; padding: 0 6px; border-radius: 999px; }

.progress { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.progress button { min-height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.progress button.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

.related { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.related a { display: block; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); text-decoration: none; color: var(--text); }
.related a:hover { border-color: var(--accent); }
.related .why { display: block; font-size: .85rem; color: var(--muted); margin-top: 2px; }

.build { display: grid; gap: 8px; }
.build p { margin: 0; color: var(--muted); font-size: .88rem; }

.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: .85rem; color: var(--muted); }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: none; background: var(--surface); }
.save-row { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.save-row .dirty { font-size: .82rem; color: var(--warn); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); display: grid; gap: 10px; }
.timeline li { position: relative; font-size: .88rem; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline time { display: block; color: var(--muted); font-size: .78rem; }

.drawer-enter-active, .drawer-leave-active { transition: transform .22s ease, opacity .22s ease; }
.drawer-enter-from, .drawer-leave-to { transform: translateX(24px); opacity: 0; }
.fade-enter-active, .fade-leave-active { transition: opacity .2s; }
.fade-enter-from, .fade-leave-to { opacity: 0; }

/* SweetAlert2 ให้เข้ากับหน้า */
.swal2-popup { font-family: "IBM Plex Sans Thai", system-ui, sans-serif !important; border-radius: 16px !important; background: var(--surface) !important; color: var(--text) !important; }
.swal2-title, .swal2-html-container { color: var(--text) !important; }
.swal2-confirm { background: var(--accent) !important; color: var(--accent-ink) !important; border-radius: 10px !important; }

@media (max-width: 600px) {
  .user .name { display: none; }
  .brand p { display: none; }
  .hint { display: none; }
  .capture-foot { justify-content: flex-end; }
  .choices { grid-template-columns: 1fr; }
  .drawer { border-left: 0; }
}
