/* ══════════════════════════════════════════════════
   Network Monitor — Dashboard Style
   Theme: Dark navy (hospital dashboard style)
   ══════════════════════════════════════════════════ */

:root {
  --bg-body: #0d1225;
  --bg-card: #141a30;
  --bg-card-hover: #1a2140;
  --bg-input: #1a2140;
  --border: #262f4a;
  --border-focus: #4a6cf7;
  --text-primary: #e8edf5;
  --text-secondary: #8892b0;
  --text-muted: #5a6380;
  --color-up: #22c55e;
  --color-down: #ef4444;
  --color-warning: #f59e0b;
  --color-unknown: #6b7280;
  --color-disabled: #4b5563;
  --color-primary: #4a6cf7;
  --color-primary-hover: #5b7bf8;
  --color-danger: #ef4444;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Container ─────────────────────────────────────── */

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Header ────────────────────────────────────────── */

.header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(135deg, #141a30, #1a2140);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-align: center;
  flex: 1;
  margin: 0 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header-clock {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}

.nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--color-primary);
  color: #fff;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.live-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.3);
  letter-spacing: 0.5px;
  transition: var(--transition);
  white-space: nowrap;
}

/* ── Buttons ───────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-warning {
  background: var(--color-warning);
  color: #000;
}
.btn-warning:hover:not(:disabled) {
  background: #d97706;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ── Stats Row ─────────────────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--text-muted);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-up { border-left: 3px solid var(--color-up); }
.stat-down { border-left: 3px solid var(--color-down); }
.stat-warning { border-left: 3px solid var(--color-warning); }
.stat-primary { border-left: 3px solid var(--color-primary); }
.stat-uptime { border-left: 3px solid #8b5cf6; }

.stat-up .stat-value { color: var(--color-up); }
.stat-down .stat-value { color: var(--color-down); }
.stat-warning .stat-value { color: var(--color-warning); }

/* ── Alert ─────────────────────────────────────────── */

.alert {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}

.alert-danger { color: #fca5a5; }

.alert-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.6;
  padding: 0 4px;
}
.alert-close:hover { opacity: 1; }

/* ── Host Grid ─────────────────────────────────────── */

.hosts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.host-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  transition: var(--transition), border-color 0.8s ease, box-shadow 0.8s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.host-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.host-disabled {
  opacity: 0.5;
}

/* Flash animations */
.card-flash-up {
  border-color: var(--color-up) !important;
  box-shadow: 0 0 20px rgba(34,197,94,0.2);
}

.card-flash-down {
  border-color: var(--color-down) !important;
  box-shadow: 0 0 20px rgba(239,68,68,0.2);
}

.host-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.host-address {
  margin-bottom: 2px;
}

.host-address code {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.2);
  padding: 2px 8px;
  border-radius: 4px;
}

.host-status-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2px 0;
}

.host-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-up { background: var(--color-up); box-shadow: 0 0 8px rgba(34,197,94,0.5); }
.status-down { background: var(--color-down); box-shadow: 0 0 8px rgba(239,68,68,0.5); }
.status-warning { background: var(--color-warning); box-shadow: 0 0 8px rgba(245,158,11,0.5); }
.status-unknown { background: var(--color-unknown); }
.status-disabled { background: var(--color-disabled); }

.status-text {
  font-size: 13px;
  font-weight: 500;
}

.response-time {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.host-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: #fca5a5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.host-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.host-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

/* ── Badges ────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-ping { background: rgba(74,108,247,0.2); color: #8ba4ff; }
.badge-tcp { background: rgba(139,92,246,0.2); color: #b79aff; }
.badge-http { background: rgba(34,197,94,0.2); color: #6ee7a7; }
.badge-up { background: rgba(34,197,94,0.2); color: var(--color-up); }
.badge-down { background: rgba(239,68,68,0.2); color: var(--color-down); }
.badge-warning { background: rgba(245,158,11,0.2); color: var(--color-warning); }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.status-dot.status-up { background: var(--color-up); }
.status-dot.status-down { background: var(--color-down); }
.status-dot.status-warning { background: var(--color-warning); }
.status-dot.status-unknown { background: var(--color-unknown); }
.status-dot.status-disabled { background: var(--color-disabled); }

/* ── Cards (generic) ───────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 16px;
  margin-bottom: 14px;
  color: var(--text-primary);
}

.card-danger {
  border-left: 3px solid var(--color-down);
}

.form-card { max-width: 600px; }
.list-card { flex: 1; }

/* ── Layout ────────────────────────────────────────── */

.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .form-card { max-width: 100%; }
  .header { gap: 8px; padding: 12px 14px; }
  .header-clock { width: 100%; text-align: center; order: -1; }
  .header-title { font-size: 16px; margin: 0 6px; }
  .header-nav { width: 100%; justify-content: center; flex-wrap: wrap; }
  .header-actions { width: 100%; justify-content: center; }
}

/* ── Forms ─────────────────────────────────────────── */

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition);
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74,108,247,0.15);
}

.form-group textarea {
  resize: vertical;
}

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

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ── Filter Bar ────────────────────────────────────── */

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.filter-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-form label {
  font-size: 13px;
  color: var(--text-secondary);
}

.filter-form select {
  padding: 6px 30px 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  min-width: 220px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892b0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.filter-count {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Tables ────────────────────────────────────────── */

.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

.table-sm td, .table-sm th {
  padding: 7px 10px;
  font-size: 12px;
}

.row-up td { border-left: 2px solid var(--color-up); }
.row-down td { border-left: 2px solid var(--color-down); }
.row-warning td { border-left: 2px solid var(--color-warning); }
.row-disabled { opacity: 0.4; }

.text-nowrap { white-space: nowrap; }
.text-center { text-align: center; }
.text-error { color: #fca5a5; font-size: 12px; }

.actions {
  display: flex;
  gap: 4px;
  white-space: nowrap;
}

/* ── Toast ─────────────────────────────────────────── */

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--color-up);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: opacity 0.4s ease;
  animation: slideIn 0.3s ease;
}

.toast-danger {
  background: var(--color-danger);
}

@keyframes slideIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Empty state ───────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 16px;
  font-size: 15px;
}

/* ── Scrollbar ─────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
