/* Beantopia server panel — Polaris-style admin UI on the tokens in tokens.css.
   Patterns: Page → Banner → stat tiles → Card (IndexTable of projects) → Cards
   (traffic, resources, certificates, docker disk) · Sheet for project details ·
   Modal for confirmations · Toast for outcomes. */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-family: var(--p-font-family-sans);
  font-size: var(--p-font-size-body-md);
  line-height: var(--p-font-line-height-body);
  color: var(--p-color-text);
  background: var(--p-color-bg);
  -webkit-font-smoothing: antialiased;
}
body { margin: 0; min-height: 100vh; }
a { color: var(--p-color-text-link); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: var(--p-font-line-height-heading); }
:focus-visible { outline: 2px solid var(--p-color-border-focus); outline-offset: 2px; border-radius: var(--p-border-radius-100); }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.text-secondary { color: var(--p-color-text-secondary); }
.text-sm { font-size: var(--p-font-size-body-sm); }
.text-xs { font-size: var(--p-font-size-body-xs); }
.mono { font-family: var(--p-font-family-mono); font-size: var(--p-font-size-body-sm); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: var(--p-space-300); }
.stack--tight { gap: var(--p-space-100); }
.row { display: flex; align-items: center; gap: var(--p-space-200); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.nowrap { white-space: nowrap; }
p { margin: 0; }

/* ---------------------------------------------------------------- page */
.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--p-space-500) var(--p-space-400) var(--p-space-1200);
  display: flex;
  flex-direction: column;
  gap: var(--p-space-500);
}
.page__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--p-space-400); flex-wrap: wrap; }
.page__title { font-size: var(--p-font-size-heading-2xl); font-weight: var(--p-font-weight-bold); margin: 0; }
.page__subtitle { color: var(--p-color-text-secondary); margin: var(--p-space-100) 0 0; }
.page__actions { display: flex; gap: var(--p-space-200); align-items: center; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: var(--p-space-300); }
.brand__mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: var(--p-color-bg-inverse); display: grid; place-items: center;
}
.brand__mark::after { content: ''; width: 18px; height: 18px; border-radius: 50%; background: #22c55e; }
.app.is-refreshing .page > *:not(.page__header) { opacity: 0.6; transition: opacity var(--p-motion-duration-200); }
.updated { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-xs); }

/* ---------------------------------------------------------------- card */
.card {
  background: var(--p-color-bg-surface);
  border-radius: var(--p-border-radius-300);
  box-shadow: var(--p-shadow-200);
  border: 1px solid var(--p-color-border-secondary);
  min-width: 0;
}
.card__header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--p-space-300);
  padding: var(--p-space-400) var(--p-space-500);
  border-bottom: 1px solid var(--p-color-border-secondary);
  flex-wrap: wrap;
}
.card__title { font-size: var(--p-font-size-heading-lg); font-weight: var(--p-font-weight-semibold); margin: 0; }
.card__subtitle { margin: 2px 0 0; color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-sm); }
.card__section { padding: var(--p-space-400) var(--p-space-500); }
.card__section + .card__section { border-top: 1px solid var(--p-color-border-secondary); }
.card__section--flush { padding: 0; }
.card__section-title { font-size: var(--p-font-size-heading-sm); font-weight: var(--p-font-weight-semibold); margin: 0 0 var(--p-space-300); color: var(--p-color-text-secondary); text-transform: uppercase; letter-spacing: 0.02em; }

.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--p-space-400); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--p-space-400); }
.grid-2--even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-2--even { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }

