:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #d9e2ec;
  --border-soft: #edf2f7;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --green: #15803d;
  --amber: #b7791f;
  --red: #b42318;
  --blue: #2563eb;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.06);
  --radius: 8px;
  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);
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(230px, 280px) auto minmax(430px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 850;
}

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

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 800;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: inline-flex;
  width: max-content;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 3px;
}

.tab,
.segment {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.tab {
  min-height: 34px;
  padding: 0 14px;
}

.tab.active,
.segment.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.header-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

label span,
select {
  display: block;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 12px;
  font-weight: 760;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 11px;
  font-size: 14px;
  outline: none;
}

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

.button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #ffffff;
  color: #344054;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 800;
}

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

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

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

.button.success {
  border-color: rgba(21, 128, 61, 0.32);
  color: var(--green);
}

.button.danger {
  border-color: rgba(180, 35, 24, 0.32);
  color: var(--red);
}

.button.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.session-pill {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.main {
  padding: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.page-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.15;
  font-weight: 820;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
  font-weight: 800;
}

h3 {
  font-size: 13px;
  line-height: 1.2;
  font-weight: 820;
}

.page-title p,
.panel-head p,
.detail-muted {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.last-refresh {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

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

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

.status-card {
  padding: 14px 16px;
  border-left: 4px solid var(--green);
}

.status-card.warning {
  border-left-color: var(--amber);
}

.status-card.danger {
  border-left-color: var(--red);
}

.status-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-card strong {
  display: block;
  margin-top: 7px;
  font-size: 30px;
  line-height: 1;
}

.status-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
  align-items: start;
}

.numbers-panel {
  min-width: 0;
}

.detail-panel,
.messages-panel {
  min-width: 0;
}

.messages-panel {
  grid-column: 1 / -1;
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-head.compact {
  padding: 14px 16px;
}

.table-tools {
  display: flex;
  align-items: end;
  gap: 10px;
}

.table-tools input {
  width: 220px;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 3px;
}

.segment {
  min-height: 30px;
  padding: 0 10px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  white-space: nowrap;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: #fbfcfe;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: #f8fbfd;
}

tbody tr.selected {
  background: rgba(15, 118, 110, 0.07);
}

.number-cell {
  color: var(--text);
  font-weight: 820;
}

.subline {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 640;
}

.warning-text {
  color: var(--amber);
  font-weight: 850;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.badge.online,
.badge.available,
.badge.ok {
  color: var(--green);
  border-color: rgba(21, 128, 61, 0.28);
}

.badge.rented,
.badge.wait,
.badge.warning {
  color: var(--amber);
  border-color: rgba(183, 121, 31, 0.3);
}

.badge.offline,
.badge.error {
  color: var(--red);
  border-color: rgba(180, 35, 24, 0.3);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.battery {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 88px;
}

.battery-bar {
  width: 44px;
  height: 7px;
  overflow: hidden;
  border-radius: 4px;
  background: #e4eaf1;
}

.battery-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.battery-fill.low {
  background: var(--red);
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.row-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.detail-content {
  padding: 16px;
}

.detail-top {
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
}

.detail-number {
  font-size: 22px;
  line-height: 1.1;
  font-weight: 850;
}

.placeholder-alert {
  border: 1px solid rgba(183, 121, 31, 0.3);
  border-radius: 7px;
  background: #fff8eb;
  color: #8a570f;
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 760;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.detail-box {
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  background: var(--surface-soft);
  padding: 10px;
}

.detail-box span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.detail-box strong {
  display: block;
  margin-top: 5px;
  font-size: 13px;
}

.detail-section {
  display: grid;
  gap: 9px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.message-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 11px;
}

.message-card p,
.rent-card p {
  margin-top: 6px;
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.rent-card {
  display: grid;
  gap: 11px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 8px;
  background: #f7fcfb;
  padding: 11px;
}

.rent-card p {
  margin-top: 0;
}

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

.message-item {
  min-width: 0;
  padding: 14px 16px;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}

.message-item strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 820;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-item p {
  margin-top: 6px;
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.count-pill {
  display: inline-flex;
  min-width: 30px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.api-panel {
  max-width: 1180px;
}

.activations-panel {
  min-width: 0;
}

.profit-strip .status-card strong {
  font-size: 28px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr)) auto auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.api-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(260px, 0.75fr) minmax(320px, 1fr);
  gap: 16px;
  padding: 16px;
}

.form-block {
  display: grid;
  gap: 12px;
  align-content: start;
}

.api-output {
  min-height: 210px;
  max-height: 340px;
  margin: 0;
  overflow: auto;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #0f172a;
  color: #dbeafe;
  padding: 14px;
  font-size: 12px;
  line-height: 1.55;
}

.empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

.login-page {
  display: grid;
  place-items: center;
  background: #eef4f7;
}

.login-shell {
  width: min(100%, 440px);
  padding: 22px;
}

.login-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-brand {
  margin-bottom: 26px;
}

.login-form {
  display: grid;
  gap: 15px;
}

.login-form h1 {
  font-size: 25px;
}

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

.login-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  font-weight: 760;
}

.toast {
  animation: pulse 0.22s ease-out;
}

@keyframes pulse {
  from { opacity: 0.68; }
  to { opacity: 1; }
}

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
  }

  .header-actions {
    justify-content: stretch;
  }

  .api-key-field {
    flex: 1;
  }

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

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

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

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

  .api-output {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .main {
    padding: 16px;
  }

  .app-header {
    padding: 13px 16px;
  }

  .header-actions,
  .page-title,
  .panel-head,
  .table-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions .button,
  .table-tools input {
    width: 100%;
  }

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

  .message-log,
  .api-grid,
  .filters-grid {
    grid-template-columns: 1fr;
  }

  .api-output {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .brand strong {
    white-space: normal;
  }

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

  .segmented {
    overflow-x: auto;
  }

  .segment {
    flex: 1 0 auto;
  }
}

@media (max-width: 720px) {
  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody tr {
    margin: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
  }

  tbody tr.selected {
    border-color: rgba(15, 118, 110, 0.4);
  }

  td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    white-space: normal;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 92px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
  }

  td.empty {
    display: block;
  }

  td.empty::before {
    content: "";
    display: none;
  }

  .row-actions {
    justify-content: flex-end;
  }
}
