/* =========================================================
   Username Router — design tokens
   ink / canvas / cobalt signal, mono สำหรับข้อมูลเชิงเทคนิค
   ========================================================= */
:root {
  --ink: #12161c;
  --muted: #5c6675;
  --canvas: #e7e9ee;
  --surface: #ffffff;
  --line: #d3d8e2;
  --signal: #2447e8;
  --signal-deep: #1a35b0;
  --signal-soft: #e7ebfd;
  --ok: #0e7a5f;
  --ok-soft: #e2f3ee;
  --warn: #a86200;
  --warn-soft: #fbeedb;
  --danger: #c2263c;
  --danger-soft: #fbe6e9;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(18, 22, 28, .06), 0 12px 32px -18px rgba(18, 22, 28, .35);

  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-variant-ligatures: none; }
.muted { color: var(--muted); }
.ta-right { text-align: right; }

a { color: var(--signal); }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------------- Public shell ---------------- */

.shell .stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
}

.card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.card-center { text-align: center; }

.eyebrow {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.lede {
  margin: 0 0 22px;
  font-size: clamp(24px, 5.5vw, 30px);
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -.02em;
}

.body-text { margin: 0 0 22px; color: var(--muted); }

.echo {
  font-family: var(--mono);
  font-size: 15px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 12px;
  margin: 0 0 18px;
  word-break: break-all;
}

.hint { margin: 14px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* ---- signature: prefix meter ---- */

.meter {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 58px;
  margin-bottom: 8px;
  padding: 8px 2px;
  overflow: hidden;
}

.meter-cells { display: flex; gap: 5px; flex: 0 0 auto; }

.meter-cell {
  width: 34px;
  height: 42px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--signal);
  background: var(--signal-soft);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background .15s ease, color .15s ease;
}

.meter-cell.is-empty {
  color: var(--line);
  background: transparent;
  border-color: var(--line);
  border-style: dashed;
}

.meter-tail {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  .meter-cell { transition: none; }
}

/* ---------------- Forms ---------------- */

.form { display: block; }

.field { display: block; margin-bottom: 16px; }

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"], input[type="url"], input[type="password"], input:not([type]), select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.field input.mono, input.mono { font-family: var(--mono); }

input:focus, select:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-soft);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  cursor: pointer;
}