/* ---------------------------------------------------------------- stat tiles */
.stat { padding: var(--p-space-400) var(--p-space-500); display: flex; flex-direction: column; gap: var(--p-space-200); }
.stat__label { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-sm); font-weight: var(--p-font-weight-medium); }
.stat__value { font-size: var(--p-font-size-heading-2xl); font-weight: var(--p-font-weight-semibold); line-height: 1.2; }
.stat__value small { font-size: var(--p-font-size-body-md); color: var(--p-color-text-secondary); font-weight: var(--p-font-weight-regular); margin-left: var(--p-space-100); }
.stat__sub { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-sm); }
.meter { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--viz-seq-250) 40%, var(--p-color-bg-surface)); overflow: hidden; }
.meter__fill { height: 100%; border-radius: 3px; background: var(--viz-seq-450); transition: width var(--p-motion-duration-300) var(--p-motion-ease); }
.meter--warning .meter__fill { background: var(--viz-status-warning); }
.meter--critical .meter__fill { background: var(--viz-status-critical); }

/* ---------------------------------------------------------------- banner */
.banner {
  display: flex; gap: var(--p-space-300); align-items: flex-start;
  padding: var(--p-space-300) var(--p-space-400);
  border-radius: var(--p-border-radius-200);
  border: 1px solid var(--p-color-border);
  background: var(--p-color-bg-surface);
}
.banner__icon { width: 20px; flex: none; text-align: center; font-size: 12px; line-height: 20px; }
.banner__content { flex: 1; min-width: 0; }
.banner__title { font-weight: var(--p-font-weight-semibold); margin: 0; }
.banner__body { margin: 2px 0 0; color: var(--p-color-text-secondary); }
.banner__actions { flex: none; }
.banner--info { background: var(--p-color-bg-fill-info-secondary); border-color: transparent; }
.banner--info .banner__icon { color: var(--p-color-text-info); }
.banner--success { background: var(--p-color-bg-fill-success-secondary); border-color: transparent; }
.banner--success .banner__icon { color: var(--p-color-text-success); }
.banner--warning { background: var(--p-color-bg-fill-warning-secondary); border-color: transparent; }
.banner--warning .banner__icon { color: var(--p-color-text-warning); }
.banner--critical { background: var(--p-color-bg-fill-critical-secondary); border-color: transparent; }
.banner--critical .banner__icon { color: var(--p-color-text-critical); }
.banner--warning .banner__body, .banner--critical .banner__body, .banner--success .banner__body, .banner--info .banner__body { color: var(--p-color-text); opacity: 0.85; }

