/* Providence UI — vanilla CSS, no build step.
 * Light palette on :root; dark overrides under prefers-color-scheme,
 * guarded so a future explicit toggle could win (none is implemented yet,
 * the system only follows the OS setting per the mission brief). */

:root {
  --bg: #f5f6f8;
  --bg-raised: #ffffff;
  --bg-sunken: #ecedf1;
  --border: #d8dbe1;
  --text: #1b1e24;
  --text-muted: #5b6270;
  --text-faint: #8a909c;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --accent-muted: #e8eefe;
  --danger: #c0362c;
  --danger-muted: #fbe9e7;
  --warn: #9a6a00;
  --warn-muted: #fff3d6;
  --ok: #1a7f4b;
  --ok-muted: #e3f6ec;
  /* Used only for power_targets.state = "unreachable" (DESIGN.md §13.5): a
   * DELIBERATELY different hue from --danger, not a shade of it — a boot
   * failure (wake_failed/shutdown_failed) means Providence tried and got
   * no confirmation; unreachable means the BMC itself never answered, so
   * Providence could not even attempt anything. Same color would visually
   * collapse two states the mission requires kept distinct at a glance. */
  --unreachable: #7c3aed;
  --unreachable-muted: #efe6fd;
  --focus-ring: #2f6fed;
  --shadow: 0 1px 2px rgba(20, 22, 30, 0.06), 0 1px 8px rgba(20, 22, 30, 0.05);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --bg-raised: #1c1f26;
    --bg-sunken: #101216;
    --border: #2c3038;
    --text: #e7e9ee;
    --text-muted: #a3a9b5;
    --text-faint: #6f7684;
    --accent: #6d9bff;
    --accent-text: #0c1220;
    --accent-muted: #1b2740;
    --danger: #ff8a80;
    --danger-muted: #3a1f1d;
    --warn: #f5c542;
    --warn-muted: #3a2f0d;
    --ok: #6fd6a0;
    --ok-muted: #133024;
    --unreachable: #b48cff;
    --unreachable-muted: #291f42;
    --focus-ring: #6d9bff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}
main { display: block; max-width: 100%; overflow-x: hidden; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); }
code, pre { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --- layout shell -------------------------------------------------- */

.topnav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.topnav__brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  margin-right: 0.5rem;
}
.topnav__links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  flex-wrap: wrap;
}
.topnav__links a {
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
}
.topnav__links a:hover { background: var(--bg-sunken); color: var(--text); }
.topnav__links a[aria-current="page"] {
  background: var(--accent-muted);
  color: var(--accent);
  font-weight: 600;
}
.topnav__user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.topnav__user .role-badge { text-transform: capitalize; }

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-header p { color: var(--text-muted); margin: 0.15rem 0 0; }

/* --- buttons --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { background: var(--bg-sunken); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { background: var(--danger-muted); border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 0.28rem 0.6rem; font-size: 0.82rem; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-sunken); }

/* --- forms ------------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.85rem; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field input[type="datetime-local"],
.field select,
.field textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.checkbox-field { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; }
.checkbox-field label { font-weight: 500; color: var(--text); }
.form-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.hint { font-size: 0.8rem; color: var(--text-faint); }
.form-error {
  background: var(--danger-muted); color: var(--danger); border-radius: var(--radius);
  padding: 0.5rem 0.7rem; font-size: 0.88rem; margin-bottom: 0.75rem;
}
/* DESIGN.md §13.5 `unreachable`: a distinct color from the default
 * (danger-red) form-error, kept in its own selector rather than folded
 * into .form-error so a plain validation error never accidentally picks
 * up this color by a shared-class coincidence. */
.form-error--unreachable { background: var(--unreachable-muted); color: var(--unreachable); }

/* --- cards / lists ------------------------------------------------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.server-card__meta { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.15rem; }
.group-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.4rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.group-row:first-of-type { border-top: none; }
.group-row__name { font-weight: 600; text-decoration: none; color: var(--text); }
.group-row__name:hover { color: var(--accent); }
.group-row__spacer { flex: 1; }
.group-row__meta { font-size: 0.8rem; color: var(--text-faint); }

.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* --- badges & tags --------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }
.badge-running { background: var(--ok-muted); color: var(--ok); }
.badge-stopped { background: var(--bg-sunken); color: var(--text-faint); }
.badge-starting, .badge-stopping { background: var(--warn-muted); color: var(--warn); }
.badge-online { background: var(--ok-muted); color: var(--ok); }
.badge-offline { background: var(--bg-sunken); color: var(--text-faint); }
.badge-revoked { background: var(--danger-muted); color: var(--danger); }

/* --- PowerTarget badges (DESIGN.md §13) -------------------------------- */

