:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #5f6b64;
  --line: #dde2de;
  --primary: #1f6f4a;
  --primary-hover: #185a3c;
  --primary-text: #ffffff;
  --danger: #b3261e;
  --ok-bg: #e3f4ea;
  --ok-fg: #17603d;
  --warn-bg: #fff3d6;
  --warn-fg: #7a5200;
  --bad-bg: #fde7e5;
  --bad-fg: #9b1c14;
  --busy-bg: #e5eefc;
  --busy-fg: #1f4f9c;
  --muted-bg: #eceeed;
  --green: #2e9d5b;
  --yellow: #e0a400;
  --red: #d33a2c;
  --radius: 10px;
  --focus: #2b6cd8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b211e;
    --text: #e6ebe8;
    --muted: #9aa69f;
    --line: #2e3632;
    --primary: #3f9d6d;
    --primary-hover: #4cb07e;
    --primary-text: #0d1310;
    --danger: #f07167;
    --ok-bg: #183526;
    --ok-fg: #8fd9ad;
    --warn-bg: #3a2f12;
    --warn-fg: #f3cf75;
    --bad-bg: #3d1a17;
    --bad-fg: #f5a59d;
    --busy-bg: #1a2a45;
    --busy-fg: #a9c5f5;
    --muted-bg: #262c29;
    --focus: #7aa7f0;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai", "Sarabun", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0 0 8px; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 20px; }
p { margin: 4px 0; }
a { color: var(--primary); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---- layout ---- */

.topbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.who { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}

.section-head {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}

.row-end { display: flex; justify-content: flex-end; margin-top: 8px; }

.hint { color: var(--muted); font-size: 0.88rem; }
.muted { color: var(--muted); }
.block { display: block; }
.empty { color: var(--muted); text-align: center; padding: 16px 0; }

.quota { font-size: 0.95rem; }
.quota-out { color: var(--danger); }

/* ---- buttons + fields ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-small { min-height: 34px; padding: 4px 10px; font-size: 0.9rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-weight: 600; font-size: 0.92rem; }
input[type=text], input[type=password], select {
  font: inherit; color: var(--text); background: var(--surface);
  min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%;
}
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); margin: 0; flex: none; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }

/* ---- messages + badges ---- */

.msg { border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.msg p { margin: 2px 0 0; }
.msg-error { background: var(--bad-bg); color: var(--bad-fg); }
.msg-ok { background: var(--ok-bg); color: var(--ok-fg); }
.msg-info { background: var(--busy-bg); color: var(--busy-fg); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem;
  font-weight: 600; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-busy { background: var(--busy-bg); color: var(--busy-fg); }
.badge-muted, .badge-none { background: var(--muted-bg); color: var(--muted); }

.tag {
  display: inline-block; margin: 2px 0 0 6px; padding: 0 6px; font-size: 0.78rem;
  border: 1px solid var(--line); border-radius: 6px; color: var(--muted);
}
.fail { color: var(--bad-fg); margin-top: 4px; }

/* ---- tables ---- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; vertical-align: top; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.clip-name { font-weight: 600; word-break: break-word; max-width: 280px; }
.cell-action { text-align: right; }
.cell-action > * { margin: 2px 0 2px 6px; }

.lang-list { display: flex; flex-direction: column; gap: 6px; }
.lang-item, .toggle { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lang-item label, .toggle label { cursor: pointer; }

.drive-link { display: inline-block; margin-right: 10px; }

.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tab {
  font: inherit; border: 0; background: var(--surface); color: var(--text);
  padding: 6px 14px; min-height: 36px; cursor: pointer;
}
.tab[aria-selected=true] { background: var(--primary); color: var(--primary-text); font-weight: 600; }

/* ---- status checks ---- */

.checks { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 5px; flex: none; }
.check-green .dot { background: var(--green); }
.check-yellow .dot { background: var(--yellow); }
.check-red .dot { background: var(--red); }
.check-red { border-color: var(--red); }
.check-tone { color: var(--muted); font-size: 0.88rem; }
.check-version { color: var(--muted); font-size: 0.85rem; }
.check-langs { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.lang-list { list-style: none; padding: 0; margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.lang-list li { padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; overflow-wrap: anywhere; }
.lang-list .lang-hit { border-color: var(--green); font-weight: 600; }
.legal { max-width: 760px; }
.legal h2 { margin-top: 20px; }

/* ---- dialog ---- */

.dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-lines { padding-left: 18px; margin: 8px 0 12px; }
.dialog-lines li { margin-bottom: 6px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

/* ---- login ---- */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }

/* ---- phones: tables become cards ---- */

@media (max-width: 760px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }
  .table-cards td { border: 0; padding: 4px 0; }
  .table-cards td[data-label]::before {
    content: attr(data-label); display: block; font-size: 0.78rem; color: var(--muted); font-weight: 600;
  }
  .clip-name { max-width: none; }
  .cell-action { text-align: left; }
  .cell-action > * { margin: 4px 6px 0 0; }
  .cell-action .btn { width: 100%; }
}
