:root {
  --ink: #16211c;
  --muted: #68756f;
  --line: #dce6e0;
  --surface: #ffffff;
  --canvas: #f2f6f3;
  --green: #0d6b48;
  --green-dark: #06472f;
  --mint: #dcf6e7;
  --yellow: #f5c74c;
  --red: #b42318;
  --red-soft: #fee9e7;
  --shadow: 0 18px 50px rgba(18, 54, 39, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% 0, rgba(245, 199, 76, 0.2), transparent 25%),
    var(--canvas);
  color: var(--ink);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 12px max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid rgba(220, 230, 224, 0.9);
  background: rgba(242, 246, 243, 0.88);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: var(--green-dark);
  color: white;
  font-weight: 900;
  letter-spacing: -0.04em;
}
.brand p, .eyebrow {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.14em;
}
.brand h1 { margin: 0; font-size: 17px; }

.ghost-button, .secondary-button, .icon-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--green-dark);
}
.ghost-button { padding: 9px 13px; border-radius: 10px; font-size: 11px; font-weight: 800; }

main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 60px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 26px;
  padding: 38px;
  overflow: hidden;
  border-radius: 25px;
  background:
    linear-gradient(120deg, rgba(255,255,255,0.04), transparent),
    var(--green-dark);
  color: white;
  box-shadow: var(--shadow);
}
.hero .eyebrow { color: #8fe0b4; }
.hero h2 { margin: 7px 0 10px; font-size: clamp(34px, 5vw, 56px); line-height: 1.02; letter-spacing: -0.05em; }
.hero p:last-child { max-width: 530px; margin: 0; color: #c7ddd2; font-size: 14px; }

.primary-button {
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--green);
  color: white;
  font-weight: 900;
}
.hero .primary-button { flex: 0 0 auto; background: var(--yellow); color: #263029; }
.primary-button:disabled { cursor: wait; opacity: 0.62; }
.full { width: 100%; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 13px;
  margin-bottom: 18px;
}
.stats-grid article {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: white;
}
.stats-grid span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.stats-grid strong { font-size: 29px; letter-spacing: -0.04em; }

.table-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 21px;
  background: white;
  box-shadow: 0 8px 25px rgba(18, 54, 39, 0.05);
}
.table-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px; }
.table-header h2 { margin: 0; font-size: 19px; }
.table-actions { display: flex; align-items: center; gap: 8px; }
.table-actions input {
  width: min(320px, 42vw);
  height: 41px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: 0;
}
.table-actions input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13,107,72,0.11); }
.icon-button { width: 41px; height: 41px; border-radius: 11px; font-size: 18px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f7faf8; color: var(--muted); font-size: 9px; letter-spacing: 0.09em; text-align: left; }
td { padding: 14px; border-bottom: 1px solid #edf1ef; font-size: 12px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td code { color: var(--green-dark); font-weight: 900; }

.plan-badge, .status-badge {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef3f0;
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
}
.status-badge.active { background: var(--mint); color: var(--green-dark); }
.status-badge.revoked, .status-badge.expired { background: var(--red-soft); color: var(--red); }
.note { max-width: 220px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.row-actions button { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--muted); font-size: 9px; font-weight: 800; }
.row-actions .revoke-button { color: var(--red); }
.row-actions button:disabled { cursor: not-allowed; opacity: 0.35; }
.empty-cell { padding: 35px; color: var(--muted); text-align: center; }

dialog {
  width: min(580px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: transparent;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 26, 17, 0.58); backdrop-filter: blur(5px); }
.dialog-card { padding: 27px; background: white; }
.dialog-card.small { max-width: 430px; margin: auto; }
.dialog-card h2 { margin: 3px 0 6px; font-size: 24px; }
.dialog-card > p:not(.eyebrow):not(.form-message) { margin: 0 0 20px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 10px; background: #f0f4f1; color: var(--muted); font-size: 20px; }

label, legend { color: #39443f; font-size: 11px; font-weight: 800; }
input, select {
  width: 100%;
  height: 44px;
  margin-top: 6px;
  padding: 0 11px;
  border: 1px solid #ccd8d1;
  border-radius: 11px;
  outline: 0;
  background: #fbfdfc;
}
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13,107,72,0.11); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.full-width { grid-column: 1 / -1; }
fieldset { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 20px 0; padding: 13px; border: 1px solid var(--line); border-radius: 13px; }
legend { padding: 0 5px; }
.check-row { display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 9px; background: #f4f8f5; }
.check-row input { width: auto; height: auto; margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.secondary-button { min-height: 46px; padding: 0 16px; border-radius: 12px; font-weight: 800; }
.form-message { min-height: 18px; margin: 10px 0; font-size: 11px; }
.form-message.error { color: var(--red); }
.hidden { display: none !important; }

.result-dialog { text-align: center; }
.success-mark { display: grid; width: 56px; height: 56px; margin: 0 auto 14px; place-items: center; border-radius: 18px; background: var(--mint); color: var(--green); font-size: 27px; font-weight: 900; }
.license-key-box { display: flex; align-items: center; gap: 8px; margin: 18px 0; padding: 11px; border: 1px dashed #9ebdaf; border-radius: 12px; background: #f4faf6; }
.license-key-box code { flex: 1; overflow-wrap: anywhere; color: var(--green-dark); font-size: 14px; font-weight: 900; }
.license-key-box button { padding: 7px 10px; border: 0; border-radius: 8px; background: var(--green); color: white; font-size: 10px; font-weight: 800; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 340px; padding: 12px 15px; border-radius: 11px; background: var(--green-dark); color: white; font-size: 11px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: 160ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 760px) {
  main { width: min(100% - 24px, 1180px); padding-top: 18px; }
  .topbar { padding-inline: 14px; }
  .hero { align-items: flex-start; flex-direction: column; padding: 25px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table-header { align-items: stretch; flex-direction: column; }
  .table-actions input { width: 100%; }
  .form-grid, fieldset { grid-template-columns: 1fr; }
}
