/* Helm auth UI. Single stylesheet — strict CSP forbids inline styles.
 *
 * Organization:
 *   1. Resets
 *   2. Layout primitives (body, .auth-container, .row)
 *   3. Components (.brand, .phrase, .spinner, button variants)
 *   4. Forms (textarea, input, label)
 *   5. Typography (h1, p, code, a)
 *   6. Utilities (.muted, .small, .err, .ok, .warn, .center)
 */

/* --- 1. Resets --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* --- 2. Layout --- */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #e0e0e0;
  background: #121212;
  padding: 2rem;
  min-height: 100vh;
}

.auth-container {
  max-width: 500px;
  margin: 80px auto 2rem;
  padding: 2rem;
  background: #1e1e1e;
  border-radius: 4px;
  text-align: center;
}

.row { margin: 1rem 0; text-align: left; }

/* --- 3. Components --- */
.brand {
  display: inline-block;
  background: #2d4a3e;
  color: #4ade80;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 1rem;
  letter-spacing: 0.02em;
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
  cursor: default;
}

.brand::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(
    circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
    rgba(74, 222, 128, 0.4) 0%,
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.brand:hover::before { opacity: 1; }

.phrase {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 1.4rem;
  letter-spacing: 0.04em;
  padding: 1rem;
  background: #121212;
  border: 1px solid #4ade80;
  border-radius: 4px;
  color: #4ade80;
  margin: 1.25rem 0;
  text-align: center;
  word-break: break-word;
}

.qr-label {
  text-align: center;
  margin: 1.25rem 0 0.5rem;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  margin: 0.5rem 0 1.5rem;
}

.qr-wrap svg {
  /* segno emits a square SVG; the wrapper centers and bounds it. White
     quiet-zone padding is part of the SVG (border=2 in the encoder). */
  max-width: 240px;
  height: auto;
  border-radius: 4px;
}

.spinner {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  border: 2px solid #333;
  border-top-color: #4ade80;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  vertical-align: -0.15em;
  margin-right: 0.4em;
}
@keyframes spin { to { transform: rotate(360deg); } }

button {
  background: #3a3a3a;
  color: #fff;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 0.55rem 1.2rem;
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:hover { background: #4a4a4a; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: #4ade80;
  color: #0a1f14;
  border-color: #4ade80;
  font-weight: 600;
}
button.primary:hover { background: #6ee79a; border-color: #6ee79a; }
button.primary:disabled { background: #4ade80; opacity: 0.5; }

button.ghost {
  background: transparent;
  color: #888;
  border: 1px solid #444;
}
button.ghost:hover { background: #2a2a2a; color: #e0e0e0; }

/* --- 4. Forms --- */
label {
  display: block;
  margin-bottom: 0.4rem;
  color: #888;
  font-size: 0.85rem;
}

textarea, input[type="text"] {
  width: 100%;
  min-height: 4em;
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: inherit;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 3px;
  resize: vertical;
}
textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: #666;
}
textarea::placeholder, input::placeholder { color: #666; }

/* --- 5. Typography --- */
h1 {
  font-size: 1.4rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 1rem;
}

p { color: #888; margin-bottom: 1rem; }

code {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.85rem;
  background: #2a2a2a;
  color: #ccc;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

a { color: #e0e0e0; text-decoration: none; }
a:hover { color: #fff; text-decoration: underline; }

/* --- 6. Utilities --- */
.muted { color: #666; }
.small { font-size: 0.85rem; }
.err  { color: #f87171; }
.ok   { color: #4ade80; }
.warn { color: #ff9800; }

.row.center { text-align: center; }
.row.muted  { color: #666; }
.mt-2 { margin-top: 1.5rem; }

.inline-actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

/* --- 7. Admin layout (wider, table-friendly) --- */
.admin-shell {
  max-width: 1100px;
  margin: 0 auto;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  border-bottom: 1px solid #2a2a2a;
  padding: 0.75rem 0;
  margin-bottom: 2rem;
  font-size: 0.9rem;
}
.admin-nav .brand { margin: 0 1rem 0 0; }
.admin-nav a { color: #ccc; font-weight: 500; }
.admin-nav a.active { color: #4ade80; }
.admin-nav .spacer { flex: 1; }
.admin-nav .me {
  color: #888;
  font-size: 0.85rem;
}

.admin-section {
  background: #1e1e1e;
  padding: 1.5rem;
  border-radius: 4px;
  margin-bottom: 1.5rem;
}

.admin-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #ccc;
  margin: 0 0 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.stat {
  background: #121212;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 1rem;
}
.stat .label {
  color: #888;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat .value {
  font-size: 2rem;
  font-weight: 600;
  color: #fff;
  margin-top: 0.25rem;
}
.stat.warn .value { color: #ff9800; }
.stat.ok .value { color: #4ade80; }
.stat.muted .value { color: #888; }

table.admin {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.admin th, table.admin td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #2a2a2a;
}
table.admin th {
  color: #888;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
table.admin tr:hover td {
  background: #232323;
}
table.admin td.actions {
  text-align: right;
  white-space: nowrap;
}
table.admin td .pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid #444;
  color: #ccc;
}
table.admin td .pill.pending { color: #ff9800; border-color: #553a13; background: rgba(255,152,0,0.08); }
table.admin td .pill.approved { color: #4ade80; border-color: #1d3a25; background: rgba(74,222,128,0.08); }
table.admin td .pill.revoked  { color: #f87171; border-color: #5a1f1f; background: rgba(248,113,113,0.08); }

.pill.pending { color: #ff9800; border-color: #553a13; background: rgba(255,152,0,0.08); }
.pill.approved { color: #4ade80; border-color: #1d3a25; background: rgba(74,222,128,0.08); }
.pill.revoked  { color: #f87171; border-color: #5a1f1f; background: rgba(248,113,113,0.08); }
.pill.self     { color: #4ade80; border-color: #1d3a25; background: rgba(74,222,128,0.08); }

.code-xs { font-size: 0.75rem; }

.inline-form {
  display: inline;
  margin: 0;
}
.inline-form button {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}
button.danger {
  background: transparent;
  color: #f87171;
  border-color: #5a1f1f;
}
button.danger:hover {
  background: rgba(248,113,113,0.1);
  color: #fca5a5;
}

.field-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
}
.field-grid dt { color: #888; }
.field-grid dd { margin: 0; color: #ddd; word-break: break-all; }

.action-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.action-form select,
.action-form input[type="text"] {
  flex: 1;
  min-width: 200px;
  min-height: 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 3px;
  height: auto;
}

/* --- Home page --- */

/* Anchor-as-button — same look as <button.primary> but for /home's
   "Sign in" link. Anonymous visitors don't have a form to submit, only a
   link to follow. */
.btn {
  display: inline-block;
  padding: 0.55rem 1.2rem;
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  text-decoration: none;
  background: #3a3a3a;
  color: #fff;
  border: 1px solid #444;
  border-radius: 3px;
}
.btn:hover { background: #4a4a4a; }
.btn.primary {
  background: #4ade80;
  color: #0a1f14;
  border-color: #4ade80;
  font-weight: 600;
}
.btn.primary:hover { background: #6ee79a; border-color: #6ee79a; }

/* App cards: one per app the signed-in device holds a cap in. The whole
   card is the click target (anchor element); no nested interactive bits,
   so the keyboard tab order stays one stop per card. */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin: 0.5rem 0 1.5rem;
}
.app-card {
  display: block;
  padding: 0.85rem 1rem;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.1s, background 0.1s;
}
.app-card:hover {
  border-color: #4ade80;
  background: #2f2f2f;
}
.app-card-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: #e0e0e0;
  margin-bottom: 0.25rem;
}
.app-card-desc {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}
.app-card-caps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.app-card-caps code {
  font-size: 0.75rem;
  color: #888;
  background: #1f1f1f;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}

/* Admin pill — same visual language as the device-status pills, just a
   different accent so it reads as "role" not "state". */
.pill.admin {
  color: #4ade80;
  border-color: #1d3a25;
  background: rgba(74,222,128,0.08);
  margin-left: 0.4rem;
}
