/* IPA Sign — night theme
   night  #06080e  page
   dusk   #0d111a  raised surfaces
   rim    #1b2232  hairlines
   haze   #8a93a8  secondary text
   moon   #e4e8f2  primary text + primary action
   lamp   #f0b35b  in-progress / attention
*/
:root {
  --night: #06080e;
  --dusk: #0d111a;
  --dusk-2: #121826;
  --rim: #1b2232;
  --rim-2: #263048;
  --haze: #8a93a8;
  --haze-2: #5f6880;
  --moon: #e4e8f2;
  --moon-dim: #b9c1d4;
  --lamp: #f0b35b;
  --ok: #86d8b0;
  --alarm: #ee8b8b;

  --font: "Anuphan", -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Thonburi", "Noto Sans Thai", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--night); }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--moon);
  background:
    radial-gradient(120% 60% at 50% -10%, #111a2e 0%, rgba(17, 26, 46, 0) 60%),
    var(--night);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--mono); font-size: 0.9em; color: var(--moon-dim); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--moon); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 600px; margin: 0 auto;
  padding: calc(var(--safe-t) + 10px) 20px 10px;
  background: linear-gradient(var(--night) 70%, rgba(6, 8, 14, 0));
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: 0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn, .moon-chip {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: transparent; border: 0; color: var(--moon-dim);
}
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.icon-btn:hover, .moon-chip:hover { background: var(--dusk); }

/* ---------- layout ---------- */
.views {
  max-width: 600px; margin: 0 auto;
  padding: 4px 20px calc(var(--tabbar-h) + var(--safe-b) + 32px);
}
.view-title { font-size: 34px; line-height: 1.2; font-weight: 700; margin: 6px 0 22px; letter-spacing: -0.01em; }
.section { margin-top: 28px; }
.section-title { font-size: 15px; font-weight: 600; color: var(--haze); margin: 0 0 10px; }
.muted { color: var(--haze); }
.small { font-size: 13px; line-height: 1.5; }
.mono { font-family: var(--mono); font-size: 13.5px; word-break: break-all; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1px solid var(--rim-2);
  background: var(--dusk-2); color: var(--moon);
  font-weight: 600; font-size: 16px; text-decoration: none; white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-primary { background: var(--moon); color: var(--night); border-color: var(--moon); }
.btn-primary:hover { background: #f3f5fa; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--moon-dim); }
.btn-danger { background: transparent; border-color: rgba(238, 139, 139, 0.35); color: var(--alarm); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.btn-stack { display: grid; gap: 10px; }

/* ---------- surfaces ---------- */
.panel {
  background: var(--dusk);
  border: 1px solid var(--rim);
  border-radius: var(--r-lg);
  padding: 18px;
}
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--r-md);
  background: rgba(240, 179, 91, 0.08); border: 1px solid rgba(240, 179, 91, 0.25);
  color: #f6d7a8; font-size: 14.5px; line-height: 1.55;
}
.notice.alarm { background: rgba(238, 139, 139, 0.08); border-color: rgba(238, 139, 139, 0.3); color: #f5c2c2; }
.notice .btn { margin-top: 10px; }
.notice svg { flex: none; width: 20px; height: 20px; margin-top: 2px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- drop zone ---------- */
.drop {
  position: relative;
  display: grid; place-items: center; text-align: center;
  min-height: 260px; padding: 28px 20px;
  border-radius: var(--r-lg);
  border: 1.5px dashed var(--rim-2);
  background: radial-gradient(80% 70% at 50% 40%, rgba(228, 232, 242, 0.04), rgba(228, 232, 242, 0) 70%), var(--dusk);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop.drag { border-color: var(--moon); background: var(--dusk-2); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px;
  display: grid; place-items: center; background: var(--dusk-2); border: 1px solid var(--rim-2);
}
.drop-icon svg { width: 28px; height: 28px; fill: none; stroke: var(--moon); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.drop-title { font-size: 20px; font-weight: 600; margin: 0; }
.drop-sub { margin: 4px 0 0; color: var(--haze); font-size: 14.5px; }

/* ---------- progress ---------- */
.progress { height: 6px; border-radius: 999px; background: var(--rim); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--moon); transition: width 0.2s ease; }
.progress.lamp > i { background: var(--lamp); }
.progress.indeterminate > i { width: 35%; animation: slide 1.3s ease-in-out infinite; background: var(--lamp); }
@keyframes slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }
.progress-meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13.5px; color: var(--haze); font-variant-numeric: tabular-nums; }

/* ---------- app identity ---------- */
.app-head { display: flex; gap: 14px; align-items: center; }
.app-icon {
  flex: none; width: 60px; height: 60px; border-radius: 14px; overflow: hidden;
  background: var(--dusk-2); border: 1px solid var(--rim-2);
  display: grid; place-items: center;
}
.app-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.app-icon svg { width: 26px; height: 26px; fill: none; stroke: var(--haze-2); stroke-width: 1.6; }
.app-icon.lg { width: 84px; height: 84px; border-radius: 19px; }
.app-name { font-size: 19px; font-weight: 600; line-height: 1.35; margin: 0; overflow-wrap: anywhere; }
.app-sub { margin: 2px 0 0; color: var(--haze); font-size: 14px; }

/* ---------- form ---------- */
.field { display: block; margin-top: 16px; }
.field:first-child { margin-top: 0; }
.field-label { display: block; font-size: 14px; font-weight: 500; color: var(--haze); margin-bottom: 6px; }
.field input:not([type="checkbox"]):not([type="file"]) {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border-radius: var(--r-md); border: 1px solid var(--rim-2);
  background: var(--night); color: var(--moon); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.field input::placeholder { color: var(--haze-2); }
.field input:focus { outline: none; border-color: var(--moon-dim); box-shadow: 0 0 0 3px rgba(228, 232, 242, 0.08); }
.field input.mono { font-family: var(--mono); font-size: 15px; }
.field-hint { margin: 6px 0 0; font-size: 13px; color: var(--haze-2); }
.input-wrap { position: relative; }
.input-wrap .reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 36px; padding: 0 10px; border: 0; background: transparent; color: var(--haze); font-size: 14px;
}

.file-pick {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 14px; border-radius: var(--r-md);
  border: 1px dashed var(--rim-2); background: var(--night);
}
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file-pick .fp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick.has-file { border-style: solid; border-color: var(--rim-2); }
.file-pick .fp-action { color: var(--haze); font-size: 14px; flex: none; }

.icon-picker { display: flex; align-items: center; gap: 14px; }
.icon-picker .btn-row { flex: 1; }

details.more { margin-top: 18px; border-top: 1px solid var(--rim); padding-top: 6px; }
details.more summary {
  list-style: none; cursor: pointer; padding: 10px 0; color: var(--moon-dim); font-weight: 500;
  display: flex; align-items: center; justify-content: space-between;
}
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: ""; width: 9px; height: 9px; border-right: 1.7px solid var(--haze); border-bottom: 1.7px solid var(--haze); transform: rotate(45deg); transition: transform 0.2s ease; margin-right: 4px; }
details.more[open] summary::after { transform: rotate(225deg); }

.switch-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; }
.switch-row .sr-text { flex: 1; }
.switch-row .sr-title { display: block; font-weight: 500; }
.switch-row .sr-desc { display: block; font-size: 13px; color: var(--haze); line-height: 1.5; }
.switch { position: relative; flex: none; width: 50px; height: 30px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--rim-2); transition: background 0.2s ease; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--haze); transition: transform 0.2s ease, background 0.2s ease; }
.switch input:checked + i { background: var(--moon); }
.switch input:checked + i::after { transform: translateX(20px); background: var(--night); }
.switch input:focus-visible + i { outline: 2px solid var(--moon); outline-offset: 2px; }

