:root {
  --brand: #6a5ae0;
  --brand-h: #5a49d6;
  --brand-50: #f0edff;
  --bg: #f4f5fa;
  --card: #ffffff;
  --text: #20223b;
  --muted: #7a7f9a;
  --line: #e7e9f4;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Noto Sans Thai UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  --shadow: 0 1px 2px rgba(32, 34, 59, .06), 0 4px 16px rgba(32, 34, 59, .06);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.ic { width: 18px; height: 18px; flex: none; vertical-align: -3px; }

.login-body {
  background: linear-gradient(160deg, #eef0ff 0%, #f7f8fd 45%, #efeaff 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-wrap { width: 400px; max-width: calc(100vw - 40px); }

.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 40px 36px;
  text-align: center;
}

.login-logo {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo .ic { width: 26px; height: 26px; }

.login-card h1 { font-size: 26px; letter-spacing: .5px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 4px 0 24px; }
.login-foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }

.login-card form { text-align: left; }

.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: .4px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--brand-50); color: var(--brand); }

.side-foot { padding-top: 12px; border-top: 1px solid var(--line); }

.main { padding: 30px 36px; max-width: 1160px; width: 100%; margin: 0 auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.topbar h1 { font-size: 22px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--brand-h); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn-ghost:hover { border-color: var(--brand); background: var(--brand-50); text-decoration: none; color: var(--brand); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { border-color: var(--danger); background: #fdeeee; color: var(--danger); }
.btn-ghost.sm { padding: 6px 12px; font-size: 13px; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #d33d42; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.card-head h2 { font-size: 17px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.stat .ic { width: 22px; height: 22px; color: var(--brand); }
.stat .s-label { color: var(--muted); font-size: 13px; margin-top: 8px; }
.stat .s-value { font-size: 22px; font-weight: 700; margin-top: 2px; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.hint { display: block; color: var(--muted); font-size: 12.5px; margin-top: 5px; }

.form-error {
  background: #fdeeee;
  color: var(--danger);
  border: 1px solid #f6cfcf;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-top: 14px;
}

.form-success {
  background: #e9f7f0;
  color: var(--ok);
  border: 1px solid #c4ead6;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-top: 14px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1.2fr; gap: 20px; align-items: start; }

.steps { list-style: none; }
.steps li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: none; }
.steps li .ic { color: var(--ok); margin-top: 3px; }
.steps li b { display: block; font-size: 14.5px; }
.steps li span { display: block; color: var(--muted); font-size: 13px; }

.console {
  background: #101218;
  color: #9fe8b8;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.75;
  border-radius: 12px;
  padding: 16px 18px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 16px;
}

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 12.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.table td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fafbff; }

.dom-cell { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.dom-cell .ic { color: var(--brand); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-50);
  color: var(--brand);
}
.badge.gray { background: #eef0f6; color: var(--muted); }
.badge.green { background: #e9f7f0; color: var(--ok); }
.badge.red { background: #fdeeee; color: var(--danger); }
.badge.amber { background: #fdf3e1; color: #a16207; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty .ic { width: 46px; height: 46px; color: #c9cbe3; margin-bottom: 12px; }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 14px; margin-bottom: 20px; }

.cred {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  margin-bottom: 10px;
  background: #fbfcff;
}
.cred .c-label { font-size: 12.5px; color: var(--muted); }
.cred .c-value {
  font-family: var(--mono);
  font-size: 14px;
  word-break: break-all;
  max-width: 100%;
}
.cred .c-val-wrap { flex: 1; min-width: 0; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 14.5px; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 500; word-break: break-all; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(24, 26, 44, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-back[hidden],
.toast[hidden] {
  display: none !important;
}
.modal {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(24, 26, 44, .25);
  width: 480px;
  max-width: 100%;
  max-height: calc(100vh - 60px);
  overflow: auto;
  padding: 26px;
}
.modal h3 { font-size: 17px; margin-bottom: 4px; }
.modal .m-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.m-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 8px;
}
.m-close:hover { background: var(--bg); color: var(--text); }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #20223b;
  color: #fff;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(24, 26, 44, .3);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast .ic { color: #7ee2a8; }
.toast.err .ic { color: #ff9b9d; }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  flex: none;
}
.copy-btn:hover { border-color: var(--brand); color: var(--brand); }
.copy-btn.done { border-color: var(--ok); color: var(--ok); }
.copy-btn .ic { width: 14px; height: 14px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
.status-dot.green { background: var(--ok); }
.status-dot.red { background: var(--danger); }
.status-dot.amber { background: var(--warn); }

.result-hero {
  background: linear-gradient(135deg, #e9f7f0, #f2fbf6);
  border: 1px solid #c4ead6;
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.result-hero .ic { width: 30px; height: 30px; color: var(--ok); margin-top: 4px; }
.result-hero h2 { font-size: 19px; color: #187a4d; }
.result-hero p { color: #2e6b4d; font-size: 14px; }

.pass-form { max-width: 380px; }

@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .brand { padding: 4px 6px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { border: none; padding: 0; margin-left: auto; }
  .main { padding: 20px; }
  .kv { grid-template-columns: 1fr; }
}