/* ---------------------------------------------------------------- badge */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--p-border-radius-200);
  font-size: var(--p-font-size-body-xs); font-weight: var(--p-font-weight-medium); line-height: 16px;
  white-space: nowrap;
  background: var(--p-color-bg-fill-neutral-secondary); color: var(--p-color-text);
}
.badge__icon { font-size: 7px; line-height: 1; }
.badge--success { background: var(--p-color-bg-fill-success-secondary); color: var(--p-color-text-success); }
.badge--info { background: var(--p-color-bg-fill-info-secondary); color: var(--p-color-text-info); }
.badge--warning { background: var(--p-color-bg-fill-warning-secondary); color: var(--p-color-text-warning); }
.badge--critical { background: var(--p-color-bg-fill-critical-secondary); color: var(--p-color-text-critical); }
.badge--caution { background: var(--p-color-bg-fill-caution-secondary); color: var(--p-color-text-caution); }
.badge--magic { background: var(--p-color-bg-fill-magic-secondary); color: var(--p-color-text-magic); }
.badge--neutral .badge__icon { opacity: 0.6; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 12px;
  border-radius: var(--p-border-radius-200);
  border: 1px solid var(--p-color-border);
  background: var(--p-color-bg-surface); color: var(--p-color-text);
  font-weight: var(--p-font-weight-medium);
  cursor: pointer; box-shadow: var(--p-shadow-100); white-space: nowrap;
  transition: background var(--p-motion-duration-150) var(--p-motion-ease), border-color var(--p-motion-duration-150);
}
.btn:hover { background: var(--p-color-bg-surface-hover); }
.btn:active { background: var(--p-color-bg-surface-active); }
.btn:disabled { cursor: not-allowed; color: var(--p-color-text-disabled); box-shadow: none; background: var(--p-color-bg-surface); }
.btn--primary { background: var(--p-color-bg-fill-brand); border-color: transparent; color: var(--p-color-text-brand-on-bg-fill); }
.btn--primary:hover { background: var(--p-color-bg-fill-brand-hover); }
.btn--primary:active { background: var(--p-color-bg-fill-brand-active); }
.btn--primary:disabled { background: var(--p-color-bg-fill-neutral-secondary); color: var(--p-color-text-disabled); }
.btn--primary.btn--destructive { background: var(--p-color-bg-fill-critical); color: var(--p-color-text-critical-on-bg-fill); }
.btn--primary.btn--destructive:hover { background: var(--p-color-bg-fill-critical-hover); }
.btn--secondary.btn--destructive { color: var(--p-color-text-critical); }
.btn--plain { border-color: transparent; background: transparent; box-shadow: none; color: var(--p-color-text-link); padding: 6px 8px; }
.btn--plain:hover { background: var(--p-color-bg-surface-hover); }
.btn--plain.btn--destructive { color: var(--p-color-text-critical); }
.btn--sm { min-height: 28px; padding: 2px 8px; font-size: var(--p-font-size-body-sm); }
.btn.is-loading { opacity: 0.7; }
.btn-group { display: inline-flex; gap: var(--p-space-200); flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--p-color-border); border-radius: var(--p-border-radius-200); overflow: hidden; background: var(--p-color-bg-surface); }
.segmented button { border: 0; background: transparent; padding: 4px 12px; min-height: 32px; cursor: pointer; font-weight: var(--p-font-weight-medium); }
.segmented button + button { border-left: 1px solid var(--p-color-border); }
.segmented button[aria-pressed="true"] { background: var(--p-color-bg-inverse); color: var(--p-color-bg-surface); }
.link-btn {
  background: none; border: 0; padding: 0; color: var(--p-color-text);
  font-weight: var(--p-font-weight-semibold); font-size: var(--p-font-size-body-lg);
  cursor: pointer; text-align: left;
}
.link-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: var(--p-font-size-body-xs); color: var(--p-color-text-secondary);
  font-weight: var(--p-font-weight-medium); padding: var(--p-space-200) var(--p-space-300);
  border-bottom: 1px solid var(--p-color-border); white-space: nowrap;
}
.table td { padding: var(--p-space-300); border-bottom: 1px solid var(--p-color-border-secondary); vertical-align: top; }
.table tbody tr:hover { background: var(--p-color-bg-surface-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table th.num { text-align: right; }
.table--compact td, .table--compact th { padding: 4px 8px; font-size: var(--p-font-size-body-sm); }
.cell-sub { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-sm); margin-top: 2px; max-width: 360px; }
.url-list { display: flex; flex-direction: column; gap: 2px; }
.url-list a { text-decoration: none; white-space: nowrap; }
.url-list a:hover { text-decoration: underline; }
.url-list .ext { color: var(--p-color-icon-secondary); font-size: 10px; margin-left: 3px; }
.url-list .url-host { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-xs); }
.cell-actions { display: flex; gap: var(--p-space-200); flex-wrap: wrap; justify-content: flex-end; }
.spark { display: block; }
.cell-spark { display: flex; align-items: center; gap: var(--p-space-300); }
@media (max-width: 860px) {
  .table--projects thead { display: none; }
  .table--projects tbody tr { display: block; padding: var(--p-space-300) 0; border-bottom: 1px solid var(--p-color-border); }
  .table--projects td { display: block; border: 0; padding: 4px var(--p-space-300); }
  .table--projects td[data-label]::before { content: attr(data-label); display: block; font-size: var(--p-font-size-body-xs); color: var(--p-color-text-secondary); }
  .table--projects td.num { text-align: left; }
  .cell-actions { justify-content: flex-start; }
}

