/* ================================
   Color Variables & Base Styles
   ================================ */
:root {
  --bg: #0f1724;
  --card: #0b1220;
  --muted: #94a3b8;
  --accent: #22c1c3;
  --accent-2: #60a5fa;
  --card-radius: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Inter, system-ui, Segoe UI, Arial, sans-serif;
  background: linear-gradient(180deg, #071021 0%, #071930 60%);
  color: #e6eef8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ================================
   Layout & Container
   ================================ */
.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.app-shell[hidden] {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: min(100%, 420px);
  background: rgba(11, 18, 32, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 12px 40px rgba(2, 6, 23, 0.7);
}

.login-card .logo {
  margin: 0 auto 16px;
}

.login-card h2 {
  margin: 0 0 8px;
  text-align: center;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

#loginForm {
  display: grid;
  gap: 12px;
}

#loginForm label {
  font-size: 13px;
  color: #dffaff;
}

#loginForm input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #111827;
  color: white;
  font-size: 14px;
}

#loginForm input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(34, 193, 195, 0.2);
}

.login-btn,
.logout-btn {
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.login-btn {
  margin-top: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #071021;
}

.logout-btn {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.login-btn:hover,
.logout-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.login-message {
  min-height: 18px;
  font-size: 13px;
  color: #fda4af;
  margin: 0;
}

.alerts {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.alert-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 10px 26px rgba(2, 6, 23, 0.25);
}

.alert-card span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font-size: 16px;
}

.alert-card .alert-text {
  color: #e2e8f0;
  font-size: 13px;
  line-height: 1.5;
}

.alert-card.info {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.08);
}

.alert-card.info span {
  background: rgba(59, 130, 246, 0.2);
  color: #7dd3fc;
}

.alert-card.warning {
  border-color: rgba(249, 115, 22, 0.35);
  background: rgba(249, 115, 22, 0.08);
}

.alert-card.warning span {
  background: rgba(249, 115, 22, 0.2);
  color: #fdba74;
}

.alert-card.error {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.alert-card.error span {
  background: rgba(239, 68, 68, 0.2);
  color: #fecaca;
}

/* ================================
   Header
   ================================ */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.logo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.6);
  flex-shrink: 0;
}

header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
  line-height: 1.3;
}

header .lead {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ================================
   Grid Layout
   ================================ */
main.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

/* ================================
   Card Styling
   ================================ */
.card {
  background: var(--card);
  padding: 18px;
  border-radius: var(--card-radius);
  box-shadow: 0 6px 24px rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.03);
  transition: all 0.3s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 32px rgba(2, 6, 23, 0.8);
}

.card h2 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #dffaff;
  font-weight: 600;
}

.value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-2);
  word-break: break-word;
  margin: 8px 0;
}

.meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ================================
   Controls & Buttons
   ================================ */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  appearance: none;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  min-width: 96px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  transform: scale(1);
  font-size: 13px;
  flex: 1;
  min-width: fit-content;
}

button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

button:active {
  transform: scale(0.98);
}

/* Active state indicator with checkmark */
button.active::before {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: 12px;
  font-weight: bold;
  animation: pulse 0.3s ease;
}

