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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg-strong);
  font-size: var(--text-13);
  font-weight: 520;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.btn:hover {
  background: var(--control);
  border-color: var(--rule-strong);
}

.btn:active {
  background: var(--rule);
}

.btn[disabled],
.btn[aria-disabled="true"] {
  color: var(--fg-faint);
  background: var(--bg);
  border-color: var(--rule);
  cursor: not-allowed;
}

.btn-primary {
  background: var(--fg-strong);
  border-color: var(--fg-strong);
  color: var(--bg);
}

.btn-primary:hover {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.btn-primary:active {
  background: var(--fg-secondary);
  border-color: var(--fg-secondary);
}

.btn-primary[disabled] {
  background: var(--rule);
  border-color: var(--rule);
  color: var(--fg-faint);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--fg-secondary);
}

.btn-quiet:hover {
  background: var(--control);
  border-color: transparent;
  color: var(--fg-strong);
}

.btn-danger {
  color: var(--state-bad);
  border-color: color-mix(in oklab, var(--state-bad) 34%, var(--rule));
}

.btn-danger:hover {
  background: color-mix(in oklab, var(--state-bad) 10%, transparent);
  border-color: var(--state-bad);
}

.btn-lg {
  height: 40px;
  padding: 0 var(--space-5);
  font-size: var(--text-14);
}

.btn-sm {
  height: 26px;
  padding: 0 var(--space-2);
  font-size: var(--text-12);
}

.btn-icon {
  width: 32px;
  padding: 0;
  color: var(--fg-muted);
}

.btn-icon:hover {
  color: var(--fg-strong);
}

.btn-block {
  width: 100%;
}

.btn .icon {
  opacity: 0.85;
}

.link {
  color: var(--fg-strong);
  font-weight: 520;
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
}

.link-quiet {
  color: var(--fg-muted);
  text-decoration: none;
}

.link-quiet:hover {
  color: var(--fg-strong);
}

/* Inside a table the row itself is the affordance, so the underline waits for
   hover rather than striping every cell in the first column. */
table.data .link {
  text-decoration: none;
}

table.data .link:hover {
  text-decoration: underline;
  text-decoration-color: currentColor;
}

.stack > .btn:not(.btn-block),
.stack > form > .btn:not(.btn-block) {
  justify-self: start;
}

/* Chrome paints its own field background over autofilled inputs, which lands as
   a light block in a dark theme. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--fg-strong);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--fg-strong);
}

/* ----------------------------------------------------------------- fields */

.field {
  display: grid;
  gap: var(--space-2);
}

.field > span,
.field > label {
  font-size: var(--text-12);
  font-weight: 540;
  color: var(--fg-secondary);
}

.field .hint {
  font-size: var(--text-12);
  color: var(--fg-muted);
}

/* Matched by exclusion rather than by listing types, because an input with no
   type attribute is still a text field and would otherwise ship unstyled. */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not(
    [type="submit"]
  ),
select,
textarea {
  width: 100%;
  min-height: 34px;
  padding: 7px var(--space-3);
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  color: var(--fg-strong);
  font-size: var(--text-13);
  transition: border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

textarea {
  padding: var(--space-3);
  resize: vertical;
  line-height: 1.6;
}

input::placeholder,
textarea::placeholder {
  color: var(--fg-muted);
}

input:not([type="checkbox"]):not([type="radio"]):hover,
select:hover,
textarea:hover {
  border-color: var(--fg-faint);
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--fg-strong);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--fg-strong) 14%, transparent);
}

select {
  appearance: none;
  padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 16px top 15px, right 11px top 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: var(--text-13);
  color: var(--fg);
}

.check input {
  width: 15px;
  height: 15px;
  margin-top: 2px;
  flex: none;
}

.form-error {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid color-mix(in oklab, var(--state-bad) 34%, var(--rule));
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--state-bad) 8%, transparent);
  color: var(--state-bad);
  font-size: var(--text-13);
}

.form-error .icon {
  margin-top: 2px;
}

