:root {
  --bg-color: #090a0f;
  --card-bg: rgba(22, 24, 33, 0.75);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --accent: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.25);
  --accent-warn: #f59e0b;
  --accent-danger: #ef4444;
  --btn-bg: rgba(255, 255, 255, 0.06);
  --btn-bg-hover: rgba(255, 255, 255, 0.12);
  --glass-blur: blur(24px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-color: #f2f2f7;
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(0, 0, 0, 0.08);
    --text-main: #111827;
    --text-muted: #6b7280;
    --btn-bg: rgba(0, 0, 0, 0.05);
    --btn-bg-hover: rgba(0, 0, 0, 0.1);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: max(16px, var(--safe-top));
  padding-bottom: calc(72px + var(--safe-bottom));
  overflow-x: hidden;
}

/* Offline Banner */
.offline-banner {
  display: none;
  background: #b91c1c;
  color: #ffffff;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.offline-banner.active {
  display: block;
}

/* App Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 16px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-btn {
  background: var(--btn-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

/* Main Container */
main {
  flex: 1;
  padding: 0 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Tab Views */
.tab-view {
  display: none;
  animation: fadeIn 0.2s ease;
}
.tab-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Big Hero Button */
.hero-action-card {
  margin-bottom: 20px;
}

.btn-hero {
  width: 100%;
  padding: 20px 24px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(5, 150, 105, 0.08));
  border: 1.5px solid rgba(16, 185, 129, 0.35);
  box-shadow: 0 8px 24px var(--accent-glow);
  border-radius: 20px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.btn-hero:active {
  transform: scale(0.98);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.hero-text {
  text-align: left;
}

.hero-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.hero-pulse-dot {
  width: 12px;
  height: 12px;
  background-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
}

/* Summary Status Pill */
.status-pill {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.status-dots {
  display: flex;
  gap: 16px;
}

.status-node {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #6b7280;
}
.dot.ok { background-color: var(--accent); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.dot.warn { background-color: var(--accent-warn); box-shadow: 0 0 8px rgba(245, 158, 11, 0.5); }
.dot.down { background-color: var(--accent-danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }
.dot.disabled { background-color: #6b7280; opacity: 0.4; box-shadow: none; }

/* Machine Cards */
.machine-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 16px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.machine-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.metric-box {
  background: var(--btn-bg);
  border-radius: 12px;
  padding: 10px 12px;
}

.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.metric-value {
  font-size: 15px;
  font-weight: 600;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-btn {
  background: var(--btn-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.action-btn:active {
  background: var(--btn-bg-hover);
  transform: scale(0.97);
}

.action-btn.danger {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.25);
}

/* Service List */
.service-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.service-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.service-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.service-name {
  font-size: 15px;
  font-weight: 600;
}

.service-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.service-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Events Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.event-item {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
}

.event-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.event-msg {
  font-weight: 500;
}

/* Bottom Floating Navigation */
.bottom-nav {
  position: fixed;
  bottom: max(12px, var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 440px;
  background: rgba(26, 28, 38, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 28px;
  padding: 6px 12px;
  display: flex;
  justify-content: space-around;
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  z-index: 90;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  border-radius: 16px;
  transition: all 0.15s ease;
}

.nav-item.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 18px;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-sheet {
  background: #181920;
  border: 1px solid var(--card-border);
  border-radius: 28px 28px 0 0;
  width: 100%;
  max-width: 540px;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: var(--btn-bg);
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

.modal-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
}

.modal-body pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 10px;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #000000;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
}

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: var(--btn-bg);
  color: var(--text-main);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #ffffff;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
