*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #050b14;
  --panel: #080f1c;
  --border: #0f2744;
  --accent: #00ffe7;
  --accent2: #ff6b35;
  --muted: #1a3050;
  --text: #c8ddf0;
  --text-dim: #4083ba;
  --font-mono: "Share Tech Mono", monospace;
  --font-ui: "Rajdhani", sans-serif;

  /* transition all color vars on theme switch */
  --theme-transition:
    background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ---- Light theme overrides ---- */
:root.light {
  --bg: #f0f4f8;
  --panel: #ffffff;
  --border: #c8d8e8;
  --accent: #0077aa;
  --accent2: #d45000;
  --muted: #dde8f2;
  --text: #1a2a3a;
  --text-dim: #6a8aaa;
}

/* scan-line is invisible in light mode */
:root.light body::before {
  opacity: 0;
}

/* ---- Theme toggle button ---- */
#theme-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s,
    background 0.2s;
  flex-shrink: 0;
}
#theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(128, 128, 128, 0.06);
}
/* The little sun/moon icon inside the button */
#theme-btn .icon {
  font-size: 13px;
  line-height: 1;
}

/* ── Login card ── */
.card {
  position: relative;
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 40px 44px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  transition:
    background 0.3s,
    border-color 0.3s;

  /* Corner accents */
  --c: var(--accent);
}
.card::before,
.card::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--accent);
  border-style: solid;
  opacity: 0.6;
  transition: border-color 0.3s;
}
.card::before {
  top: -1px;
  left: -1px;
  border-width: 2px 0 0 2px;
  border-radius: 4px 0 0 0;
}
.card::after {
  bottom: -1px;
  right: -1px;
  border-width: 0 2px 2px 0;
  border-radius: 0 0 4px 0;
}

/* ── Card header ── */
.card-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.brand {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--accent);
  text-transform: uppercase;
}
.title {
  font-family: var(--font-ui);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
}
.subtitle {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ── Form fields ── */
.fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
}
input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition:
    border-color 0.2s,
    background 0.3s,
    color 0.3s;
  width: 100%;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 255, 231, 0.08);
}
:root.light input:focus {
  box-shadow: 0 0 0 2px rgba(0, 119, 170, 0.1);
}
input::placeholder {
  color: var(--text-dim);
  opacity: 0.5;
}

/* ── Error message ── */
.error-msg {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--accent2);
  min-height: 14px; /* reserve space so card doesn't jump */
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transform: translateY(-4px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.error-msg.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Submit button ── */
.submit-btn {
  width: 100%;
  padding: 11px;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition:
    background 0.2s,
    color 0.2s,
    box-shadow 0.2s;
}
.submit-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
  z-index: 0;
}
.submit-btn:hover::before {
  transform: scaleX(1);
}
.submit-btn:hover {
  color: var(--bg);
  box-shadow: 0 0 14px rgba(0, 255, 231, 0.2);
}
:root.light .submit-btn:hover {
  box-shadow: 0 0 14px rgba(0, 119, 170, 0.2);
}
.submit-btn span {
  position: relative;
  z-index: 1;
}

/* Loading state */
.submit-btn.loading {
  pointer-events: none;
  opacity: 0.7;
}
.submit-btn.loading span::after {
  content: " ...";
  animation: dots 1s steps(3) infinite;
}
@keyframes dots {
  0% {
    content: " .";
  }
  33% {
    content: " ..";
  }
  66% {
    content: " ...";
  }
}

/* ── Card entry animation ── */
@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.card {
  animation: cardIn 0.4s ease forwards;
}

/* ---- Logout button ---- */
.logout-btn-color {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s,
    background 0.2s;
  flex-shrink: 0;
}
.logout-btn-color:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(128, 128, 128, 0.06);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 500;
  min-height: 100vh; /* ← ขั้นต่ำ 100vh แต่ขยายได้ */
  overflow-y: auto; /* ← เปิด vertical scroll */
  overflow-x: hidden; /* ← ปิด horizontal scroll */
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: var(--theme-transition);
}

.body-login {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 500;
  min-height: 90vh;
  display: grid;
  place-items: center;
  align-items: center;
  justify-content: center;
  gap: 0;
  transition:
    background 0.3s,
    color 0.3s;
  position: relative;
}

.panel,
th,
td {
  transition: var(--theme-transition);
}