/* ----------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--rule);
  min-height: 49px;
}

.panel-head h2,
.panel-head h3 {
  font-size: var(--text-14);
  letter-spacing: -0.01em;
}

.panel-body {
  padding: var(--space-5);
}

.panel-foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--rule);
  color: var(--fg-muted);
  font-size: var(--text-12);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ------------------------------------------------------- stats and basis */

/* The instrument strip. Every figure states where it came from directly beneath
   itself, which is the one habit that keeps an estimate from reading as a bill. */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(var(--stat-cols, 4), minmax(0, 1fr));
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--panel);
  overflow: hidden;
}

.stat {
  display: grid;
  gap: var(--space-1);
  align-content: start;
  padding: var(--space-4) var(--space-5) var(--space-5);
  border-left: 1px solid var(--rule);
  min-width: 0;
}

.stat:first-child {
  border-left: 0;
}

.stat-label {
  font-size: var(--text-12);
  color: var(--fg-secondary);
  font-weight: 520;
}

.stat-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-24);
  font-weight: 500;
  letter-spacing: -0.03em;
  color: var(--fg-strong);
  line-height: 1.15;
}

.stat-value .unit {
  font-size: var(--text-14);
  color: var(--fg-muted);
  letter-spacing: 0;
}

.basis {
  font-family: var(--mono);
  font-size: var(--text-11);
  line-height: 1.5;
  color: var(--fg-muted);
  letter-spacing: -0.005em;
}

.basis b {
  font-weight: 500;
  color: var(--fg-secondary);
}

/* ------------------------------------------------------------------ meter */

.meter {
  display: block;
  height: 6px;
  border-radius: 2px;
  background: var(--control);
  overflow: hidden;
  color: var(--fg-faint);
}

.meter > i {
  display: block;
  height: 100%;
  color: var(--fg-secondary);
  background-color: color-mix(in oklab, var(--fg-strong) 20%, transparent);
}

.meter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
}

/* ------------------------------------------------------------------- tags */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-sm);
  background: var(--control);
  border: 1px solid var(--rule);
  color: var(--fg-secondary);
  font-size: var(--text-11);
  font-weight: 520;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.tag::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.72;
  flex: none;
}

.tag-plain::before {
  display: none;
}

.tag-link {
  color: var(--fg-secondary);
  text-decoration: none;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.tag-link:hover {
  color: var(--fg-strong);
  border-color: var(--rule-strong);
}

.tag-ok {
  color: var(--state-ok);
  background: color-mix(in oklab, var(--state-ok) 10%, transparent);
  border-color: color-mix(in oklab, var(--state-ok) 26%, transparent);
}

.tag-warn {
  color: var(--state-warn);
  background: color-mix(in oklab, var(--state-warn) 10%, transparent);
  border-color: color-mix(in oklab, var(--state-warn) 26%, transparent);
}

.tag-bad {
  color: var(--state-bad);
  background: color-mix(in oklab, var(--state-bad) 10%, transparent);
  border-color: color-mix(in oklab, var(--state-bad) 26%, transparent);
}

.tag-info {
  color: var(--state-info);
  background: color-mix(in oklab, var(--state-info) 10%, transparent);
  border-color: color-mix(in oklab, var(--state-info) 26%, transparent);
}

.tag .icon {
  width: 11px;
  height: 11px;
}

/* ------------------------------------------------------------------ table */

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-13);
}

table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: var(--space-3) var(--space-4);
  background: var(--panel);
  border-bottom: 1px solid var(--rule-strong);
  font-size: var(--text-11);
  font-weight: 560;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
  white-space: nowrap;
}

table.data td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--rule);
  color: var(--fg);
  vertical-align: middle;
}

table.data tbody tr:last-child td {
  border-bottom: 0;
}

table.data tbody tr {
  transition: background var(--dur-fast) var(--ease);
}

table.data tbody tr:hover {
  background: color-mix(in oklab, var(--fg-strong) 3.5%, transparent);
}

table.data .right {
  text-align: right;
}