.badge-off { background: var(--bg-sunken); color: var(--text-faint); }
.badge-on { background: var(--ok-muted); color: var(--ok); }
.badge-waking, .badge-wake_sent, .badge-booting, .badge-stopping { background: var(--warn-muted); color: var(--warn); }
/* wake_failed/shutdown_failed: Providence tried and got no confirmation —
 * danger red. unreachable: the BMC itself never answered — a DIFFERENT
 * color (--unreachable, not a shade of --danger) so the two read as
 * distinct at a glance, not as "two flavors of the same failure". */
.badge-wake_failed, .badge-shutdown_failed { background: var(--danger-muted); color: var(--danger); }
.badge-unreachable { background: var(--unreachable-muted); color: var(--unreachable); }
.badge-mechanism-redfish { background: var(--accent-muted); color: var(--accent); }
.badge-mechanism-wol { background: var(--bg-sunken); color: var(--text-muted); }
.badge-verified { background: var(--ok-muted); color: var(--ok); }
.badge-risk { background: var(--warn-muted); color: var(--warn); font-weight: 700; }
.badge-maintenance { background: var(--warn-muted); color: var(--warn); }
.badge-public-wake { background: var(--accent-muted); color: var(--accent); }

/* --- dependency tree / boot progress ------------------------------------ */

/* Applied directly to the <ol>/<ul> element (views/powerTargetDetail.js,
 * components/powerActions.js), not a wrapper — so the rule targets
 * `.dep-tree` itself, not a `.dep-tree ul` descendant. */
.dep-tree {
  list-style: none; font-size: 0.9rem;
  margin: 0.25rem 0 0; padding-left: 1.25rem; border-left: 1px dashed var(--border);
}
.dep-tree li { margin: 0.25rem 0; }
.dep-tree__self { font-weight: 700; }

.boot-steps { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.boot-step {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.65rem; border-radius: 999px; font-size: 0.8rem;
  border: 1px solid var(--border); color: var(--text-faint); background: var(--bg-sunken);
}
.boot-step--done { color: var(--ok); border-color: var(--ok); background: var(--ok-muted); }
.boot-step--current { color: var(--accent); border-color: var(--accent); background: var(--accent-muted); font-weight: 700; }
.boot-step--alert { color: var(--danger); border-color: var(--danger); background: var(--danger-muted); font-weight: 700; }

.quota-meter {
  height: 6px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; margin-top: 0.3rem;
  border: 1px solid var(--border);
}
.quota-meter__fill { height: 100%; width: 0; background: var(--accent); }
.quota-meter__fill--warn { background: var(--warn); }
.quota-meter__fill--danger { background: var(--danger); }
.quota-meter__fill--w0 { width: 0%; }
.quota-meter__fill--w10 { width: 10%; }
.quota-meter__fill--w20 { width: 20%; }
.quota-meter__fill--w30 { width: 30%; }
.quota-meter__fill--w40 { width: 40%; }
.quota-meter__fill--w50 { width: 50%; }
.quota-meter__fill--w60 { width: 60%; }
.quota-meter__fill--w70 { width: 70%; }
.quota-meter__fill--w80 { width: 80%; }
.quota-meter__fill--w90 { width: 90%; }
.quota-meter__fill--w100 { width: 100%; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 0.78rem;
  border: 1px solid var(--border);
}
.tag-chip button {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.9em;
  padding: 0;
  line-height: 1;
}
.tag-list { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* --- tables ------------------------------------------------------------ */

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-raised); }
table { border-collapse: collapse; width: 100%; min-width: 560px; }
th, td { text-align: left; padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tbody tr:last-child td { border-bottom: none; }
td.mono, code.mono { font-family: var(--mono); font-size: 0.82rem; word-break: break-all; }

/* --- tabs --------------------------------------------------------------- */

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button {
  font: inherit;
  border: none;
  background: none;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* --- dialog / modal ------------------------------------------------------ */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--bg-raised);
  color: var(--text);
  max-width: 480px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 12, 16, 0.5); }
.dialog-body { padding: 1.1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.secret-reveal {
  background: var(--warn-muted);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0.75rem 0;
}
.secret-reveal__label { font-size: 0.8rem; font-weight: 700; color: var(--warn); margin-bottom: 0.35rem; }
.secret-reveal__value {
  display: block;
  font-family: var(--mono);
  font-size: 0.85rem;
  word-break: break-all;
  user-select: all;
  background: var(--bg-sunken);
  padding: 0.5rem;
  border-radius: var(--radius);
}

/* --- toasts ------------------------------------------------------------- */

#toast-root {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  width: min(420px, calc(100% - 2rem));
}
.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-success { border-color: var(--ok); color: var(--ok); }

/* --- login screen -------------------------------------------------------- */

.login-wrap {
  min-height: calc(100vh - 3.2rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { text-align: center; }
.login-card__hint { text-align: center; margin-top: 0.75rem; }

/* --- resolved policy grid ------------------------------------------------- */

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}
.kv-grid dt { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.kv-grid dd { margin: 0.15rem 0 0; font-weight: 600; }

@media (max-width: 560px) {
  .page { padding: 1rem 0.75rem 3rem; }
  .topnav { padding: 0.5rem 0.75rem; }
}
