:root {
  color-scheme: dark light;
  --bg: var(--tg-theme-bg-color, #0b1220);
  --card: var(--tg-theme-secondary-bg-color, #151f33);
  --text: var(--tg-theme-text-color, #f8fafc);
  --muted: var(--tg-theme-hint-color, #94a3b8);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(148, 163, 184, 0.2);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px calc(26px + env(safe-area-inset-bottom));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1 {
  margin: 3px 0 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.icon-button {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:disabled {
  opacity: 0.5;
}

.card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.card-head .muted {
  margin-top: 5px;
}

.status-pill {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.status-pill::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  content: "";
}

.status-pill.ok {
  background: rgba(34, 197, 94, 0.15);
}

.status-pill.ok::before {
  background: #22c55e;
}

.status-pill.off {
  background: rgba(239, 68, 68, 0.15);
}

.status-pill.off::before {
  background: #ef4444;
}

.status-pill.warn {
  background: rgba(245, 158, 11, 0.15);
}

.status-pill.warn::before {
  background: #f59e0b;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  min-height: 46px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
}

.button:active:not(:disabled) {
  transform: scale(0.98);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.button.secondary {
  background: rgba(148, 163, 184, 0.16);
  color: var(--text);
}

.button.danger {
  background: #dc2626;
  color: #ffffff;
}

.button.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.button.small {
  min-height: 38px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 4px;
}

.swatch {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.swatch:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.swatch.red {
  background: #ef4444;
}

.swatch.green {
  background: #22c55e;
}

.swatch.blue {
  background: #3b82f6;
}

.swatch.white {
  background: #f8fafc;
}

.swatch.violet {
  background: #a855f7;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.control-label {
  min-width: 64px;
  color: var(--muted);
  font-size: 13px;
}

input[type="color"] {
  width: 48px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

input[type="range"] {
  flex: 1 1 120px;
  min-width: 110px;
  accent-color: var(--accent);
}

#led-bright-value {
  min-width: 28px;
  text-align: right;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
}

.tab {
  flex: 1 1 0;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.tab.active {
  background: rgba(148, 163, 184, 0.16);
  color: var(--text);
}

.tab:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.section-title {
  margin: 20px 4px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-value {
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.metric-value.small {
  font-size: 30px;
}

.metric-value.warn {
  color: #f59e0b;
}

.metric-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 14px;
  margin-top: 10px;
  font-size: 14px;
}

.meter {
  height: 10px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
}

.meter-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}

.meter-fill.free {
  background: #22c55e;
}

.alert-banner {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(239, 68, 68, 0.55);
  border-radius: 16px;
  background: rgba(239, 68, 68, 0.14);
  color: #fecaca;
  font-size: 14px;
  line-height: 1.45;
}

.alert-title {
  margin-bottom: 6px;
  font-weight: 700;
}

.alert-list {
  margin: 0;
  padding-left: 18px;
}

.alert-list li + li {
  margin-top: 4px;
}

.disk-card .card-head {
  margin-bottom: 10px;
}

.disk-model {
  font-size: 16px;
  font-weight: 700;
}

.disk-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.monitor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 14px 4px 0;
  border-top: 1px solid var(--border);
}

.monitor-footer .button {
  flex: 0 0 auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-cell {
  min-width: 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.10);
}

.metric-cell-value {
  margin-top: 5px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric-error {
  grid-column: 1 / -1;
  line-height: 1.45;
}

.beszel-toggle {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.beszel-toggle::after {
  flex: 0 0 auto;
  margin-left: 4px;
  color: var(--muted);
  content: "▾";
  transition: transform 0.2s ease;
}

.beszel-card.open .beszel-toggle::after {
  transform: rotate(180deg);
}

.uptime-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.uptime-group {
  margin: 14px 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.uptime-group:first-child {
  margin-top: 0;
}

.uptime-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.uptime-group + .uptime-item {
  border-top: 0;
}

.uptime-item::before {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  content: "";
}

.uptime-item.state-up::before {
  background: #22c55e;
}

.uptime-item.state-down::before {
  background: #ef4444;
}

.uptime-item.state-pending::before,
.uptime-item.state-maintenance::before {
  background: #f59e0b;
}

.uptime-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uptime-meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

.chart-block + .chart-block {
  margin-top: 14px;
}

.chart-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}

.chart {
  height: 56px;
}

.chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

.detail-rows {
  display: flex;
  flex-direction: column;
  margin-top: 16px;
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.detail-row:first-child {
  border-top: 0;
}

.detail-row .muted {
  min-width: 0;
}

.detail-value {
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

.section-subtitle {
  margin: 18px 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.container-list,
.disk-usage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.container-item,
.disk-usage-item {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.08);
}

.container-head,
.disk-usage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.container-name,
.disk-usage-head span:first-child {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.container-status {
  flex: 0 0 auto;
  max-width: 45%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.container-meta,
.disk-usage-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.disk-usage-meta {
  margin-top: 7px;
}

.beszel-link {
  width: 100%;
  margin-top: 14px;
}

.notice {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 16px;
  background: rgba(245, 158, 11, 0.12);
  font-size: 14px;
  line-height: 1.45;
}

.toast {
  position: sticky;
  top: 8px;
  z-index: 10;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: var(--shadow);
}

.toast.ok {
  border-color: rgba(34, 197, 94, 0.45);
}

.toast.warn {
  border-color: rgba(245, 158, 11, 0.55);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.55);
}

.footer-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  .app {
    padding-top: 16px;
  }

  h1 {
    font-size: 25px;
  }

  .card {
    padding: 16px;
  }

  .button-row .button {
    flex: 1 1 130px;
  }

  .monitor-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .metric-cell {
    padding: 10px;
  }

  .metric-cell-value {
    font-size: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