table.data .cell-strong {
  color: var(--fg-strong);
  font-weight: 520;
}

.row-actions {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
}

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

.rows {
  display: grid;
}

.row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--rule);
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}

.rows > .row:first-child {
  border-top: 0;
}

button.row:hover {
  background: color-mix(in oklab, var(--fg-strong) 3.5%, transparent);
}

.row-title {
  display: block;
  color: var(--fg-strong);
  font-weight: 520;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  display: block;
  color: var(--fg-muted);
  font-size: var(--text-12);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.glyph {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--fg-secondary);
  font-family: var(--mono);
  font-size: var(--text-12);
  font-weight: 500;
  flex: none;
}

/* ------------------------------------------------------------------ empty */

.empty {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-5);
  max-width: 52ch;
}

.empty h3 {
  font-size: var(--text-15);
}

.empty p {
  color: var(--fg-muted);
}

.empty-center {
  justify-items: center;
  text-align: center;
  margin: 0 auto;
}

/* -------------------------------------------------------------- terminal */

.term {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #0a0c0e;
  color: #c8d2dc;
  overflow: hidden;
}

.term-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid #1e242a;
  font-family: var(--mono);
  font-size: var(--text-11);
  color: #7c8894;
}

.term-bar .spacer {
  margin-left: auto;
}

.term pre,
.term .term-body {
  margin: 0;
  padding: var(--space-4);
  font-family: var(--mono);
  font-size: var(--text-12);
  line-height: 1.7;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.term .cmd {
  color: #f4f6f8;
}

.term .cmd::before {
  content: "$ ";
  color: #414a54;
}

.term .ok { color: #3fb950; }
.term .warn { color: #d6a32c; }
.term .bad { color: #f0564a; }
.term .dim { color: #7c8894; }

.copy-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--mono);
  font-size: var(--text-12);
  color: var(--fg-strong);
}

.copy-line code {
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.copy-line code::-webkit-scrollbar {
  display: none;
}

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

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 380px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg-strong);
  box-shadow: var(--shadow-overlay);
  font-size: var(--text-13);
  pointer-events: auto;
  animation: toast-in var(--dur) var(--ease) both;
}

.toast .icon {
  color: var(--fg-muted);
}

.toast-ok .icon { color: var(--state-ok); }
.toast-bad .icon { color: var(--state-bad); }

.toast-state {
  font-family: var(--mono);
  font-size: var(--text-11);
  color: var(--fg-muted);
  margin-left: auto;
  padding-left: var(--space-3);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ----------------------------------------------------------------- modals */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--backdrop);
  animation: fade-in var(--dur-fast) var(--ease) both;
}

.modal {
  width: min(560px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;
  animation: modal-in var(--dur) var(--ease) both;
}

.modal-wide {
  width: min(1000px, 100%);
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--rule);
}

.modal header h2 {
  font-size: var(--text-15);
}

.modal-body {
  padding: var(--space-5);
  overflow: auto;
}

.modal form {
  display: grid;
  gap: var(--space-4);
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
}

/* ------------------------------------------------------------ page header */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}

.page-head h1 {
  font-size: var(--text-24);
  letter-spacing: -0.022em;
}

.page-head p {
  margin-top: var(--space-2);
  color: var(--fg-muted);
  max-width: 74ch;
}

.page-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.section {
  margin-top: var(--space-6);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.section-head h2 {
  font-size: var(--text-15);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  align-items: start;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.grid-wide {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

.stack {
  display: grid;
  gap: var(--space-4);
  align-content: start;
}

.stack-sm {
  display: grid;
  gap: var(--space-2);
  align-content: start;
}

.inline {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .grid-2,
  .grid-3,
  .grid-wide {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* The copy control sits on the dark terminal chrome, so it takes that surface's
   ink rather than the page's. */
.term-bar .btn-icon {
  color: #7c8894;
  border-color: transparent;
  background: transparent;
  height: 24px;
  width: 24px;
}

.term-bar .btn-icon:hover {
  color: #f4f6f8;
  background: #1a1f23;
}
