:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef3f5;
  --border: #d8e0e6;
  --text: #15222b;
  --muted: #667782;
  --primary: #126c74;
  --primary-dark: #0c555c;
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #157347;
  --shadow: 0 12px 30px rgba(21, 34, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 16px;
}

button:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button,
.ghost-button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.secondary-button:hover,
.ghost-button:hover {
  background: var(--surface-muted);
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(18, 108, 116, 0.14);
  outline: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #16252d;
  color: #eef7f7;
  padding: 24px 16px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-mark {
  align-items: center;
  background: #e8b44f;
  border-radius: 8px;
  color: #16252d;
  display: flex;
  font-weight: 900;
  height: 40px;
  justify-content: center;
  width: 40px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #a9b8bf;
  font-size: 13px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border-radius: 6px;
  color: #c8d6dc;
  padding: 10px 12px;
  text-decoration: none;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.content {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.segmented {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.segmented button {
  background: transparent;
  border-radius: 0;
  color: var(--muted);
  font-size: 13px;
  min-height: 38px;
  padding: 0 12px;
}

.segmented button.active {
  background: var(--primary);
  color: #fff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.3;
}

.topbar p {
  color: var(--muted);
  margin-top: 5px;
}

.icon-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  height: 40px;
  padding: 0;
  width: 40px;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.subscription-row,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 92px;
  padding: 16px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  font-size: 28px;
  line-height: 1.15;
  margin-top: 10px;
}

.subscription-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 160px minmax(0, 1fr);
  padding: 14px;
}

.subscription-row label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.copy-field {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  min-height: 54px;
  padding: 0 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

table {
  border-collapse: collapse;
  min-width: 850px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 6px 9px;
}

.status.online {
  background: #e5f6ed;
  color: var(--ok);
}

.status.installing {
  background: #fff4df;
  color: var(--warning);
}

.status.error {
  background: #fde8e7;
  color: var(--danger);
}

.status.manual {
  background: #e9f0f7;
  color: #305d82;
}

.status.pending_payment {
  background: #fff4df;
  color: var(--warning);
}

.status.paid {
  background: #e5f6ed;
  color: var(--ok);
}

.status.cancelled {
  background: #f0f2f4;
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
}

button.compact {
  min-height: 34px;
  padding: 0 10px;
}

.row-actions .secondary {
  background: var(--surface-muted);
  color: var(--text);
}

.row-actions .danger {
  background: #fbe9e8;
  color: var(--danger);
}

.empty-state {
  color: var(--muted);
  display: none;
  padding: 22px;
  text-align: center;
}

.grid {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 0.85fr);
}

.form-panel {
  padding-bottom: 16px;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
}

.form-grid label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 800;
  gap: 6px;
}

.toggle-row {
  align-items: center;
  display: flex !important;
  gap: 10px !important;
}

.toggle-row input {
  min-height: auto;
  width: auto;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 16px;
}

.log-panel {
  min-height: 390px;
}

.info-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.info-content {
  color: var(--text);
  display: grid;
  gap: 14px;
  line-height: 1.55;
  padding: 16px;
}

.info-content p {
  color: var(--muted);
}

.info-content dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.info-content dl div {
  align-items: center;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  padding-top: 10px;
}

.info-content dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.info-content dd {
  font-weight: 800;
  margin: 0;
}

pre {
  background: #101820;
  color: #d7e5ea;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  height: 335px;
  line-height: 1.5;
  margin: 0;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
}

.toast {
  background: #15222b;
  border-radius: 8px;
  bottom: 20px;
  color: #fff;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden {
  display: none !important;
}

.auth-page {
  background: #16252d;
}

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

.auth-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  margin: 0 auto;
  max-width: 430px;
  padding: 24px;
  width: 100%;
}

.auth-brand {
  color: var(--text);
  margin-bottom: 24px;
}

.auth-brand span {
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form h1 {
  font-size: 26px;
}

.auth-form p {
  color: var(--muted);
  line-height: 1.45;
  margin-top: 6px;
}

.auth-form label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 800;
  gap: 6px;
}

.auth-message {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  min-height: 20px;
  padding-top: 14px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 14px;
  }

  .brand {
    margin-bottom: 14px;
  }

  .nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

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

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

@media (max-width: 640px) {
  .content {
    padding: 16px;
  }

  .subscription-row,
  .copy-field,
  .stats-grid,
  .info-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: space-between;
  }
}