/* Subtle scan-line texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 231, 0.015) 2px,
    rgba(0, 255, 231, 0.015) 4px
  );
  pointer-events: none;
  z-index: 999;
}

/* ---- Header ---- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 4px;
  flex-shrink: 0;
}

.logo {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0.9;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

.status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

#clock {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--accent);
  letter-spacing: 2px;
}

/* --- ML Drift Alert Animation --- */
@keyframes drift-pulse {
  0% {
    text-shadow: 0 0 5px #ff3b3b, 0 0 10px #ff3b3b;
    color: #ff3b3b;
  }
  50% {
    text-shadow: 0 0 20px #ff0000, 0 0 30px #ff0000;
    color: #ffffff;
  }
  100% {
    text-shadow: 0 0 5px #ff3b3b, 0 0 10px #ff3b3b;
    color: #ff3b3b;
  }
}

/* Class ที่จะถูกเพิ่มผ่าน JS เมื่อค่า Drift > 0.25 */
.drift-alert {
  animation: drift-pulse 1.5s infinite;
  font-weight: bold;
  border: 1px solid #ff3b3b;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255, 59, 59, 0.1);
}

/* --- Save Baseline Button Styling --- */
.baseline-btn-color {
  background: transparent;
  color: var(--accent); /* ใช้สี Cyan เดิมของระบบ */
  border: 1px solid var(--accent);
  font-family: 'Share Tech Mono', monospace;
  padding: 5px 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-right: 10px;
  font-size: 0.8rem;
  clip-path: polygon(10% 0, 100% 0, 100% 70%, 90% 100%, 0 100%, 0 30%); /* ทรงเหลี่ยมเท่ๆ */
}

.baseline-btn-color:hover {
  background: var(--accent);
  color: #0a2352;
  box-shadow: 0 0 15px var(--accent);
}

.baseline-btn-color:active {
  transform: scale(0.95);
}

/* --- Drift Panel Grid Adjustment --- */
.drift-panel {
  border-left: 2px solid #ffaa00; /* สีส้มแจ้งเตือน */
}

#drift-status {
    display: none;
    transition: all 0.5s ease-in-out;
}

#drift-status.visible {
    display: inline-block;
}

/* ---- Main grid ---- */
.grid {
  display: grid;
  grid-template-rows: repeat(10, 1fr);
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.grid1 {
  grid-row: span 3 / span 3;
}
.grid2 {
  grid-row: span 3 / span 3;
}
.grid3 {
  grid-row: span 2 / span 2;
  grid-row-start: 4;
}
.grid4 {
  grid-row: span 2 / span 2;
  grid-row-start: 4;
}
.grid5 {
  grid-column: span 2 / span 2;
  grid-row: span 5 / span 5;
  grid-row-start: 6;
}


.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* Corner decorations */
.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: var(--accent);
  border-style: solid;
  opacity: 0.5;
}
.panel::before {
  top: 0;
  left: 0;
  border-width: 1px 0 0 1px;
}
.panel::after {
  bottom: 0;
  right: 0;
  border-width: 0 1px 1px 0;
}

.panel-title {
  font-family: var(--font-mono);
  font-size: 16px;
  letter-spacing: 3px;
  color: var(--text-dim);
  text-transform: uppercase;
  flex-shrink: 0;
}

.panel-title span {
  color: var(--accent);
  margin-right: 6px;
}

.chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ---- Table panel ---- */
.table-panel {
  grid-column: span 2;
  max-height: 220px;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.scroll::-webkit-scrollbar {
  width: 4px;
}
.scroll::-webkit-scrollbar-track {
  background: transparent;
}
.scroll::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 2px;
}

table {
  width: 100%;
  font-size: 15px;
  font-family: var(--font-mono);
  border-collapse: collapse;
}

th {
  background: var(--muted);
  color: var(--text-dim);
  letter-spacing: 1px;
  font-size: 15px;
  padding: 5px 6px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 1;
  font-family: var(--font-ui);
  font-weight: 700;
  text-transform: uppercase;
}

td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

tr:hover td {
  background: rgba(0, 255, 231, 0.04);
}

td:nth-child(4) {
  color: var(--accent2);
} /* Port */
td:nth-child(7) {
  color: #ff4466;
} /* SYN */
td:nth-child(8) {
  color: #44aaff;
} /* ACK */

/* Row fade-in */
@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
tr.new-row {
  animation: rowIn 0.25s ease forwards;
}
