:root {
  color-scheme: light;
  --bg: #eceef1;
  --panel: #ffffff;
  --panel2: #f2f3f5;
  --line: #e3e6ea;
  --text: #111418;
  --muted: #6b7480;
  --ink: #111418;      /* ปุ่มหลัก/ตัวเด่น (ดำ) */
  --lime: #d6f24b;     /* สีเน้น */
  --red: #c93434;
  --amber: #9a6a0c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.55;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 15px; }
.err { color: var(--red); min-height: 20px; font-size: 15px; }

#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  border-radius: 0 24px 24px 0;
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  gap: 16px;
}
.brand { font-weight: 800; font-size: 24px; padding: 0 10px; }
.brand span { background: var(--ink); color: var(--lime); padding: 1px 8px; border-radius: 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar button {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 11px 14px;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 17px;
  transition: background-color .15s, color .15s;
}
.sidebar button:hover { background: var(--panel2); color: var(--text); }
.sidebar button.active { background: var(--ink); color: var(--lime); }

main { flex: 1; padding: 18px 22px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.topbar h2 { margin: 0; font-size: 24px; flex: 1; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(17,20,24,.04);
}
.card h3 { margin: 0 0 14px; font-size: 20px; }

input, textarea, select {
  width: 100%;
  background: var(--panel2);
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 14px;
  padding: 11px 14px;
  min-height: 48px;
  margin: 6px 0 12px;
  font: inherit;
}
textarea { resize: vertical; }
label { display: block; font-size: 16px; color: var(--muted); }

button {
  background: var(--ink);
  border: 0;
  color: #fff;
  padding: 11px 22px;
  min-height: 48px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  transition: filter .15s, background-color .15s;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: var(--panel); border: 1px solid var(--line); color: var(--text); font-weight: 500; }
button.danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
button:disabled { opacity: .55; cursor: default; }

.row { display: flex; gap: 8px; align-items: center; }
.table-scroll { overflow-x: auto; }
.account-actions { flex-wrap: wrap; min-width: 170px; }
.account-actions button { padding-inline: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 16px; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 6px; border-bottom: 1px solid var(--line); }
td, tbody th[scope="row"] { padding: 9px 6px; border-bottom: 1px solid var(--line); }
tbody th[scope="row"] { color: inherit; font-weight: inherit; vertical-align: middle; }
tr:last-child :is(td, th[scope="row"]) { border-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat:last-child { background: var(--lime); border-color: var(--lime); }
.stat:last-child div { color: #3a4300; }
.stat div { font-size: 14px; color: var(--muted); }
.stat b { font-size: 30px; display: block; }

.badge { font-size: 14px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: #14532d; background: var(--lime); border-color: var(--lime); }
.badge.warn { color: var(--amber); border-color: #e8d29a; background: #fff8e6; }

.pre {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  max-height: 240px;
  overflow: auto;
}
.pre.tall { max-height: 60vh; }


/* ---------- accessibility ---------- */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--ink); background: #fff; }
button.ghost:hover { background: var(--panel2); filter: none; }


/* ---------- responsive ---------- */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px; white-space: nowrap; }
  .sidebar nav { flex-direction: row; gap: 4px; }
  .sidebar button { white-space: nowrap; }
  main { padding: 14px 12px 32px; }
  .card { overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.sent { color: var(--green, #1f7a45); font-weight: 700; text-transform: uppercase; }

fieldset { min-width: 0; margin: 0; border: 0; padding: 0; }
#savedWrap { margin-bottom: 12px; }
#savedLogins { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.saved-login {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
}
.saved-login button.ghost { border: 0; min-height: 40px; }
.saved-login button:last-child { padding-inline: 12px; }
.account-auto { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.account-auto input { width: auto; }
.cookie-help { margin: 6px 0; line-height: 1.6; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14171d;
  --panel: #1c2028;
  --panel2: #272d37;
  --line: #3a424f;
  --text: #f3f5f8;
  --muted: #b4bfcc;
  --ink: #101319;
  --red: #ff9d9d;
  --amber: #ffd184;
  --green: #7ddc9c;
}

.session-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.session-bar #adminLogin {
  flex: 0 1 28rem;
  margin-inline: auto;
}
.session-bar:has(#adminLogin:not([hidden])) #adminLogin { order: 1; }
.session-bar:has(#adminLogin:not([hidden])) > .preferences { flex-basis: 100%; justify-content: flex-end; }
.preferences, .preferences [role="group"], .ops-pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
}
.preferences [aria-pressed="true"] {
  border-color: var(--text);
  background: var(--panel2);
  color: var(--text);
}
.ops-health { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: .5rem; }
.ops-health dt { color: var(--muted); }
.ops-health dd { margin: 0; overflow-wrap: anywhere; }
.ops-filters { display: flex; align-items: end; flex-wrap: wrap; gap: .75rem; margin-block: 1rem; }
.ops-filters input, .ops-filters select { margin: .25rem 0 0; }
.ops-pagination { justify-content: flex-end; padding-top: .75rem; }
.ops-id { overflow-wrap: anywhere; }
