:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f9fbfd;
  --text: #17202a;
  --muted: #607083;
  --border: #dce5ee;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e7f5f3;
  --blue: #2563eb;
  --amber: #b7791f;
  --amber-soft: #fff7e6;
  --green: #16784d;
  --green-soft: #e9f7ef;
  --red: #b42318;
  --red-soft: #fff1f0;
  --shadow: 0 18px 45px rgba(22, 32, 42, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 15px;
}

.login-card h1,
.topbar h1 {
  margin: 0;
  letter-spacing: 0;
}

.login-card h1 {
  margin-top: 18px;
  font-size: 28px;
  line-height: 1.15;
}

.login-card p,
.topbar p,
.section-toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.login-card label {
  margin-top: 18px;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 750;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.primary-button {
  width: 100%;
  margin-top: 20px;
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: white;
  color: var(--text);
  border-color: var(--border);
  padding: 0 14px;
}

.ghost-button:hover {
  border-color: #b6c6d6;
  background: var(--surface-soft);
}

.ghost-button.full {
  width: 100%;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  background: white;
  color: var(--muted);
  border-color: var(--border);
}

.icon-button:hover {
  color: var(--text);
  border-color: #b6c6d6;
}

.form-error,
.inline-message {
  min-height: 20px;
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

.inline-message.ok {
  color: var(--green);
}

.smtp-status {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.smtp-status.ready {
  border-color: #b9e3cd;
  background: var(--green-soft);
  color: var(--green);
}

.smtp-status.paused {
  border-color: #f0d490;
  background: var(--amber-soft);
  color: var(--amber);
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0 22px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.15;
}

.topbar-actions,
.panel-actions,
.toolbar-controls,
.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.metric.wide strong {
  font-size: 18px;
  line-height: 1.2;
}

.error-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #ffd1cc;
  background: var(--red-soft);
  color: var(--red);
  border-radius: 8px;
  font-size: 14px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.85fr) minmax(520px, 1.15fr);
  gap: 16px;
  margin-top: 16px;
}

.panel,
.inventory-panel,
.history-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.panel {
  padding: 18px;
}

.panel-heading,
.section-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel h2,
.section-toolbar h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.quiet {
  color: var(--muted);
  font-size: 13px;
}

.helper-text {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin: 16px 0;
  background: #edf2f7;
  border-radius: 8px;
}

.segment {
  border: 0;
  border-radius: 6px;
  min-height: 34px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

.segment.active {
  background: white;
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(22, 32, 42, 0.08);
}

.rules-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.rule-row {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr) 40px;
  gap: 8px;
}

.compact-label {
  margin-top: 14px;
}

.panel-actions {
  margin-top: 16px;
}

.panel-actions .primary-button {
  width: auto;
  margin-top: 0;
  padding: 0 16px;
}

.panel-actions.split {
  justify-content: space-between;
}

.switch {
  display: inline-flex;
  align-items: center;
  grid-auto-flow: column;
  gap: 8px;
  color: var(--text);
}

.switch input {
  width: 18px;
  min-height: 18px;
}

.smtp-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.span-2 {
  grid-column: span 2;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.55fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.inventory-panel,
.history-panel {
  padding: 18px;
}

.search-input {
  width: 260px;
}

.server-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.server-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.server-card.match {
  border-color: #98d6cd;
  background: var(--accent-soft);
}

.server-card.new {
  border-color: #e8c479;
  background: var(--amber-soft);
}

.server-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.server-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: 0;
}

.server-id {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.price {
  white-space: nowrap;
  color: var(--accent-strong);
  font-size: 20px;
  font-weight: 850;
}

.spec-list {
  display: grid;
  gap: 7px;
  margin: 12px 0;
  color: #344454;
  font-size: 13px;
  line-height: 1.35;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--border);
  color: #3e5164;
  font-size: 12px;
  font-weight: 750;
}

.chip.good {
  color: var(--green);
  background: var(--green-soft);
  border-color: #b9e3cd;
}

.chip.warn {
  color: var(--amber);
  background: #fff8ea;
  border-color: #f0d490;
}

.pagination {
  justify-content: center;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  max-height: 760px;
  overflow: auto;
  padding-right: 4px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.history-item.gone {
  opacity: 0.78;
}

.history-item h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.current {
  color: var(--green);
  background: var(--green-soft);
}

.status-pill.gone {
  color: var(--amber);
  background: var(--amber-soft);
}

.empty-state {
  border: 1px dashed #b9c7d6;
  border-radius: 8px;
  padding: 26px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-soft);
}

@media (max-width: 1100px) {
  .status-grid,
  .control-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .server-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .panel-heading,
  .section-toolbar,
  .topbar-actions,
  .toolbar-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .smtp-grid,
  .rule-row {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .search-input {
    width: 100%;
  }

  .icon-button.remove-rule {
    width: 100%;
  }
}
