:root {
  --bg: #0b0b09;
  --panel: rgba(24, 21, 16, 0.96);
  --panel-2: #15110b;
  --card: #211b13;
  --card-hover: #2a2116;
  --input: #282116;
  --border: #473827;
  --border-soft: rgba(255, 179, 71, 0.14);
  --text: #f5f7fb;
  --muted: #9ca3af;
  --orange: #ff9f1c;
  --orange-2: #f97316;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #fbbf24;
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255, 159, 28, 0.18), transparent 32%),
    radial-gradient(circle at bottom right, rgba(249, 115, 22, 0.10), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 32px 14px;
}

.shell {
  width: min(940px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 28px;
}

.page {
  position: relative;
  overflow: hidden;
  padding: 34px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.56), inset 0 1px 0 rgba(255, 159, 28, 0.08);
}

.page::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 4px;
  background: repeating-linear-gradient(135deg, var(--orange) 0 18px, #2b2114 18px 36px);
  opacity: 0.95;
}

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

.brand h1 {
  margin: 0;
  color: var(--orange);
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: -0.7px;
}

.brand small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(0, 212, 159, 0.12);
  border: 1px solid rgba(0, 212, 159, 0.35);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-chip.offline {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: var(--red);
}

.status-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.status-chip.offline::before {
  background: var(--red);
  box-shadow: 0 0 14px var(--red);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  margin-bottom: 26px;
}

.tab {
  padding: 12px 10px;
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.tab.active {
  color: #00131b;
  background: linear-gradient(135deg, var(--orange), var(--orange-2));
  box-shadow: 0 10px 26px rgba(255, 159, 28, 0.24);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0 14px;
  color: var(--orange);
  font-size: 18px;
  font-weight: 800;
}

.section-title::before {
  content: "";
  width: 4px;
  height: 23px;
  border-radius: 999px;
  background: var(--orange);
  box-shadow: 0 0 18px rgba(255, 159, 28, 0.75);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

#devicesGrid {
  display: grid;
  gap: 28px;
}

.card {
  padding: 14px;
  min-height: 80px;
  background: linear-gradient(180deg, var(--card), #141c2b);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  transition: transform 0.18s ease, background 0.18s ease;
  overflow: hidden;
  word-break: break-all;
}

.card:hover {
  transform: translateY(-2px);
  background: var(--card-hover);
}

.card .label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.card .value {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  font-weight: 800;
}

.card .value.bool-true { color: var(--green); }
.card .value.bool-false { color: var(--red); }

.io-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 9px;
}

.io {
  padding: 9px 6px;
  border-radius: 9px;
  color: #fff;
  background: var(--red);
  border: 1px solid var(--red);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.io.on {
  color: #001a13;
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 18px rgba(0, 212, 159, 0.32);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

label {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

input, select {
  width: 100%;
  min-height: 42px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--input);
  border: 1px solid #5a462c;
  border-radius: 10px;
  outline: none;
  font-size: 15px;
}

input:focus, select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 159, 28, 0.14);
}

.password-wrap {
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 8px;
}

button, .btn {
  min-height: 42px;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  color: white;
  background: linear-gradient(135deg, var(--orange), var(--orange-2));
  font-weight: 800;
  cursor: pointer;
  transition: filter 0.18s ease, transform 0.18s ease;
}

button:hover, .btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
button.full, .btn.full { width: 100%; margin-top: 12px; }
button.icon { padding: 0; }
button.danger, .btn.danger { background: var(--red); }

/* Login Styles */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100vh - 64px);
}

.login-box {
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    font-size: 2rem;
    margin: 0 0 1.5rem 0;
    text-align: center;
    font-weight: 700;
    color: var(--orange);
}

.input-group {
    margin-bottom: 1.5rem;
}

.error-message {
    color: var(--red);
    font-size: 0.9rem;
    text-align: center;
    margin-top: 1rem;
    min-height: 1.2rem;
}

/* Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dashboard-header h1 {
    color: var(--orange);
    margin: 0;
}

@media (max-width: 720px) {
  body { padding: 18px 10px; }
  .page { padding: 22px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .io-grid { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .tabs { font-size: 14px; }
}

.tab-content {
  display: none;
  animation: fadeIn 0.4s;
}
.tab-content.active {
  display: block;
}

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

/* Controls at the bottom of device card */
.device-controls {
    margin-top: 24px;
    display: flex;
    gap: 12px;
}
.device-controls button {
    flex: 1;
}

/* Fix nested objects in card */
.nested-data {
    font-size: 0.85em;
    text-align: left;
    margin-top: 12px;
}
.nested-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}
.nested-row:last-child {
    margin-bottom: 0;
}
.nested-label {
    color: var(--muted);
}
.nested-value {
    color: var(--text);
    font-weight: bold;
}
