:root {
  --ac: #3DDC97;
  --text: #E8ECEE; --soft: #D5DADD; --muted: #9AA3A9; --dim: #7C858B; --ash: #5E676D;
  --sky: #38BDF8; --sky-t: #7DD3FC; --amber: #F5A524; --amber-t: #FBC66A; --red: #FF6B6B; --red-t: #FFB3B5; --danger: #E5484D;
  --glass: rgba(20,24,30,0.62); --line: rgba(255,255,255,0.08); --line2: rgba(255,255,255,0.12);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #04060C; color: var(--text); font: 400 14px/1.5 'IBM Plex Sans Thai', system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--text); }
.mono { font-family: var(--mono); }
.lbl { font-size: 13px; color: var(--muted); }
.dim { color: var(--dim); }
.ash { color: var(--ash); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* backdrop */
#backdrop { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background: radial-gradient(ellipse 70% 60% at 10% 30%, rgba(40,56,140,0.35) 0%, transparent 70%), linear-gradient(180deg, #04060C 0%, #080D1C 55%, #0A1222 100%); }
#backdrop svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#backdrop .layer { transition: transform 1.2s cubic-bezier(.2,.7,.2,1); }
#backdrop .topfade { position: absolute; left: 0; right: 0; top: 0; height: 30%; background: linear-gradient(180deg, rgba(4,6,12,.7), rgba(4,6,12,0)); }

/* shell */
#app { position: relative; z-index: 1; min-height: 100vh; padding: 20px 24px 32px; display: flex; flex-direction: column; gap: 18px; }
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding-right: 12px; font-weight: 500; font-size: 15px; }
.glass { background: var(--glass); -webkit-backdrop-filter: blur(18px) saturate(1.2); backdrop-filter: blur(18px) saturate(1.2); border: 1px solid var(--line); border-radius: 18px; }
nav.pills { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; border-radius: 999px; }
.pill { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px; color: #AEB6BB; text-decoration: none; white-space: nowrap; font-size: 14px; }
.pill:hover { color: #fff; background: rgba(255,255,255,.06); }
.pill.on { background: rgba(255,255,255,.10); color: #fff; }
.top .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.search { width: 300px; max-width: 60vw; height: 40px; padding: 0 16px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); outline: none; }
.search:focus, .field:focus { border-color: color-mix(in srgb, var(--ac) 60%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac) 12%, transparent); }
.iconbtn { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--glass); border: 1px solid var(--line); cursor: pointer; color: var(--soft); }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); font-size: 13px; color: var(--soft); }
.chip b { color: #fff; font-weight: 400; }
h1.page { margin: 0; font-size: 44px; font-weight: 300; letter-spacing: -0.01em; text-shadow: 0 2px 20px rgba(0,0,0,.5); }
.big { font-weight: 200; letter-spacing: -0.02em; line-height: 1.05; }
.big .tail { color: var(--ash); }

/* buttons + fields */
.btn { height: 44px; padding: 0 20px; border-radius: 12px; border: 1px solid var(--line2); background: rgba(255,255,255,.08); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: rgba(255,255,255,.12); }
.btn.primary { border: 0; background: var(--ac); color: #062019; font-weight: 600; box-shadow: 0 0 24px color-mix(in srgb, var(--ac) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: rgba(120,40,40,.35); border-color: rgba(229,72,77,.35); color: var(--red-t); }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .pill:focus-visible, .card:focus-visible, .rowbtn:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }
.field { width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; background: rgba(6,8,12,.6); border: 1px solid var(--line2); outline: none; }
textarea.field { height: auto; min-height: 70px; padding: 10px 12px; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9AA3A9 50%), linear-gradient(135deg, #9AA3A9 50%, transparent 50%); background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.form .full { grid-column: 1 / -1; }

/* status tags */
.tag { display: inline-flex; align-items: center; font-size: 12px; padding: 2px 11px; border-radius: 999px; border: 1px solid var(--ash); color: var(--muted); white-space: nowrap; }
.tag.active { border-color: var(--ac); color: var(--ac); }
.tag.expiring { border-color: var(--amber); color: var(--amber-t); }
.tag.suspended { border-color: var(--red); color: var(--red-t); }
.tag.recurring { border-color: var(--sky); color: var(--sky-t); }
.tag.soft { background: rgba(255,255,255,.06); border-color: transparent; color: #C3CACE; }

/* layout helpers */
.cols { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; flex: 1; }
.main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.side { flex: 1 1 340px; max-width: 440px; display: flex; flex-direction: column; gap: 12px; }
.left { flex: 0 1 360px; min-width: 300px; display: flex; flex-direction: column; gap: 12px; }
.card { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card .head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.tile { border-radius: 12px; background: rgba(255,255,255,.04); padding: 10px 12px; display: flex; flex-direction: column; }
.tile .lbl { font-size: 11px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ac); box-shadow: 0 0 10px var(--ac); display: inline-block; }
.empty { padding: 28px 12px; text-align: center; color: var(--dim); }

/* table */
.tablebox { overflow-x: auto; padding: 6px 8px; }
table.list { width: 100%; min-width: 680px; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 400; font-size: 12px; color: var(--dim); padding: 12px; }
table.list td { padding: 13px 12px; }
table.list tr.r { cursor: pointer; }
table.list tr.r:hover td { background: rgba(255,255,255,.04); }
table.list tr.sel td { background: rgba(255,255,255,.08); }
table.list td:first-child { border-radius: 12px 0 0 12px; }
table.list td:last-child { border-radius: 0 12px 12px 0; }
.rowbtn { all: unset; cursor: pointer; font-family: var(--mono); font-size: 13px; }

/* timeline + events */
.timeline { border-left: 1px solid rgba(255,255,255,.18); margin-left: 8px; padding-left: 14px; display: flex; flex-direction: column; gap: 10px; }
.ev { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.ev:last-child { border-bottom: 0; }
.ev time { font-family: var(--mono); font-size: 11px; color: var(--dim); min-width: 44px; padding-top: 2px; }
.warnbox { background: rgba(120,40,40,.35); border: 1px solid rgba(229,72,77,.25); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.badge-n { width: 18px; height: 18px; flex: none; border-radius: 50%; background: var(--danger); font-size: 11px; display: inline-flex; align-items: center; justify-content: center; color: #fff; }

/* product cards */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.pcard { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; gap: 14px; padding: 18px; border-radius: 18px; background: var(--glass); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border: 1px solid var(--line); }
.pcard:hover { background: rgba(36,40,48,.72); }
.pcard.sel { border-color: color-mix(in srgb, var(--ac) 60%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac) 12%, transparent), 0 0 32px color-mix(in srgb, var(--ac) 18%, transparent); }
.pcard.add { border: 1px dashed rgba(255,255,255,.18); background: rgba(20,24,30,.35); align-items: center; justify-content: center; min-height: 260px; text-align: center; gap: 10px; }
.glyph { width: 46px; height: 46px; flex: none; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 500; border: 1px solid var(--ac); color: var(--ac); background: color-mix(in srgb, var(--ac) 14%, transparent); }
pre.code { margin: 0; padding: 12px; border-radius: 12px; background: rgba(6,8,12,.7); border: 1px solid var(--line); font: 11.5px/1.7 var(--mono); color: #C3CACE; white-space: pre-wrap; word-break: break-all; }

/* dialog */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: min(520px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgba(2,4,8,.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog .card { padding: 24px; gap: 16px; }
.keys { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow: auto; }
.keys div { font-family: var(--mono); padding: 8px 12px; border-radius: 10px; background: rgba(255,255,255,.05); }

/* login */
.login { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 32px; padding: 24px; }
.wordmark { font: 400 22px var(--mono); letter-spacing: .9em; padding-left: .9em; color: #F1F4FF; text-shadow: 0 0 14px rgba(180,195,255,.8); text-align: center; }
.login .card { width: min(380px, 100%); padding: 24px; }
.err { color: var(--red-t); font-size: 13px; min-height: 18px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 12px 18px; border-radius: 12px; background: rgba(20,24,30,.92); border: 1px solid var(--line2); font-size: 14px; }

@media (max-width: 720px) {
  #app { padding: 14px 16px 24px; }
  h1.page { font-size: 34px; }
  .top .right { margin-left: 0; width: 100%; }
  .search { flex: 1; width: auto; max-width: none; }
  .form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { #backdrop .layer { transition: none; } }
