:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --brand: #0b7a75;
  --brand-dark: #075f5a;
  --danger: #c2410c;
  --warn: #b7791f;
  --ok: #15803d;
  --blue: #2563eb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(11,122,117,.08), rgba(11,122,117,0)),
    var(--bg);
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, .08);
}

.login-box h1 { margin: 0 0 8px; font-size: 24px; }
.login-box p { margin: 0 0 24px; color: var(--muted); }

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

.sidebar {
  background: #111827;
  color: white;
  padding: 20px 14px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  padding: 0 10px 18px;
}

.nav button {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 0 12px;
  margin-bottom: 4px;
}

.nav button.active, .nav button:hover {
  background: rgba(255,255,255,.1);
  color: white;
}

.main { min-width: 0; }
.topbar {
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.content { padding: 24px; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-title h2 { margin: 0; font-size: 22px; }

.grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.stat, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat { padding: 18px; }
.stat strong { display: block; font-size: 28px; margin-bottom: 4px; }
.stat span { color: var(--muted); }

.panel { padding: 18px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 17px; }
.panel.narrow { max-width: 620px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid.single { grid-template-columns: 1fr; }

.field { display: grid; gap: 6px; }
.field label { color: #344054; font-size: 13px; font-weight: 600; }
.field small { display: block; line-height: 1.4; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: white;
}
.field textarea { min-height: 84px; resize: vertical; }
.certificate-picker {
  position: relative;
}
.certificate-picker-button {
  width: 100%;
  min-height: 41px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 34px 10px 11px;
  background: white;
  color: var(--text);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.certificate-picker-button::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 17px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #667085;
  pointer-events: none;
}
.certificate-picker-menu {
  position: absolute;
  z-index: 35;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: 0 14px 35px rgba(15, 23, 42, .14);
}
.certificate-picker-menu input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  margin-bottom: 8px;
}
.certificate-picker-options {
  max-height: 260px;
  overflow: auto;
}
.certificate-picker-option {
  width: 100%;
  display: grid;
  gap: 3px;
  border: 0;
  border-radius: 6px;
  padding: 9px 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.certificate-picker-option:hover {
  background: #f2f4f7;
}
.certificate-picker-option span,
.certificate-picker-empty {
  color: var(--muted);
  font-size: 12px;
}
.certificate-picker-empty {
  padding: 10px;
}
.checkline {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #344054;
  font-size: 14px;
}
.checkline input { width: 16px; height: 16px; }
.ipa-inspect-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}
.ipa-inspect-status {
  grid-column: 1 / -1;
  color: #344054;
  font-weight: 700;
}
.ipa-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.ipa-meta-icon {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
}
.ipa-meta-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ipa-progress {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}
.ipa-progress[hidden] { display: none; }
.ipa-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #344054;
  font-size: 13px;
}
.ipa-progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}
.ipa-progress-track div {
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width .2s ease;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px auto auto;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
}
.filter-bar input, .filter-bar select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: white;
}
.btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  border-radius: 6px;
  height: 36px;
  padding: 0 12px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: white; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #fed7aa; background: #fff7ed; }
.btn.small { height: 30px; padding: 0 9px; font-size: 13px; }

.table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
th { background: #f8fafc; color: #475467; font-weight: 700; }
tr:last-child td { border-bottom: 0; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .35);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 22px 60px rgba(15, 23, 42, .18);
}
.modal-header, .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-header h3, .modal-head h3 { margin: 0; font-size: 17px; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: var(--blue);
}
.tag.enable, .tag.used { background: #dcfce7; color: var(--ok); }
.tag.unused { background: #dbeafe; color: var(--blue); }
.tag.frozen { background: #fef3c7; color: var(--warn); }
.tag.banned, .tag.disable { background: #fee2e2; color: #b91c1c; }
.tag.expired { background: #e5e7eb; color: #4b5563; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.preline { white-space: pre-line; max-width: 360px; }
.ipa-links {
  flex-basis: 100%;
  display: flex;
  gap: 10px;
  font-size: 12px;
}
.ipa-links a { color: var(--brand); text-decoration: none; }
.ipa-links a:hover { text-decoration: underline; }
.ipa-qr {
  flex-basis: 100%;
  width: 150px;
  padding-top: 4px;
  text-align: center;
}
.ipa-qr img {
  width: 132px;
  height: 132px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: white;
}
.ipa-qr .muted { font-size: 12px; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  background: #111827;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: 0 14px 35px rgba(0,0,0,.25);
  display: none;
  z-index: 20;
}
.toast.show { display: block; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, .42);
}
.modal-backdrop[hidden] { display: none; }
.ipa-success-modal {
  position: relative;
  width: min(420px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: #f3f4f6;
  color: #344054;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.ipa-success-head {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding-top: 8px;
  text-align: center;
}
.ipa-success-icon {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}
.ipa-success-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ipa-success-head h3 {
  margin: 4px 0 0;
  font-size: 20px;
}
.ipa-success-head p {
  margin: 0;
  color: var(--muted);
}
.ipa-success-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 20px;
}
.ipa-success-qr {
  margin-top: 16px;
  text-align: center;
}
.ipa-success-qr img {
  width: 210px;
  height: 210px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.floating-progress {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  width: min(360px, calc(100vw - 40px));
  display: grid;
  gap: 9px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .18);
}
.floating-progress[hidden] { display: none; }
.floating-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #344054;
  font-size: 13px;
}
.floating-progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}
.floating-progress-track div {
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width .2s ease;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; }
  .nav { display: flex; gap: 6px; overflow-x: auto; }
  .nav button { width: auto; white-space: nowrap; margin: 0; }
  .grid, .form-grid, .ipa-inspect-panel { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr; }
}
