:root {
  color-scheme: dark;
  --background: #0b1123;
  --surface: #151d34;
  --field: #10172b;
  --line: #303b58;
  --text: #f4f6fd;
  --muted: #aab5d0;
  --accent: #5648dc;
  --accent-hover: #6456e8;
  --link: #b9b1ff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font: 15px/1.55 system-ui, sans-serif;
}
header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem max(1.25rem, calc((100% - 1120px) / 2));
  border-bottom: 1px solid var(--line);
  background: #10172c;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  font-size: 1.18rem;
  font-weight: 750;
  letter-spacing: -.035em;
  white-space: nowrap;
  color: var(--text);
}
.brand::before {
  content: "IP";
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: .55rem;
  background: var(--accent);
  color: white;
  font-size: .72rem;
  letter-spacing: .04em;
}
nav, .actions { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
nav a { padding: .42rem .72rem; border-radius: .46rem; color: var(--muted); }
nav a[aria-current] { background: #292747; color: var(--text); font-weight: 650; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 1160px; margin: auto; padding: 2.8rem 1.25rem 3rem; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.08; letter-spacing: -.045em; margin: 0 0 1.6rem; }
h2 { font-size: 1.08rem; margin: 0 0 .3rem; }
p { margin: .18rem 0; color: var(--muted); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(19rem, 26rem); gap: 2rem; align-items: start; }
article {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.05rem 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
article:first-child { border-top: 1px solid var(--line); }
.editor { border: 1px solid var(--line); border-radius: .85rem; background: var(--surface); padding: 1.3rem; }
.editor h2 { margin-bottom: .95rem; }
label { display: block; margin-bottom: .85rem; font-weight: 600; }
input:not([type=checkbox]), select {
  display: block;
  width: 100%;
  min-height: 2.65rem;
  margin-top: .3rem;
  padding: .5rem .7rem;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: .5rem;
  font: inherit;
  font-weight: 400;
}
input::placeholder { color: var(--muted); opacity: 1; }
.check { display: flex; align-items: center; gap: .45rem; }
input[type=checkbox] { accent-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-weight: 650; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
button {
  min-height: 2.55rem;
  padding: .48rem .8rem;
  border: 1px solid transparent;
  border-radius: .5rem;
  font: inherit;
  font-weight: 650;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
button:hover { background: var(--accent-hover); }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.secondary:hover { background: #222c47; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
.snackbar-stack {
  position: fixed;
  z-index: 10;
  inset: 1rem 1rem auto auto;
  display: grid;
  gap: .5rem;
  width: min(24rem, calc(100% - 2rem));
  pointer-events: none;
}
.snackbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  padding: .7rem .9rem;
  background: #252344;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--link);
  border-radius: .65rem;
  box-shadow: 0 .5rem 1.5rem #0005;
  color: var(--text);
  overflow-wrap: anywhere;
  pointer-events: auto;
}
.snackbar-error { background: #382337; border-inline-start-color: #fa9eae; }
.snackbar button { flex: none; padding: 0 .25rem; background: transparent; color: var(--text); font-size: 1.25rem; line-height: 1.15; }
.snackbar button:hover { background: #ffffff18; }
.empty { padding: 1rem 0; border-top: 1px solid var(--line); }
.empty, time { color: var(--muted); }
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; gap: 1.3rem; }
  main { padding-top: 1.6rem; }
  article { align-items: flex-start; flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

.inventory {
  border: 1px solid var(--line);
  border-radius: .85rem;
  background: var(--surface);
  padding: 1.3rem;
}
.inventory > h2 { margin-bottom: .85rem; }
.inventory article:last-child { border-bottom: 0; padding-bottom: .15rem; }
.inventory-empty {
  border: 1px dashed var(--line);
  border-radius: .6rem;
  background: var(--field);
  padding: 1.35rem;
}
.inventory-empty h3 { font-size: 1rem; margin: 0 0 .4rem; }
.inventory-empty ol { color: var(--muted); margin: .4rem 0 1rem; padding-left: 1.25rem; }
.inventory-empty li + li { margin-top: .35rem; }
.button-link {
  display: inline-block;
  padding: .45rem .7rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  font-weight: 650;
}

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .8rem; }
.section-heading h2 { margin: 0; }
.proxy-row { flex-wrap: wrap; }
.proxy-status strong { color: #f6d78e; }
.status-ok { color: #8ee1ad; }

.proxy-row .actions { gap: .4rem; }
.icon-action {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--field);
  color: var(--link);
}
.icon-action:hover { background: #222c47; }
.icon-action svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-action::after {
  content: attr(data-tooltip);
  display: none;
  position: absolute;
  z-index: 1;
  right: 0;
  bottom: calc(100% + .45rem);
  width: max-content;
  padding: .25rem .5rem;
  border: 1px solid var(--line);
  border-radius: .35rem;
  background: var(--background);
  color: var(--text);
  font: 500 .8rem/1.4 system-ui, sans-serif;
  pointer-events: none;
}
.icon-action:hover::after, .icon-action:focus-visible::after { display: block; }

.account-row { flex-wrap: wrap; row-gap: .35rem; }
.account-row .actions { gap: .4rem; }
.status-paused { color: #f6d78e; }
.status-error { color: #fa9eae; }
.icon-action[aria-disabled="true"] {
  cursor: default;
  color: var(--muted);
}

.account-details { flex: 1 1 15rem; }
.account-heading { display: flex; flex: 0 0 100%; justify-content: space-between; align-items: baseline; gap: .75rem; }
.account-heading h2 { margin: 0; }
.account-balance { display: flex; align-items: baseline; gap: .45rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.account-balance span { color: var(--muted); font-size: .76rem; }
.account-controls { display: flex; order: 1; margin-left: auto; align-items: center; flex-wrap: wrap; gap: .6rem; }
.account-badge {
  display: inline-flex;
  align-items: center;
  padding: .25rem .6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-ok { color: #8ee1ad; border-color: #3b735a; background: #142d2b; }
.badge-paused { color: #f6d78e; border-color: #856432; background: #30281e; }
.badge-error { color: #fa9eae; border-color: #8d4e64; background: #382337; }

.account-stats { display: flex; flex-wrap: wrap; column-gap: 1rem; row-gap: .4rem; margin: .6rem 0; }
.account-stats dt { color: var(--muted); font-size: .76rem; }
.account-stats dd { margin: 0; color: var(--text); font-size: .95rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.search-row { flex-wrap: wrap; }
.search-row > form > button[name="op"] {
  min-height: 2rem;
  padding: .3rem .6rem;
  font-size: .8rem;
  line-height: 1.25;
}
.search-settings { flex: 1 0 100%; }
.search-settings > form { margin-top: .65rem; }
.search-settings label { margin-top: .55rem; }
summary { color: var(--link); cursor: pointer; }
.stacked-editor { margin-top: 1rem; }
.select-ip { user-select: all; }

.confirm-panel { margin-bottom: 1rem; border-color: #8d4e64; }
.confirm-panel p { margin-bottom: .8rem; }
button.danger { background: #a03955; }
button.danger:hover { background: #b24562; }

.account-zones { margin-bottom: .85rem; }
.zone-options { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .4rem; }
.zone-options .check { margin: 0; padding: .2rem .45rem; border: 1px solid var(--line); border-radius: .4rem; }

.journal-tabs { margin: -0.35rem 0 1rem; }
/* Anchor the filter popup to the full page heading. */
.filter-heading { position: relative; display: grid; margin-bottom: 1.15rem; }
.filter-heading > h1, .filter-heading > .list-filters { grid-area: 1 / 1; }
.filter-heading > h1 { align-self: start; display: flex; align-items: center; min-height: 44px; margin: 0; padding-inline-end: 13rem; }
.list-filters { min-width: 0; }
.list-filters summary {
  display: flex;
  width: max-content;
  min-height: max(44px, clamp(2rem, 5.4vw, 3.456rem));
  margin-inline-start: auto;
  align-items: center;
  gap: .55rem;
  padding: .45rem .8rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  list-style: none;
}
.list-filters summary::-webkit-details-marker { display: none; }
.list-filters summary:hover { background: #222c47; }
.list-filters[open] summary { border-color: var(--link); }
.list-filters summary svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.list-filters summary span { color: var(--link); font-size: .78rem; }
@media (max-width: 500px) {
  .filter-heading > h1 { padding-inline-end: 9rem; }
  .list-filters summary span { font-size: 0; }
  .list-filters summary span::before { content: ""; display: block; width: .45rem; height: .45rem; border-radius: 50%; background: var(--link); }
}

.filter-form {
  position: absolute;
  z-index: 8;
  inset: calc(100% + .5rem) 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .85rem 1rem;
  max-height: max(12rem, calc(100dvh - 10rem));
  overflow-y: auto;
  box-shadow: 0 .65rem 1.5rem #0007;
}
.filter-form > label, .filter-form fieldset label { margin: 0; min-width: 0; }
.filter-form > .filter-wide, .filter-form > .actions { grid-column: 1 / -1; }
.filter-form > fieldset { grid-column: span 2; }
@media (max-width: 720px) {
  .filter-form { grid-template-columns: minmax(0, 1fr); }
  .filter-form > fieldset { grid-column: auto; }
}


.stats-table { overflow-x: auto; }
.stats-table table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.stats-table th, .stats-table td { padding: .55rem .7rem; text-align: right; border-bottom: 1px solid var(--line); }
.stats-table th:first-child { text-align: left; }
.stats-table thead th { color: var(--muted); font-size: .8rem; }

.journal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: start;
  column-gap: 1rem;
}
.journal-action { min-width: 0; }
.journal-date {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 480px) {
  .journal-row { grid-template-columns: minmax(0, 1fr); row-gap: .25rem; }
  .journal-date { text-align: left; }
}

.search-clock { font-variant-numeric: tabular-nums; }

.search-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: .85rem;
}
.inventory .search-cards > .search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: var(--field);
  align-items: start;
}
.search-cards > .search-row > .actions { flex-wrap: nowrap; }
.search-cards > .search-row > .search-settings { grid-column: 1 / -1; }
.search-cards > .inventory-empty { grid-column: 1 / -1; }
@media (max-width: 760px) {
  .search-cards { grid-template-columns: minmax(0, 1fr); }
}


.login-panel { max-width: 26rem; margin: clamp(1rem, 9vh, 6rem) auto 0; }
.login-panel h1 { font-size: clamp(1.5rem, 5vw, 2rem); }
.login-panel button { width: 100%; }
.logout-control { margin-left: auto; }


.panel-menu { display: contents; }
.menu-toggle { display: none; }
.menu-toggle svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

@media (max-width: 960px) {
  .panel-header { position: relative; justify-content: space-between; gap: .75rem; }
  .menu-toggle:not([hidden]) { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; }
  .menu-toggle[aria-expanded="true"] { border-color: var(--link); }
  .panel-menu { display: grid; flex: 0 0 100%; gap: .75rem; border-top: 1px solid var(--line); padding-top: .65rem; }
  .menu-toggle:not([hidden]) + .panel-menu {
    position: absolute;
    z-index: 9;
    top: calc(100% - .6rem);
    right: 1.25rem;
    width: min(15rem, calc(100% - 2.5rem));
    max-height: calc(100dvh - 5rem);
    overflow-y: auto;
    gap: .45rem;
    padding: .45rem;
    border: 1px solid var(--line);
    border-radius: .75rem;
    background: var(--surface);
    box-shadow: 0 .65rem 1.5rem #0007;
  }
  .menu-toggle:not([hidden])[aria-expanded="false"] + .panel-menu { display: none; }
  .panel-menu nav { display: grid; gap: .15rem; }
  .panel-menu nav a { min-height: 44px; display: flex; align-items: center; padding-inline: .7rem; }
  .panel-menu .logout-control { margin: 0; padding-top: .45rem; border-top: 1px solid var(--line); }
  .panel-menu .logout-control button { width: 100%; min-height: 44px; }
}


.journal-pagination {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .5rem;
  margin-top: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.journal-pagination a { justify-self: start; min-height: 44px; display: flex; align-items: center; border: 1px solid var(--line); color: var(--link); }
.journal-pagination a[rel="next"] { justify-self: end; }


.logout-dialog {
  width: min(24rem, calc(100% - 2rem));
  max-width: none;
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: .85rem;
  box-shadow: 0 .65rem 1.5rem #0007;
}
.logout-dialog::backdrop { background: #060a15b3; }
.logout-dialog h2 { margin: 0 0 1rem; }
.logout-dialog .actions { justify-content: flex-end; }
.logout-dialog button { min-width: 4rem; min-height: 44px; }


@media (max-width: 720px) {
  .inventory .account-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .7rem;
    margin-top: .65rem;
    padding: .85rem;
    border: 1px solid var(--line);
    border-radius: .65rem;
    background: var(--field);
  }
  .inventory .account-row:last-child { border-bottom: 1px solid var(--line); padding-bottom: .85rem; }
  .account-heading { align-items: start; gap: .5rem; }
  .account-heading h2 { min-width: 0; }
  .account-balance { flex: none; align-items: baseline; }
  .account-controls { order: 0; justify-content: space-between; margin: 0; }
  .account-controls .actions { flex-wrap: nowrap; margin-inline-start: auto; }
  .account-badge { white-space: normal; }
  .account-details { display: grid; gap: .55rem; }
  .account-meta { display: grid; gap: .2rem; font-size: .86rem; }
  .account-meta p, .account-note { margin: 0; }
  .account-endpoint { white-space: nowrap; }
  .account-note { font-size: .82rem; }
  .account-row .account-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .4rem;
    margin: 0;
    padding: .55rem .65rem;
    border-radius: .45rem;
    background: var(--surface);
  }
  .account-row .account-stats dt { min-height: 2.4em; line-height: 1.2; }
  .account-row .account-stats dd { margin-top: .16rem; }
}