.check input { width: 18px; height: 18px; accent-color: var(--signal); }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  padding: 13px 18px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.btn-primary { background: var(--signal); color: #fff; }
.btn-primary:hover { background: var(--signal-deep); }

.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { font-size: 13px; padding: 8px 12px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- Notices ---------------- */

.notice {
  margin: 0 0 16px;
  padding: 11px 14px;
  border-radius: var(--r-md);
  font-size: 14px;
}

.notice-error { background: var(--danger-soft); color: var(--danger); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.badge-error { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

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

.topbar {
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }

.brand-mark {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  background: var(--signal);
  border-radius: var(--r-sm);
  padding: 5px 7px;
}

.brand-name { font-weight: 600; font-size: 15px; }

.topnav { display: flex; gap: 4px; margin-inline-start: auto; }

.topnav a {
  color: rgba(255, 255, 255, .72);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--r-sm);
}

.topnav a:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.topnav a.is-current { color: #fff; background: rgba(255, 255, 255, .16); }

.topbar-out .btn-ghost {
  background: transparent;
  color: rgba(255, 255, 255, .8);
  border-color: rgba(255, 255, 255, .25);
}

.topbar-out .btn-ghost:hover { color: #fff; border-color: #fff; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 18px calc(48px + env(safe-area-inset-bottom));
}

.wrap-narrow { max-width: 640px; }

.wrap .notice { margin-top: 18px; margin-bottom: 0; }

/* ---------------- Stats ---------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 18px;
}

.stat-num {
  display: block;
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.stat-label { font-size: 13px; color: var(--muted); }

/* ---------------- Panel ---------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px;
  margin-bottom: 20px;
}

.panel-title { margin: 0 0 16px; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.panel-head .panel-title { margin: 0; }

.panel-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.search { display: flex; gap: 8px; align-items: center; }
.search input, .search select { font-size: 14px; padding: 8px 11px; width: auto; min-width: 160px; }

.row-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row-form .field { margin-bottom: 0; }
.row-form .check { margin-bottom: 8px; }
.field-prefix { width: 130px; }
.field-note { width: 190px; }
.field-grow { flex: 1 1 260px; min-width: 220px; }

/* ---------------- Table ---------------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }

.chip {
  display: inline-block;
  background: var(--signal-soft);
  color: var(--signal-deep);
  border-radius: var(--r-sm);
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 500;
}

.url {
  display: inline-block;
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.note { display: block; font-size: 12px; color: var(--muted); }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-inline-end: 7px;
}

.dot-on { background: var(--ok); }
.dot-off { background: var(--line); }

.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-bad { background: var(--danger-soft); color: var(--danger); }

.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.actions form { display: inline; }

.empty {
  margin: 0;
  padding: 28px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.pager-info { font-size: 13px; color: var(--muted); }

.meta { margin: 18px 0 0; display: grid; gap: 8px; font-size: 14px; }
.meta > div { display: flex; gap: 10px; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 8px; }
.meta dt { color: var(--muted); margin: 0; }
.meta dd { margin: 0; }

/* ---------------- Mobile: ตารางกลายเป็นการ์ด ---------------- */

@media (max-width: 720px) {
  .topbar-inner { padding: 10px 14px; }
  .brand-name { display: none; }
  .topnav { margin-inline-start: 0; order: 3; width: 100%; }
  .topnav a { flex: 1; text-align: center; }
  .topbar-out { margin-inline-start: auto; }

  .panel { padding: 16px; border-radius: var(--r-md); }
  .row-form { flex-direction: column; align-items: stretch; }
  .field-prefix, .field-note, .field-grow { width: 100%; }
  .search { width: 100%; }
  .search input, .search select { flex: 1; min-width: 0; }
  .panel-tools { width: 100%; }

  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }

  .table tr {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 6px 12px;
    margin-bottom: 10px;
  }

  .table td {
    border-bottom: 1px dashed var(--line);
    padding: 9px 0;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    align-items: center;
    text-align: right;
  }

  .table td::before {
    content: attr(data-th);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    flex: 0 0 auto;
  }

  .table td:last-child { border-bottom: 0; }
  .url { max-width: 60vw; }
  .actions { justify-content: flex-end; }
  .card { padding: 24px 20px; }
  .meter-cell { width: 30px; height: 38px; font-size: 18px; }
}
/* GOLD-THEME-START */
body.gold{--g-gold:#d4af37;--g-gold-soft:#b8912e;--g-gold-bright:#f4d576;--g-muted:#9a9186;background:radial-gradient(1200px 700px at 50% -10%,rgba(212,175,55,.10),transparent 60%),radial-gradient(900px 600px at 50% 120%,rgba(212,175,55,.06),transparent 60%),linear-gradient(180deg,#0a0a0b,#131215);background-attachment:fixed;color:#f3eee6}
body.gold .stage{padding:max(20px,5vh) 18px calc(20px + env(safe-area-inset-bottom))}
body.gold .card{width:100%;max-width:440px;margin:0 auto;background:linear-gradient(180deg,rgba(30,27,22,.92),rgba(18,16,20,.96));border:1px solid #2f2a22;border-radius:20px;box-shadow:0 1px 0 rgba(244,213,118,.14) inset,0 30px 80px -30px rgba(0,0,0,.85),0 0 0 1px rgba(212,175,55,.08);padding:32px 32px 40px;position:relative;overflow:hidden}
body.gold .card::before{content:"";position:absolute;top:0;left:24px;right:24px;height:1px;background:linear-gradient(90deg,transparent,var(--g-gold),transparent);opacity:.7}
body.gold .brand-logo{display:block;width:min(78%,300px);height:auto;margin:4px auto 26px;filter:drop-shadow(0 4px 14px rgba(212,175,55,.25))}
body.gold .field-label{color:var(--g-gold-bright);font-weight:600;letter-spacing:.02em;text-transform:none;font-size:clamp(14px,3.6vw,16px)}
body.gold input[type="text"]{background:#0e0d10;border:1px solid #3a332690;color:#f6f1e7;font-size:clamp(16px,4.2vw,18px);padding:15px 16px;border-radius:12px}
body.gold input[type="text"]::placeholder{color:#6f675b}
body.gold input[type="text"]:focus{border-color:var(--g-gold);box-shadow:0 0 0 3px rgba(212,175,55,.18),0 0 24px -6px rgba(212,175,55,.35);background:#100e12}
body.gold .btn-primary{background:linear-gradient(180deg,var(--g-gold-bright),var(--g-gold) 55%,var(--g-gold-soft));color:#1a1508;font-weight:700;font-size:clamp(15px,4vw,17px);letter-spacing:.03em;padding:15px 18px;border:1px solid #8a6d1f;border-radius:12px;margin-top:4px;box-shadow:0 1px 0 rgba(255,255,255,.35) inset,0 10px 26px -10px rgba(212,175,55,.5);transition:transform .12s ease,box-shadow .15s ease,filter .15s ease}
body.gold .btn-primary:hover{filter:brightness(1.06);box-shadow:0 1px 0 rgba(255,255,255,.4) inset,0 14px 32px -10px rgba(212,175,55,.65)}
body.gold .btn-primary:active{transform:translateY(1px)}
body.gold .hint{color:var(--g-muted);font-size:12.5px;margin-top:16px;text-align:center}
body.gold .notice-error{background:rgba(120,30,30,.25);color:#f0a5a5;border:1px solid rgba(180,60,60,.35)}
body.gold :focus-visible{outline-color:var(--g-gold)}
@media (max-width:380px){body.gold .card{padding:26px 20px 30px}body.gold .brand-logo{margin-bottom:20px}body.gold .hint{font-size:12px}}
@media (min-width:768px){body.gold .card{max-width:460px;padding:40px 40px 48px}}
@media (max-height:480px) and (orientation:landscape){body.gold .stage{padding-top:16px;padding-bottom:16px}body.gold .card{padding:20px 24px 24px}body.gold .brand-logo{width:min(55%,220px);margin-bottom:16px}body.gold .hint{margin-top:10px}}
/* GOLD-THEME-END */
