/* ==========================================================================
   Certificate Manager -- hand-written stylesheet.

   No framework and no CDN on purpose: the board runs on an isolated LAN and
   must render correctly with zero internet access. Everything here is plain
   CSS with system fonts.
   ========================================================================== */

:root {
  --bg:            #f5f6f8;
  --surface:       #ffffff;
  --border:        #d8dce3;
  --text:          #1d2129;
  --text-muted:    #6b7280;
  --accent:        #1f5fa9;
  --accent-dark:   #17457a;
  --ok:            #1a7f47;
  --ok-bg:         #e6f4ec;
  --bad:           #b3261e;
  --bad-bg:        #fbeae9;
  --warn:          #8a5b00;
  --warn-bg:       #fdf3e0;
  --radius:        6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

code, .serial, pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92em;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

/* --- layout ------------------------------------------------------------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-name { font-weight: 600; }
.brand-zone {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.85em;
}
/* the public domain, shown beside the internal zone when one is configured */
.brand-zone-public { background: #e8eff8; color: var(--accent-dark); }

.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent); color: #fff; }
.nav-form { margin: 0 0 0 8px; }

.link-button {
  background: none;
  border: none;
  padding: 6px 8px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
}
.link-button:hover { color: var(--text); text-decoration: underline; }

.page { max-width: 1080px; margin: 0 auto; padding: 24px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

.footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px 32px;
  color: var(--text-muted);
  font-size: 0.88em;
}
.footer-sep { margin: 0 8px; }

/* --- cards and grid ----------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-narrow { max-width: 460px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

/* --- forms -------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field-inline label { display: inline; font-weight: 400; }

.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font: inherit;
}
.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.input-suffix { display: flex; align-items: center; gap: 8px; }
.suffix { color: var(--text-muted); white-space: nowrap; }

.hint { margin: 4px 0 0; color: var(--text-muted); font-size: 0.86em; }
.field-error { margin: 4px 0 0; color: var(--bad); font-size: 0.88em; }

.inline-form { display: inline; margin: 0; }

/* --- buttons ------------------------------------------------------------ */
.button {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: var(--bg); color: var(--text); }

.button-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.button-primary:hover { background: var(--accent-dark); color: #fff; }

.button-danger { color: var(--bad); border-color: #e3b7b4; }
.button-danger:hover { background: var(--bad-bg); color: var(--bad); }

.button-small { padding: 4px 9px; font-size: 0.86em; }

.button.is-loading {
  cursor: default;
  opacity: 0.7;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.button.is-loading::before {
  content: "";
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: button-spin 0.6s linear infinite;
}
@keyframes button-spin {
  to { transform: rotate(360deg); }
}

/* --- tables ------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.table th, .table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  background: var(--bg);
  font-size: 0.82em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }

.col-actions { white-space: nowrap; text-align: right; }
.detail { color: var(--text-muted); }
.serial { word-break: break-all; }

.stats { border-collapse: collapse; }
.stats th {
  text-align: left;
  font-weight: 400;
  color: var(--text-muted);
  padding: 3px 16px 3px 0;
}
.stats td { padding: 3px 0; font-weight: 600; }

.stat { margin: 0 0 12px; }
.stat-value { font-size: 1.7rem; font-weight: 600; margin-right: 6px; }

.warn { color: var(--warn); font-weight: 600; }

/* --- pills, flashes, misc ----------------------------------------------- */
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.pill-ok  { background: var(--ok-bg);  color: var(--ok); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
/* which CA issued a certificate */
.pill-issuer { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.pill-public { background: #e8eff8; color: var(--accent-dark); }

/* checkbox + label on one line, e.g. the public-certificate opt-in */
.field-check { display: flex; align-items: baseline; gap: 8px; }
.field-check label { font-weight: 500; }

.flashes { list-style: none; margin: 0 0 20px; padding: 0; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 8px;
}
.flash-success { background: var(--ok-bg);  border-color: #bfe2ce; color: var(--ok); }
.flash-error   { background: var(--bad-bg); border-color: #e9c3c0; color: var(--bad); }
.flash-warning { background: var(--warn-bg); border-color: #ecd7ab; color: var(--warn); }

.plain { list-style: none; margin: 0 0 12px; padding: 0; }
.plain li { padding: 3px 0; }

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

.pager { display: flex; align-items: center; gap: 12px; }

@media (max-width: 640px) {
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .col-actions { text-align: left; }
}
