@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Orbitron:wght@400;600;800&family=Outfit:wght@300;400;600;700&family=Roboto+Mono:wght@400;600&display=swap');

:root {
  --theme-color: #00d2ff;
  --theme-color-rgb: 0, 210, 255;
  --theme-color-glow: rgba(0, 210, 255, 0.4);
  --bg-gradient: linear-gradient(135deg, #09090e 0%, #131324 100%);
  --bg-image: none;
  --font-family: 'Outfit', sans-serif;

  /* Glassmorphism system */
  --glass-bg: rgba(18, 18, 36, 0.6);
  --glass-bg-hover: rgba(28, 28, 56, 0.75);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.18);
  --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

  /* Status Colors */
  --color-low: #00e676;       /* Safe/Low - Neon green */
  --color-normal: #00d2ff;    /* Normal - Neon blue */
  --color-high: #ff1744;      /* High - Neon red */
  
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.35);
}

/* Base resets */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  background-attachment: fixed;
  background-size: cover;
  background-position: center;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
}

/* Background overlay when background image is set */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  z-index: -2;
  opacity: 0.8;
  pointer-events: none;
  display: var(--bg-image-display, none);
}

body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 8, 16, 0.75); /* fallback dark screen filter */
  backdrop-filter: blur(10px);
  z-index: -1;
  pointer-events: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(10, 10, 20, 0.5);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--theme-color);
  box-shadow: 0 0 10px var(--theme-color);
}

/* Navigation bar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 2.5rem;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
  color: var(--text-primary);
}

.nav-logo {
  height: 40px;
  width: 40px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 10px var(--theme-color-glow);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.nav-logo-placeholder {
  height: 40px;
  width: 40px;
  border-radius: 50%;
  background: var(--theme-color-glow);
  border: 1px solid var(--theme-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-color);
  font-weight: 700;
  text-shadow: 0 0 5px var(--theme-color);
}

.nav-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 1.5rem;
  align-items: center;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.3s ease;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background: var(--glass-bg-hover);
  border-color: var(--glass-border);
  box-shadow: 0 0 15px rgba(var(--theme-color-rgb), 0.15);
}

.nav-link.active {
  border-color: var(--theme-color);
  text-shadow: 0 0 10px var(--theme-color-glow);
}

/* Page Container Layout */
.container {
  max-width: 1300px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Glass Cards */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 1.8rem;
  box-shadow: var(--card-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
  border-color: var(--glass-border-hover);
  transform: translateY(-4px);
  box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.5), 0 0 20px rgba(var(--theme-color-rgb), 0.05);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Grid Layouts */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.2fr 2fr;
  gap: 2rem;
}

@media (max-width: 968px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.2rem;
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Mini Statistics Cards */
.stat-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 15px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: all 0.3s ease;
}

.stat-box:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(var(--theme-color-rgb), 0.2);
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: 'Orbitron', monospace;
  color: var(--text-primary);
}

.stat-unit {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-family: var(--font-family);
  margin-left: 0.15rem;
}

/* Gauge Meter styling */
.gauge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 1rem 0;
}

.gauge-canvas {
  width: 250px;
  height: 250px;
}

.gauge-info {
  text-align: center;
  margin-top: -30px;
  z-index: 1;
}

.gauge-value {
  font-size: 3rem;
  font-weight: 800;
  font-family: 'Orbitron', monospace;
  line-height: 1;
  text-shadow: 0 0 15px var(--theme-color-glow);
}

.gauge-status {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 0.4rem;
  padding: 0.25rem 0.8rem;
  border-radius: 20px;
  display: inline-block;
  letter-spacing: 1px;
}

.status-low {
  background: rgba(0, 230, 118, 0.1);
  color: var(--color-low);
  border: 1px solid rgba(0, 230, 118, 0.25);
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.15);
}

.status-normal {
  background: rgba(0, 210, 255, 0.1);
  color: var(--color-normal);
  border: 1px solid rgba(0, 210, 255, 0.25);
  box-shadow: 0 0 8px rgba(0, 210, 255, 0.15);
}

.status-high {
  background: rgba(255, 23, 68, 0.1);
  color: var(--color-high);
  border: 1px solid rgba(255, 23, 68, 0.25);
  box-shadow: 0 0 8px rgba(255, 23, 68, 0.15);
}

.last-update {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Charts and Filters */
.chart-controls {
  display: flex;
  gap: 0.5rem;
}

.btn-tab {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.3s ease;
}

.btn-tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.btn-tab.active {
  background: var(--theme-color-glow);
  color: var(--text-primary);
  border-color: var(--theme-color);
  box-shadow: 0 0 10px var(--theme-color-glow);
}

.chart-wrapper {
  margin-top: 1rem;
  height: 320px;
  position: relative;
}

/* Serial Config Card Styling */
.serial-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: center;
  justify-content: space-between;
}

.serial-controls-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.form-select-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-select-group label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

select, input[type="text"], input[type="password"], textarea {
  background: rgba(20, 20, 35, 0.7);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all 0.3s ease;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--theme-color);
  box-shadow: 0 0 10px var(--theme-color-glow);
}

select option {
  background: #15152a;
  color: var(--text-primary);
}

/* Buttons */
.btn {
  background: var(--theme-color-glow);
  border: 1px solid var(--theme-color);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.52rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn:hover {
  background: var(--theme-color);
  box-shadow: 0 0 15px var(--theme-color-glow);
  transform: scale(1.03);
}

.btn:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: none;
}

.btn-danger {
  background: rgba(255, 23, 68, 0.15);
  border-color: var(--color-high);
  color: var(--text-primary);
}