.form-error { margin: 14px 0 0; color: var(--alarm); font-size: 14.5px; }
.hint { margin: 14px 0 0; font-size: 13.5px; color: var(--haze); }

/* ---------- signing / done ---------- */
.stage { text-align: center; padding: 26px 18px; }
.stage .app-icon { margin: 0 auto 14px; }
.stage-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.stage-line { color: var(--haze); font-size: 14px; margin: 0 0 18px; min-height: 1.6em; overflow-wrap: anywhere; }
.lamp-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--lamp); margin-right: 8px; vertical-align: 2px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.done-check {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(134, 216, 176, 0.1); border: 1px solid rgba(134, 216, 176, 0.3);
}
.done-check svg { width: 28px; height: 28px; fill: none; stroke: var(--ok); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- library ---------- */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; background: var(--rim); border: 1px solid var(--rim); border-radius: var(--r-lg); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 14px 16px; background: var(--dusk); border: 0; text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.row:hover { background: var(--dusk-2); }
.row .app-icon { width: 52px; height: 52px; border-radius: 12px; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub .ver { margin-right: 10px; color: var(--moon-dim); }
.row-sub { display: block; font-size: 13.5px; color: var(--haze); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-side { flex: none; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--rim-2); color: var(--haze); white-space: nowrap; }
.tag.lamp { color: var(--lamp); border-color: rgba(240, 179, 91, 0.35); }
.tag.alarm { color: var(--alarm); border-color: rgba(238, 139, 139, 0.35); }
.tag.ok { color: var(--ok); border-color: rgba(134, 216, 176, 0.35); }
.storage { margin-top: 14px; font-size: 13.5px; color: var(--haze); }

.empty { text-align: center; padding: 48px 20px; }
.empty-art { width: 76px; height: 76px; margin: 0 auto 16px; opacity: 0.9; }
.empty-title { font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.empty-sub { color: var(--haze); margin: 0 0 18px; }

/* ---------- details list ---------- */
.dl { margin: 0; border-top: 1px solid var(--rim); }
.dl > div { display: flex; gap: 16px; justify-content: space-between; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--rim); }
.dl dt { color: var(--haze); font-size: 14.5px; flex: none; }
.dl dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.log {
  margin: 12px 0 0; padding: 12px 14px; max-height: 240px; overflow: auto;
  background: var(--night); border: 1px solid var(--rim); border-radius: var(--r-md);
  font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--moon-dim); white-space: pre-wrap; word-break: break-word;
}

/* ---------- certificate / moon ---------- */
.moon-hero { display: grid; justify-items: center; text-align: center; padding: 12px 0 8px; }
.moon-hero svg { width: 176px; height: 176px; filter: drop-shadow(0 0 40px rgba(205, 214, 236, 0.16)); }
.moon-hero.revoked svg { filter: drop-shadow(0 0 40px rgba(238, 139, 139, 0.18)); }
.moon-days { font-size: 44px; font-weight: 700; line-height: 1.1; margin: 22px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.moon-days small { font-size: 20px; font-weight: 500; color: var(--moon-dim); margin-left: 6px; letter-spacing: 0; }
.moon-caption { color: var(--haze); margin: 0; }
.cert-status { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 22px; }
.cert-status .cs-text { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.cert-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--haze-2); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 10px rgba(134, 216, 176, 0.5); }
.dot.alarm { background: var(--alarm); box-shadow: 0 0 10px rgba(238, 139, 139, 0.5); }
.dot.lamp { background: var(--lamp); }
.udid { font-family: var(--mono); font-size: 13px; padding: 10px 0; border-bottom: 1px solid var(--rim); word-break: break-all; color: var(--moon-dim); }
.udid:last-child { border-bottom: 0; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(var(--safe-b) + 6px);
  background: rgba(8, 10, 17, 0.86);
  -webkit-backdrop-filter: saturate(150%) blur(18px); backdrop-filter: saturate(150%) blur(18px);
  border-top: 1px solid var(--rim);
}
.tab {
  flex: 1; max-width: 170px; min-height: 52px;
  display: grid; justify-items: center; align-content: center; gap: 2px;
  background: transparent; border: 0; border-radius: 12px; color: var(--haze-2);
  font-size: 12px; font-weight: 500; -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--moon); }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(2, 3, 6, 0.6); animation: fade 0.2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 600px; margin: 0 auto; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 20px calc(var(--safe-b) + 24px);
  background: var(--dusk); border: 1px solid var(--rim); border-bottom: 0;
  border-radius: 26px 26px 0 0;
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-grip { width: 38px; height: 5px; border-radius: 999px; background: var(--rim-2); margin: 4px auto 14px; }
.sheet h2 { font-size: 22px; margin: 0 0 16px; }
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  transform: translateX(-50%);
  max-width: calc(100% - 40px); padding: 11px 18px; border-radius: 999px;
  background: var(--moon); color: var(--night); font-weight: 600; font-size: 14.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: fade 0.2s ease;
}
.toast.alarm { background: var(--alarm); }

