:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --line: #d7dee8;
  --text: #18202a;
  --muted: #5f6d7c;
  --primary: #176b87;
  --primary-dark: #0f4f65;
  --success: #1b7a4b;
  --warning: #a66a00;
  --danger: #b42318;
  --soft-blue: #e8f3f7;
  --soft-green: #e9f6ef;
  --soft-red: #fbecea;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

.app-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 68px;
  padding: 14px 24px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  font-weight: 720;
}

h2 {
  font-size: 18px;
  font-weight: 700;
}

h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.app-header p {
  color: var(--muted);
  margin-top: 2px;
}

main {
  margin: 0 auto;
  max-width: 1180px;
  padding: 20px;
}

[hidden] {
  display: none !important;
}

.auth-panel {
  background: #fff7e6;
  border: 1px solid #e6c67a;
  border-radius: 6px;
  margin-bottom: 14px;
  padding: 12px;
}

.auth-panel form {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.status-line {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: 8px;
  white-space: nowrap;
}

.dot {
  background: var(--warning);
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.dot.ok {
  background: var(--success);
}

.dot.bad {
  background: var(--danger);
}

.stats-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 74px;
  padding: 13px 14px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 8px;
}

.stat strong {
  font-size: 24px;
  overflow-wrap: anywhere;
}

.tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
  min-height: 42px;
  padding: 0 14px;
}

.tab.active {
  border-bottom-color: var(--primary);
  color: var(--text);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbar-form,
.stack-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
}

.toolbar-form {
  align-items: end;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
}

.stack-form {
  grid-template-columns: 1fr;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 650;
  gap: 5px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #c4cfda;
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 8px 9px;
  width: 100%;
}

textarea {
  resize: vertical;
}

button {
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 38px;
  padding: 8px 12px;
  white-space: nowrap;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #fff;
  border-color: #b9c5d0;
  color: var(--text);
}

button.secondary:hover {
  background: #eef3f6;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.small {
  min-height: 32px;
  padding: 5px 9px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
}

.table-wrap.tight {
  max-height: 280px;
}

table {
  border-collapse: collapse;
  min-width: 720px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f9fbfd;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.outline-panel {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
}

.outline-panel h3 {
  margin-bottom: 4px;
}

.key-output,
.json-output {
  background: #111827;
  border-radius: 6px;
  color: #e5edf5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.key-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.key-output.empty {
  background: #f9fbfd;
  border: 1px dashed #b9c5d0;
  color: var(--muted);
}

.share-card {
  display: none;
}

.share-card-inner {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 16px auto;
  max-width: 680px;
  padding: 28px;
}

.card-brand {
  color: var(--primary);
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 8px;
}

.card-help,
.card-footnote {
  color: var(--muted);
  margin: 10px 0;
}

#shareKeyText {
  background: #f7fafc;
  border: 1px dashed #9fb0bf;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  line-height: 1.45;
  margin: 18px 0;
  overflow-wrap: anywhere;
  padding: 16px;
  white-space: pre-wrap;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  padding: 5px 8px;
}

.badge.pending {
  background: #fff5df;
  color: var(--warning);
}

.badge.approved,
.badge.active {
  background: var(--soft-green);
  color: var(--success);
}

.badge.revoked,
.badge.deleted,
.badge.disabled {
  background: var(--soft-red);
  color: var(--danger);
}

.badge.standby {
  background: var(--soft-blue);
  color: var(--primary);
}

.muted {
  color: var(--muted);
}

.toast {
  background: #18202a;
  border-radius: 6px;
  bottom: 18px;
  color: white;
  left: 50%;
  opacity: 0;
  padding: 10px 13px;
  pointer-events: none;
  position: fixed;
  transform: translateX(-50%) translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 860px) {
  .app-header {
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
  }

  main {
    padding: 14px;
  }

  .stats-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .toolbar-form {
    grid-template-columns: 1fr;
  }

  .auth-panel form,
  .outline-panel {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .outline-panel {
    display: grid;
  }

  .tabs {
    overflow-x: auto;
  }
}

@media print {
  body > header,
  body > main,
  .toast {
    display: none !important;
  }

  #shareCard {
    display: block !important;
  }

  .share-card-inner {
    border: 0;
    margin: 0;
    max-width: none;
    padding: 0;
  }
}
