:root {
  --yellow: #f5b800;
  --yellow-dark: #c99600;
  --yellow-soft: #fff6d6;
  --ink: #2a2620;
  --muted: #6f6a60;
  --line: #e8e2d4;
  --bg: #faf8f3;
  --card: #fff;
  --danger: #c0392b;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Sarabun', system-ui, sans-serif; font-size: 16px;
  color: var(--ink); background: var(--bg); line-height: 1.6;
  display: flex; flex-direction: column; min-height: 100vh;
}
a { color: #8a6500; }
h1, h2, h3 { line-height: 1.3; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.mt-0 { margin-top: 0; }
.container { width: min(1180px, 100% - 32px); margin: 0 auto; }
.main { flex: 1; padding: 24px 0 48px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: ui-monospace, Consolas, monospace; letter-spacing: .03em; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.req { color: var(--danger); }

/* top bar */
.topbar { background: var(--yellow); border-bottom: 4px solid var(--yellow-dark); }
.is-admin .topbar { background: var(--ink); border-color: var(--yellow); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; }
.is-admin .brand, .is-admin .nav a { color: #fff; }
.brand-mark { width: 44px; height: 44px; border-radius: 50%; background: #fff; color: var(--yellow-dark);
  display: grid; place-items: center; font-size: 22px; flex: none; }
.brand-logo { height: 56px; width: auto; max-width: 100%; flex: none; }
@media (max-width: 600px) { .brand-logo { height: 44px; } }
.brand strong { display: block; font-size: 1.15rem; }
.brand small { display: block; font-size: .85rem; opacity: .85; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.45); }
.is-admin .nav a:hover, .is-admin .nav a.active { background: rgba(245,184,0,.25); color: var(--yellow); }

/* hero */
.hero { background: linear-gradient(135deg, var(--yellow-soft), #fff); border: 1px solid var(--line);
  border-left: 6px solid var(--yellow); border-radius: var(--radius); padding: 24px 28px; margin-bottom: 20px; }
.hero h1 { margin: 0 0 8px; font-size: 2rem; }
.hero p { margin: 0 0 14px; max-width: 760px; }

/* cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px; }
.card.narrow { max-width: 440px; margin: 24px auto; }
.layout-side { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.align-end { align-items: end; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
@media (max-width: 860px) {
  .layout-side, .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* forms */
.form label { display: block; margin-bottom: 14px; font-weight: 500; }
.form h2 { border-bottom: 2px solid var(--yellow-soft); padding-bottom: 6px; margin-top: 8px; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password],
input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 9px 12px; border: 1px solid #d6cfbf; border-radius: 8px; background: #fff; margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--yellow); border-color: var(--yellow); }
textarea { resize: vertical; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input { width: auto; margin: 0; }
.radio-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 8px; }
.hp { position: absolute; left: -9999px; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
form.inline input, form.inline select { margin: 0; width: auto; }
.input-sm { width: 120px !important; padding: 5px 8px; }
.input-xs { width: 70px !important; padding: 5px 8px; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { margin: 0; }
.filter { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px; }
.filter input, .filter select { margin: 0; flex: 1; min-width: 180px; }

/* buttons */
.btn { display: inline-block; font: inherit; font-weight: 600; padding: 9px 18px; border-radius: 8px;
  border: 1px solid #d6cfbf; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { background: #f3efe5; }
.btn-primary { background: var(--yellow); border-color: var(--yellow-dark); }
.btn-primary:hover { background: #e6ad00; }
.btn-danger { background: #fff; color: var(--danger); border-color: #e7b4ae; }
.btn-danger:hover { background: #fdeceA; }
.btn-ghost { background: transparent; border-color: var(--yellow-dark); }
.btn-lg { padding: 12px 28px; font-size: 1.05rem; }
.btn-sm { padding: 4px 10px; font-size: .9rem; }
.btn-block { display: block; width: 100%; }

/* alerts & badges */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert-error { background: #fdeeec; border-color: #f0c2bc; color: #8e2a1f; }
.alert-success { background: #ecf8ef; border-color: #b9e2c3; color: #1f6b35; }
.badge { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600; white-space: nowrap; }
.badge-new { background: #fde2df; color: #a32a1c; }
.badge-in_progress { background: #fff1c2; color: #7a5a00; }
.badge-replied { background: #dcefff; color: #1b5c96; }
.badge-closed { background: #e4f4e6; color: #2a6b35; }

/* success */
.big-check { width: 72px; height: 72px; border-radius: 50%; background: var(--yellow); margin: 8px auto; display: grid; place-items: center; font-size: 36px; }
.code-box { display: inline-block; font-family: ui-monospace, Consolas, monospace; font-size: 2rem; font-weight: 700; letter-spacing: .15em;
  padding: 12px 28px; border: 2px dashed var(--yellow-dark); border-radius: 12px; background: var(--yellow-soft); margin: 8px 0 16px; }

/* stepper */
.stepper { display: flex; list-style: none; padding: 0; margin: 20px 0; counter-reset: s; }
.stepper li { flex: 1; text-align: center; position: relative; font-size: .9rem; color: var(--muted); counter-increment: s; }
.stepper li::before { content: counter(s); display: grid; place-items: center; width: 32px; height: 32px; margin: 0 auto 6px;
  border-radius: 50%; background: #eee; font-weight: 700; position: relative; z-index: 1; }
.stepper li::after { content: ''; position: absolute; top: 16px; left: -50%; width: 100%; height: 3px; background: #eee; }
.stepper li:first-child::after { display: none; }
.stepper li.done { color: var(--ink); font-weight: 600; }
.stepper li.done::before, .stepper li.done::after { background: var(--yellow); }

/* meta & content */
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.prose { white-space: normal; word-break: break-word; }
details summary { cursor: pointer; color: #8a6500; margin-top: 12px; }
.attach { background: var(--yellow-soft); padding: 8px 12px; border-radius: 8px; display: inline-block; }

/* thread */
.thread { display: flex; flex-direction: column; gap: 12px; }
.bubble { border: 1px solid var(--line); border-left: 4px solid var(--yellow); border-radius: 10px; padding: 10px 14px; background: #fffdf6; }
.bubble-internal { border-left-color: #9a9488; background: #f6f5f2; }
.bubble-head { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none;
  color: var(--ink); display: flex; flex-direction: column; border-top: 4px solid #ccc; }
.stat-n { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat.active { box-shadow: 0 0 0 2px var(--yellow); }
.stat-new { border-top-color: #e2584a; } .stat-in_progress { border-top-color: var(--yellow); }
.stat-replied { border-top-color: #3d8bd4; } .stat-closed { border-top-color: #4caf62; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; background: var(--yellow-soft); padding: 10px; white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr { cursor: default; }
.table tbody tr[onclick] { cursor: pointer; }
.table tbody tr:hover { background: #fffbea; }
.row-new td { font-weight: 600; }
.row-muted td { opacity: .5; }
.pager { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pager a { padding: 4px 12px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; }
.pager a.active { background: var(--yellow); border-color: var(--yellow-dark); color: var(--ink); }

/* bar chart */
.bar-row { margin-bottom: 10px; font-size: .95rem; }
.bar { height: 8px; background: #f0ece1; border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar span { display: block; height: 100%; background: var(--yellow); }

/* footer */
.footer { background: var(--ink); color: #ddd6c6; padding: 20px 0; font-size: .9rem; }
.footer a { color: var(--yellow); }

/* google login */
.btn-google { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; border-color: #c9c3b5; }
.btn-google:hover { background: #f7f5f0; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; font-size: .9rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.tag { display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 999px; background: #eee; color: var(--muted); }
.tag-on { background: #e4f4e6; color: #2a6b35; }
