:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #047857;
  --danger: #b91c1c;
  --tab: #0369a1;
  color-scheme: light;
  font-family: "Sarabun", "Thonburi", "Leelawadee UI", "Tahoma", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, p { margin: 0 0 .6rem; }
a { color: var(--tab); }

.tone-1 { --accent: #b45309; }
.tone-2 { --accent: #047857; }
.tone-3 { --accent: #1e3a8a; }

.app-header { background: var(--accent); color: #fff; }
.header-inner, .wrap { width: min(1200px, 100%); margin: 0 auto; }
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
}
.header-left, .header-right, .command, .command-actions, .filter-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.header-left { min-width: 0; }
.header-title { font-weight: 700; font-size: 1rem; }
.header-back, .header-out {
  background: rgba(255,255,255,.18);
  color: #fff;
  text-decoration: none;
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.role-badge {
  background: #fff;
  color: #0f172a;
  border-radius: 6px;
  min-height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  font-size: .8rem;
  font-weight: 600;
}

.wrap { padding: 16px 16px 96px; }
.command, .panel, .stat, .card, .home-card, .pick {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.command { padding: 14px 16px; justify-content: space-between; align-items: flex-end; }
.command label { display: grid; gap: 4px; justify-items: start; color: var(--muted); font-size: .8rem; font-weight: 700; }
.thai-picks { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.thai-picks select { width: auto; flex: 1 1 8rem; }
.filter-line form, .filter-line label { display: flex; align-items: center; gap: 8px; }
.command label span, .hint, .muted, .legend, .stat .k { color: var(--muted); font-size: .8rem; }
.command input[type="month"] { width: auto; min-width: 11rem; min-height: 40px; }
.day-badge {
  background: #f0f9ff;
  color: #0369a1;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: .78rem;
  font-weight: 700;
}
.command-actions { margin-left: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .82rem;
  text-decoration: none;
  cursor: pointer;
}
.btn.block { width: 100%; }
.btn.compact { min-height: 40px; }
.btn.indigo { background: #4f46e5; }
.btn.amber { background: #d97706; }
.btn.slate { background: #334155; }
.btn.green { background: #059669; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: #dc2626; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.stat { padding: 12px 14px; }
.stat .v { font-size: 1.55rem; font-weight: 700; line-height: 1.2; }
.stat .v.indigo { color: #4f46e5; }
.stat .v.amber { color: #d97706; }
.stat .v.green { color: #059669; }

.panel { margin-top: 12px; overflow: hidden; }
.tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 0 0 auto;
  color: #64748b;
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
  padding: 14px 16px;
  min-height: 48px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a.on { color: var(--tab); border-bottom-color: var(--tab); }
.panel-body { padding: 12px 14px 16px; }
.filter-line { justify-content: flex-start; margin-bottom: 10px; font-size: .82rem; }
.filter-line select { width: auto; min-height: 40px; min-width: 9rem; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.sheet { width: 100%; border-collapse: collapse; background: #fff; min-width: 720px; }
table.sheet th, table.sheet td { border: 1px solid #e2e8f0; padding: 8px 6px; text-align: center; font-size: .82rem; }
table.sheet th { background: #1e293b; color: #fff; font-weight: 600; }
table.sheet td.left, table.sheet th.left { text-align: left; }
table.sheet td.day { font-weight: 700; }
table.sheet td.sum { color: #059669; font-weight: 700; }
table.sheet tr.rest td { background: #fef2f2; color: #7f1d1d; }
table.sheet tr.cut td { background: #fffbeb; }
table.sheet tr.rest td.sum, table.sheet tr.cut td.sum { color: #059669; }
table.sheet tfoot td { background: #0f172a; color: #fff; font-weight: 700; }
table.sheet tfoot td.sum { color: #fff; }

.flash { border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.flash.ok { background: #ecfdf5; color: #065f46; }
.flash.bad { background: #fef2f2; color: var(--danger); }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; font-size: .85rem; }
input, select, textarea {
  width: 100%;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 96px; }
input:focus, select:focus, textarea:focus { outline: 3px solid #bae6fd; border-color: var(--tab); }
.override { color: var(--danger); background: #fef2f2; border-color: #fca5a5; font-weight: 700; }
.card { padding: 14px; margin-bottom: 12px; }
.stack, .day-list { display: grid; gap: 10px; }
.split, .actions, .meals, .between, .record-top { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.split { align-items: stretch; }
.split .field { flex: 1; }
.actions { display: grid; grid-template-columns: 1fr 1fr; }
.actions .btn, .actions form { width: 100%; }
.meals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
.meal { background: #f8fafc; border-radius: 8px; padding: 8px; text-align: center; }
.meal span { display: block; color: var(--muted); font-size: .75rem; }
.meal input { text-align: center; font-weight: 700; }
.day { padding: 12px; }
.day.rest { background: #fef2f2; }
.day.cut { background: #fffbeb; }
.day header, .record-top { display: flex; justify-content: space-between; gap: 8px; }
.note { color: var(--muted); font-size: .85rem; }
.rule { background: #f8fafc; border-radius: 8px; padding: 10px 12px; }
.hint { display: block; margin-top: 4px; }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.check { display: flex; gap: 8px; align-items: center; min-height: 44px; margin: 8px 0 14px; }
.check input { width: 20px; min-height: 20px; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); padding: 22px; text-align: left; }
.mark, .pick .num {
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  background: var(--accent);
}
.demo { font-size: .9rem; background: #f0f9ff; border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.demo code { font-family: ui-monospace, SFMono-Regular, monospace; }
.print-head { display: none; }
.home { min-height: calc(100dvh - 48px); display: grid; place-items: center; }
.home-card { width: min(960px, 100%); padding: 28px 20px; text-align: center; }
.home-card h1 { font-size: 1.35rem; }
.picker { display: grid; gap: 12px; margin-top: 18px; }
.pick { display: block; text-decoration: none; color: inherit; padding: 18px 12px; text-align: center; border-color: color-mix(in srgb, var(--pick, var(--accent)) 45%, white); background: color-mix(in srgb, var(--pick, var(--accent)) 12%, white); }
.pick .num { margin: 0 auto 8px; background: var(--pick, var(--accent)); }
.pick b { display: block; font-size: 1.05rem; }
.pick span { display: inline-block; margin-top: 8px; font-size: .75rem; border-radius: 999px; padding: 3px 8px; background: color-mix(in srgb, var(--pick, var(--accent)) 24%, white); color: var(--pick, var(--accent)); }
.home-links { margin-top: 14px; font-size: .9rem; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 8px; }
.home-links a { white-space: nowrap; }

@media (min-width: 800px) {
  .stats, .picker { grid-template-columns: repeat(4, 1fr); }
  .picker { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .submit-grid { grid-template-columns: 1fr 1fr; }
  .scroll-hint { display: none; }
}

@media (max-width: 799px) {
  .command-actions { width: 100%; margin-left: 0; }
  .command-actions .btn { flex: 1 1 calc(50% - 8px); }
}

.app-header.system-header { background: #0f172a; }
.brand-logo { height: 36px; width: auto; max-width: 140px; object-fit: contain; background: #fff; border-radius: 6px; }
.brand-logo.home-logo { height: 64px; max-width: 220px; display: block; margin: 0 auto 12px; }
.brand-preview { display: block; height: 64px; width: auto; max-width: 100%; object-fit: contain; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.brand-preview.favicon { height: 40px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 52px; min-width: 52px; padding: 4px; }
.system-tabs { margin-bottom: 14px; }
.grade-tools { align-items: stretch; margin-bottom: 12px; }
.grade-tools > .card { flex: 1; margin-bottom: 0; }

@media (max-width: 640px) {
  .split { flex-direction: column; }
}

@media print {
  .no-print, .app-header, .command, .tabs, .dock, .stats { display: none !important; }
  .print-head { display: block; text-align: center; }
  body, .panel, .card { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .panel { border: 0; }
  table.sheet { min-width: 0; }
}