@keyframes pulse {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Button color variants */
.auto {
  background: linear-gradient(90deg, #16a34a, #4ade80);
  box-shadow: 0 4px 12px rgba(34, 161, 68, 0.3);
}

.auto.active {
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.8);
  filter: brightness(1.1);
}

.manual {
  background: linear-gradient(90deg, #dc2626, #fb7185);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.manual.active {
  box-shadow: 0 0 20px rgba(248, 113, 113, 0.8);
  filter: brightness(1.1);
}

.on {
  background: linear-gradient(90deg, #0ea5a4, #60a5fa);
  box-shadow: 0 4px 12px rgba(14, 165, 164, 0.3);
}

.on.active {
  box-shadow: 0 0 20px rgba(96, 165, 250, 0.8);
  filter: brightness(1.1);
}

.off {
  background: linear-gradient(90deg, #475569, #64748b);
  box-shadow: 0 4px 12px rgba(71, 85, 105, 0.3);
  opacity: 0.7;
}

.off.active {
  opacity: 1;
  box-shadow: 0 0 20px rgba(100, 116, 139, 0.6);
  filter: brightness(1.1);
}

.feed {
  background: linear-gradient(90deg, #f59e0b, #fb923c);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.feed.active {
  box-shadow: 0 0 20px rgba(251, 146, 60, 0.8);
  filter: brightness(1.1);
  animation: feedPulse 0.5s ease;
}

@keyframes feedPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

/* ================================
   History Section
   ================================ */
.card.history-card {
  grid-column: 1 / -1;
}

.history-section {
  display: grid;
  gap: 16px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-card {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 12px;
  transition: all 0.3s ease;
}

.chart-card:hover {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.95);
}

.chart-card h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: #dffaff;
  font-weight: 600;
}

.chart-box {
  position: relative;
  height: 220px;
}

/* ================================
   Table Styling
   ================================ */
.table-wrapper {
  overflow-x: auto;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  color: white;
  font-size: 13px;
}

th,
td {
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 8px;
  text-align: center;
  font-size: 12px;
}

th {
  background: #172554;
  font-weight: 600;
  position: sticky;
  top: 0;
}

tbody tr {
  transition: background 0.2s ease;
}

tbody tr:hover {
  background: #1a2332;
}

tbody tr:nth-child(even) {
  background: #111827;
}

/* ================================
   Footer
   ================================ */
footer {
  margin-top: 24px;
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ================================
   Responsive: Tablet (768px)
   ================================ */
@media (max-width: 768px) {
  .wrap {
    padding: 16px;
  }

  .logo {
    width: 48px;
    height: 48px;
    font-size: 24px;
  }

  header h1 {
    font-size: 18px;
  }

  header .lead {
    font-size: 12px;
  }

  main.grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .card {
    padding: 14px;
  }

  .value {
    font-size: 24px;
  }

  button {
    padding: 9px 12px;
    font-size: 12px;
  }

  .chart-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .chart-box {
    height: 180px;
  }

  table,
  th,
  td {
    font-size: 11px;
  }

  th,
  td {
    padding: 8px 6px;
  }
}

/* ================================
   Responsive: Mobile (640px)
   ================================ */
@media (max-width: 640px) {
  .wrap {
    padding: 12px;
  }

  main.grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .card {
    padding: 12px;
  }

  .card h2 {
    font-size: 13px;
    margin-bottom: 10px;
  }

  .value {
    font-size: 22px;
  }

  .meta {
    font-size: 11px;
  }

  button {
    padding: 8px 10px;
    font-size: 11px;
    min-width: 65px;
  }

  .chart-box {
    height: 160px;
  }

  table,
  th,
  td {
    font-size: 10px;
  }

  th,
  td {
    padding: 6px 4px;
  }
}

/* ================================
   Responsive: Small Phone (480px)
   ================================ */
@media (max-width: 480px) {
  .wrap {
    padding: 10px;
  }

  .logo {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }

  header {
    gap: 8px;
    margin-bottom: 16px;
  }

  header h1 {
    font-size: 15px;
  }

  header .lead {
    font-size: 11px;
  }

  main.grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .card {
    padding: 10px;
  }

  .card h2 {
    font-size: 12px;
    margin-bottom: 8px;
  }

  .value {
    font-size: 20px;
  }

  .meta {
    font-size: 10px;
  }

  button {
    padding: 7px 8px;
    font-size: 10px;
    min-width: 60px;
  }

  .chart-box {
    height: 140px;
  }

  .chart-grid {
    gap: 8px;
  }

  .chart-card {
    padding: 8px;
  }

  table,
  th,
  td {
    font-size: 9px;
  }

  th,
  td {
    padding: 5px 3px;
  }
}

/* ================================
   Responsive: Extra Small (360px)
   ================================ */
@media (max-width: 360px) {
  .wrap {
    padding: 8px;
  }

  .logo {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  header h1 {
    font-size: 14px;
  }

  header .lead {
    display: none;
  }

  main.grid {
    gap: 6px;
  }

  .card {
    padding: 8px;
  }

  .card h2 {
    font-size: 11px;
    margin-bottom: 6px;
  }

  .value {
    font-size: 18px;
  }

  button {
    padding: 6px 8px;
    font-size: 9px;
  }

  .chart-box {
    height: 120px;
  }

  table,
  th,
  td {
    font-size: 8px;
  }

  th,
  td {
    padding: 4px 2px;
  }

  footer {
    font-size: 11px;
  }
}