/* ---------- login ---------- */
.login .login-wrap { max-width: 380px; margin: 0 auto; padding: calc(var(--safe-t) + 12vh) 24px 40px; }
.login-moon svg { filter: drop-shadow(0 0 30px rgba(205, 214, 236, 0.18)); display: block; }
.login-title { font-size: 34px; line-height: 1.2; margin: 26px 0 4px; }
.login-sub { margin: 0 0 30px; color: var(--haze); }
.login-form .btn { margin-top: 22px; }

/* ---------- wide screens ---------- */
@media (min-width: 720px) {
  .view-title { font-size: 40px; }
  .tabbar { top: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- utilities (no inline styles: CSP blocks them) ---------- */
.m-0 { margin: 0 !important; }
.mt-12 { margin-top: 12px; } .mt-14 { margin-top: 14px; } .mt-16 { margin-top: 16px; }
.mt-18 { margin-top: 18px; } .mt-20 { margin-top: 20px; }
.mb-6 { margin-bottom: 6px !important; } .mb-16 { margin-bottom: 16px; } .mb-20 { margin-bottom: 20px; }
.min0 { min-width: 0; }
.fs-17 { font-size: 17px; } .fs-22 { font-size: 22px; }
.py-4 { padding-top: 4px; padding-bottom: 4px; }
.bt-0 { border-top: 0 !important; } .bb-0 { border-bottom: 0 !important; }
.moon-days-sm { font-size: 26px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