/* ---------------------------------------------------------------- horizontal bars */
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 1.1fr) 3fr 64px; align-items: center; gap: var(--p-space-300); }
.hbar__label { display: flex; flex-direction: column; min-width: 0; }
.hbar__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--p-font-size-body-sm); }
.hbar__sub { font-size: var(--p-font-size-body-xs); color: var(--p-color-text-secondary); }
.hbar__track { height: 12px; position: relative; }
.hbar__fill { height: 100%; border-radius: 0 4px 4px 0; transition: width var(--p-motion-duration-300) var(--p-motion-ease); }
.hbar__value { text-align: right; font-variant-numeric: tabular-nums; font-size: var(--p-font-size-body-sm); }

/* ---------------------------------------------------------------- charts */
.viz { margin: 0; position: relative; min-width: 0; }
.viz__plot { position: relative; }
.viz__svg { width: 100%; height: auto; display: block; background: var(--viz-surface); border-radius: var(--p-border-radius-100); }
.viz__tick { font-size: 11px; fill: var(--viz-muted); font-family: var(--p-font-family-sans); font-variant-numeric: tabular-nums; }
.viz__bar { display: flex; justify-content: space-between; align-items: center; gap: var(--p-space-300); margin-bottom: var(--p-space-200); flex-wrap: wrap; }
.viz__bar > .btn { margin-left: auto; }
.viz__legend { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.legend__item {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none;
  padding: 4px; border-radius: var(--p-border-radius-100); cursor: pointer;
  color: var(--p-color-text); font-size: var(--p-font-size-body-sm); min-height: 28px;
}
.legend__item:hover { background: var(--p-color-bg-surface-hover); }
.legend__item.is-off { opacity: 0.45; text-decoration: line-through; }
.legend__swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend__total { color: var(--p-color-text-secondary); font-variant-numeric: tabular-nums; }
.viz__tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--p-color-bg-surface); border: 1px solid var(--p-color-border);
  border-radius: var(--p-border-radius-200); box-shadow: var(--p-shadow-300);
  padding: 8px 10px; min-width: 180px; max-width: 240px; font-size: var(--p-font-size-body-sm);
}
.viz__tip-title { color: var(--p-color-text-secondary); }
.viz__tip-total { font-weight: var(--p-font-weight-semibold); margin-bottom: 4px; }
.viz__tip-row { display: grid; grid-template-columns: 12px auto 1fr; gap: 6px; align-items: center; }
.viz__tip-row span:last-child { color: var(--p-color-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viz__key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.viz__table { margin-top: var(--p-space-200); overflow-x: auto; }

/* ---------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field__label { font-weight: var(--p-font-weight-medium); font-size: var(--p-font-size-body-sm); }
.field__help { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-xs); }
.input, .select, .textarea {
  width: 100%; min-height: 36px; padding: 6px 10px;
  border: 1px solid var(--p-color-border-inverse); border-radius: var(--p-border-radius-200);
  background: var(--p-color-bg-surface); color: var(--p-color-text);
}
.textarea { min-height: 80px; resize: vertical; font-family: var(--p-font-family-mono); font-size: var(--p-font-size-body-sm); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline-offset: 0; }
.form-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--p-space-300); }
@media (max-width: 600px) { .form-group { grid-template-columns: minmax(0, 1fr); } }
.checkbox { display: flex; gap: 8px; align-items: center; min-height: 36px; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; margin: 0; }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--p-space-500); }
.login__card { width: 100%; max-width: 400px; padding: var(--p-space-600); display: flex; flex-direction: column; gap: var(--p-space-400); }
.login__title { margin: 0; font-size: var(--p-font-size-heading-xl); }

/* ---------------------------------------------------------------- modal & sheet */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: grid; place-items: center; z-index: 50; padding: var(--p-space-400); }
.modal {
  background: var(--p-color-bg-surface); border-radius: var(--p-border-radius-300); box-shadow: var(--p-shadow-600);
  width: 100%; max-width: 480px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal--large { max-width: 760px; }
.modal__header { display: flex; justify-content: space-between; align-items: center; gap: var(--p-space-300); padding: var(--p-space-400) var(--p-space-500); border-bottom: 1px solid var(--p-color-border-secondary); }
.modal__title { margin: 0; font-size: var(--p-font-size-heading-lg); }
.modal__body { padding: var(--p-space-500); overflow: auto; }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--p-space-200); padding: var(--p-space-300) var(--p-space-500); border-top: 1px solid var(--p-color-border-secondary); }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 40; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(780px, 100%);
  background: var(--p-color-bg); box-shadow: var(--p-shadow-600); z-index: 41;
  display: flex; flex-direction: column;
  animation: sheet-in var(--p-motion-duration-300) var(--p-motion-ease);
}
@keyframes sheet-in { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet__header {
  background: var(--p-color-bg-surface); padding: var(--p-space-400) var(--p-space-500);
  border-bottom: 1px solid var(--p-color-border);
  display: flex; justify-content: space-between; gap: var(--p-space-300); align-items: flex-start; flex-wrap: wrap;
}
.sheet__title { margin: 0; font-size: var(--p-font-size-heading-xl); }
.sheet__body { overflow: auto; padding: var(--p-space-400) var(--p-space-500); display: flex; flex-direction: column; gap: var(--p-space-400); }

/* ---------------------------------------------------------------- toast */
.toast-region {
  position: fixed; bottom: var(--p-space-500); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(520px, calc(100% - 32px));
}
.toast {
  display: flex; align-items: center; gap: var(--p-space-300);
  background: var(--p-color-bg-inverse); color: var(--p-color-bg-surface);
  padding: 10px 8px 10px 16px; border-radius: var(--p-border-radius-200); box-shadow: var(--p-shadow-300);
  animation: sheet-in var(--p-motion-duration-200) var(--p-motion-ease);
}
.toast .btn--plain { color: inherit; }
.toast--critical { background: var(--p-color-bg-fill-critical); color: var(--p-color-text-critical-on-bg-fill); }
.toast--success { box-shadow: inset 4px 0 0 var(--viz-status-good), var(--p-shadow-300); }
.toast--warning { box-shadow: inset 4px 0 0 var(--viz-status-warning), var(--p-shadow-300); }
.toast__text { flex: 1; }

/* ---------------------------------------------------------------- misc */
.logbox {
  background: var(--p-color-bg-inverse); color: var(--p-color-bg-surface);
  font-family: var(--p-font-family-mono); font-size: 11.5px; line-height: 1.5;
  padding: var(--p-space-300); border-radius: var(--p-border-radius-200);
  max-height: 380px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0;
}
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; font-size: var(--p-font-size-body-sm); margin: 0; }
.kv dt { color: var(--p-color-text-secondary); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--p-space-300); }
.mini { padding: var(--p-space-300); background: var(--p-color-bg-surface-secondary); border-radius: var(--p-border-radius-200); }
.mini__label { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-xs); }
.mini__value { font-size: var(--p-font-size-heading-xl); font-weight: var(--p-font-weight-semibold); }
.mini__sub { color: var(--p-color-text-secondary); font-size: var(--p-font-size-body-xs); }
.empty { text-align: center; padding: var(--p-space-800); color: var(--p-color-text-secondary); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot--success { background: var(--viz-status-good); }
.dot--warning { background: var(--viz-status-warning); }
.dot--critical { background: var(--viz-status-critical); }
.dot--neutral { background: var(--viz-other); }
.note { font-size: var(--p-font-size-body-sm); color: var(--p-color-text-secondary); }
.divider { border: 0; border-top: 1px solid var(--p-color-border-secondary); margin: 0; }