.btn-danger:hover {
  background: var(--color-high);
  box-shadow: 0 0 15px rgba(255, 23, 68, 0.4);
}

/* Connection Status Badge */
.status-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px currentColor;
}

.status-pill.connected {
  border-color: rgba(0, 230, 118, 0.3);
  color: var(--color-low);
  background: rgba(0, 230, 118, 0.08);
}

.status-pill.connected .status-dot {
  background: var(--color-low);
  animation: pulse 1.5s infinite;
}

.status-pill.disconnected {
  border-color: rgba(255, 23, 68, 0.3);
  color: var(--color-high);
  background: rgba(255, 23, 68, 0.08);
}

.status-pill.disconnected .status-dot {
  background: var(--color-high);
}

.status-pill.waiting {
  border-color: rgba(255, 179, 0, 0.3);
  color: var(--warning-color);
  background: rgba(255, 179, 0, 0.08);
}

.status-pill.waiting .status-dot {
  background: var(--warning-color);
  animation: pulse 0.8s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.5; }
}

/* Authentication Page layout */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem 2.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.auth-header {
  text-align: center;
}

.auth-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.auth-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 1.2rem;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Image Manager Grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.media-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  aspect-ratio: 1;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: all 0.3s ease;
}

.media-item:hover {
  border-color: var(--theme-color);
  transform: scale(1.02);
}

.media-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-item-delete {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(255, 23, 68, 0.8);
  border: none;
  color: #fff;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.media-item:hover .media-item-delete {
  opacity: 1;
}

.media-item-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.65rem;
  padding: 0.2rem 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* History table styling */
.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.5rem;
  justify-content: space-between;
}

.filters-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.history-actions {
  display: flex;
  gap: 0.8rem;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: 15px;
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.15);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

th, td {
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--glass-border);
}

th {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

tr:last-child td {
  border-bottom: none;
}

tr {
  transition: background-color 0.2s ease;
}

tr:hover td {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Loader style */
.loader-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: var(--theme-color);
  animation: spin 1s linear infinite;
  box-shadow: 0 0 10px var(--theme-color-glow);
}

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

/* Footer style */
footer {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--glass-border);
  background: rgba(10, 10, 20, 0.3);
  margin-top: auto;
}

/* Alerts and notifications */
.alert {
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: fadeIn 0.3s ease;
  margin-bottom: 1rem;
}

.alert-success {
  background: rgba(0, 230, 118, 0.15);
  color: var(--color-low);
  border: 1px solid rgba(0, 230, 118, 0.3);
}

.alert-danger {
  background: rgba(255, 23, 68, 0.15);
  color: var(--color-high);
  border: 1px solid rgba(255, 23, 68, 0.3);
}

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

/* ====== ปุ่มรีเซ็ตค่าเริ่มต้น ====== */
.btn-reset {
  background: rgba(255, 179, 0, 0.12);
  border: 1px solid rgba(255, 179, 0, 0.4);
  color: #ffb300;
  font-size: 0.8rem;
  padding: 0.42rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  transition: all 0.25s ease;
  font-family: inherit;
}

.btn-reset:hover {
  background: rgba(255, 179, 0, 0.25);
  box-shadow: 0 0 14px rgba(255, 179, 0, 0.3);
  transform: scale(1.03);
}

.btn-reset:active {
  transform: scale(0.97);
}

/* ====== Drag Zone Layout Helpers ====== */
.drag-zone {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.drag-zone-single {
  width: 100%;
}

/* ====== Stats Cards ใน drag zone ====== */
.drag-zone-right .stat-box {
  /* ปรับให้ stats cards อยู่ใน 2x2 grid */
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
}

/* ====== Highlight Row styling ====== */
tr.highlight-row td {
  background-color: rgba(var(--theme-color-rgb), 0.25) !important;
  border-top: 1.5px solid var(--theme-color) !important;
  border-bottom: 1.5px solid var(--theme-color) !important;
  box-shadow: inset 0 0 10px rgba(var(--theme-color-rgb), 0.3);
  font-weight: bold;
  animation: highlight-pulse 2s infinite ease-in-out;
}

@keyframes highlight-pulse {
  0% { background-color: rgba(var(--theme-color-rgb), 0.15); }
  50% { background-color: rgba(var(--theme-color-rgb), 0.35); }
  100% { background-color: rgba(var(--theme-color-rgb), 0.15); }
}

/* ====== Discord-Style Bottom-Left Notifications ====== */
.discord-notification-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  pointer-events: none;
}

.discord-notification-toast {
  pointer-events: auto;
  width: 320px;
  background: #2f3136; /* Discord dark card bg */
  color: #dcddde;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  display: flex;
  overflow: hidden;
  position: relative;
  font-family: var(--font-family);
  animation: slideInFromLeft 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards,
             fadeOutDiscord 0.5s ease-in 4.5s forwards;
  border-left: 5px solid var(--theme-color);
}

.discord-notification-toast.low {
  border-left-color: #f04747; /* Discord red */
}

.discord-notification-toast.high {
  border-left-color: #faa61a; /* Discord warning orange/yellow */
}

.discord-notification-body {
  padding: 12px 16px;
  flex: 1;
}

.discord-notification-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.discord-notification-icon {
  font-size: 1.1rem;
}

.discord-notification-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.discord-notification-text {
  font-size: 0.85rem;
  line-height: 1.4;
}

.discord-notification-close {
  background: transparent;
  border: none;
  color: #72767d;
  cursor: pointer;
  padding: 8px;
  align-self: flex-start;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.discord-notification-close:hover {
  color: #fff;
}

@keyframes slideInFromLeft {
  from {
    transform: translateX(-120%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

