/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #fff;
  color: #1a1a2e;
  line-height: 1.6;
  min-height: 100vh;
}

/* === HEADER === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #1a1a2e;
  color: #fff;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }
.header-logo { width: 22px; height: 22px; display: block; }
.back-link { color: #94a3b8; text-decoration: none; font-size: 0.95rem; font-weight: 600; padding: 0.3rem 0; }
.back-link:hover { color: #fff; }
.header-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; }
.nav-link { color: #94a3b8; text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav-link:hover { color: #fff; }

/* === MAIN === */
main { padding: 1rem; max-width: 800px; margin: 0 auto; }

/* === DASHBOARD CARDS === */
.cards { display: flex; flex-direction: column; gap: 0.85rem; }

.card {
  border: 2px solid #d0d0d8;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.card-main {
  display: block;
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: inherit;
}
.card-main:hover { background: #f8f8fb; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}
.card-header h2 { font-size: 1.05rem; font-weight: 700; color: #1a1a2e; }
.card-url { display: block; font-size: 0.8rem; color: #555; word-break: break-all; }

.card-version-row { padding: 0 1.1rem 0.35rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.card-version { font-size: 0.78rem; color: #555; font-weight: 500; }
.update-badge { background: #dbeafe; color: #1e40af; font-size: 0.7rem; }

.card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem 0.7rem;
  border-top: 1px solid #e8e8ee;
}
.btn-manage {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  background: #f0f0f4;
  color: #1a1a2e;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid #c0c0cc;
  text-align: center;
}
.btn-manage:hover { background: #e0e0e8; border-color: #2563eb; }
.btn-update { background: #dbeafe; border-color: #93c5fd; color: #1e40af; cursor: pointer; }
.btn-update:hover { background: #bfdbfe; border-color: #2563eb; }
.btn-notes { background: #f0fdf4; border-color: #86efac; color: #166534; cursor: pointer; }
.btn-notes:hover { background: #dcfce7; border-color: #22c55e; }

/* === BADGE / STATUS === */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.up { background: #dcfce7; color: #166534; }
.badge.degraded { background: #fef3c7; color: #92400e; }
.badge.down { background: #fee2e2; color: #991b1b; }

/* === PLATFORM PAGE === */
.platform-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.platform-head h1 { font-size: 1.35rem; font-weight: 700; }

.btn-primary {
  display: block;
  width: 100%;
  padding: 0.85rem 1.2rem;
  background: #2563eb;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  text-align: center;
  text-decoration: none;
  margin-bottom: 1rem;
}
.btn-primary:hover { background: #1d4ed8; }

/* Action grid */
.action-grid {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1rem;
}
.action-btn {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.85rem 1.1rem;
  background: #fff;
  border: 2px solid #d0d0d8;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a2e;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.action-btn:hover { border-color: #2563eb; background: #f0f4ff; }
.action-btn:active { background: #e0e8f8; }

/* Panels (logs, devices, result) */
.panel {
  border: 2px solid #d0d0d8;
  border-radius: 12px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #f4f4f6;
  border-bottom: 1px solid #d0d0d8;
}
.panel-header h3 { font-size: 0.95rem; font-weight: 700; }
.panel-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: #666;
  line-height: 1;
}
.panel-close:hover { color: #000; }
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid #e8e8ee;
  flex-wrap: wrap;
}
.panel-body { padding: 0.75rem 1rem; }

/* Small inputs and buttons */
.input-sm {
  width: 60px;
  padding: 0.25rem 0.4rem;
  border: 1px solid #c0c0cc;
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: center;
}
.btn-sm {
  padding: 0.3rem 0.7rem;
  background: #f0f0f4;
  border: 1px solid #c0c0cc;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: #1a1a2e;
}
.btn-sm:hover { background: #e0e0e8; }
.btn-sm.active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* Search input for logs */
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 120px;
}
.search-input {
  width: 100%;
  padding: 0.3rem 1.6rem 0.3rem 0.7rem;
  border: 1px solid #c0c0cc;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  outline: none;
  background: #fff;
}
.search-input:focus { border-color: #2563eb; }
.search-clear {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 4px;
  background: none;
  border: none;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
  padding: 2px 4px;
  border-radius: 4px;
}
.search-clear:hover { color: #1a1a2e; background: #e0e0e8; }

/* Output blocks (logs, result) */
.output-block {
  background: #1a1a2e;
  color: #e2e8f0;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
}
.output-block mark {
  background: #eab308;
  color: #1a1a2e;
  padding: 0.1rem 0.15rem;
  border-radius: 3px;
}

/* Device management */
.device-list { display: flex; flex-direction: column; gap: 0.5rem; }
.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid #e0e0e8;
  border-radius: 8px;
  flex-wrap: wrap;
}
.device-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.device-info strong { font-size: 0.9rem; }
.device-id, .device-ip, .device-scopes {
  font-size: 0.78rem;
  color: #555;
  word-break: break-all;
}
.device-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.btn-approve, .btn-reject {
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid #c0c0cc;
  border-radius: 6px;
  cursor: pointer;
}
.btn-approve { background: #dcfce7; color: #166534; border-color: #86efac; }
.btn-approve:hover { background: #bbf7d0; }
.btn-reject { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.btn-reject:hover { background: #fecaca; }

.empty-state { color: #666; font-size: 0.85rem; padding: 0.5rem 0; }
.loading { color: #666; font-style: italic; font-size: 0.85rem; }

/* === MESSAGES === */
.msg { display: none; font-size: 0.85rem; margin-top: 0.5rem; font-weight: 500; padding: 0.4rem 0.6rem; border-radius: 6px; }
.msg-error { display: block; color: #991b1b; background: #fee2e2; }
.msg-success { display: block; color: #166534; background: #dcfce7; }

/* === LOGIN PAGE === */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #f4f4f6; padding: 1rem; }
.login-card {
  background: #fff;
  border: 2px solid #d0d0d8;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}
.login-card h1 { font-size: 1.5rem; font-weight: 700; color: #1a1a2e; margin-bottom: 0.2rem; }
.login-card .subtitle { color: #555; margin-bottom: 1.25rem; font-size: 0.85rem; }
.login-card label { display: block; font-weight: 600; margin-bottom: 0.3rem; color: #1a1a2e; font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 2px solid #c0c0cc;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  -webkit-appearance: none;
}
.login-card input:focus { border-color: #2563eb; }
.login-card .error-msg { display: none; color: #dc2626; font-size: 0.85rem; margin-top: 0.5rem; font-weight: 500; }
.login-card button {
  width: 100%;
  margin-top: 1rem;
  padding: 0.75rem;
  background: #2563eb;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  -webkit-appearance: none;
}

/* === SETTINGS MODAL === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: #fff;
  border: 2px solid #d0d0d8;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  margin: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem 0.3rem;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; color: #1a1a2e; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #666; line-height: 1; }
.modal-close:hover { color: #000; }
.modal-body { padding: 0.3rem 1.2rem 1.2rem; }
.modal-body h3 { font-size: 0.9rem; font-weight: 600; color: #333; margin-bottom: 0.7rem; }
.modal-body label { display: block; font-weight: 600; margin-bottom: 0.25rem; margin-top: 0.6rem; color: #1a1a2e; font-size: 0.85rem; }
.modal-body input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 2px solid #c0c0cc;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  -webkit-appearance: none;
}
.modal-body input:focus { border-color: #2563eb; }
.modal-body button[type="submit"] {
  width: 100%;
  margin-top: 0.9rem;
  padding: 0.7rem;
  background: #2563eb;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

/* === SYSTEM METRICS (VPS status bar) === */
.sys-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 2px solid #d0d0d8;
  border-radius: 12px;
  background: #fff;
}
.sys-metric {
  flex: 1;
  min-width: 150px;
}
.sys-metric-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}
.sys-metric-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a2e;
}
.sys-bar-track {
  height: 6px;
  background: #e8e8ee;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.3rem;
}
.sys-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s ease;
}
.sys-bar-fill.green { background: #22c55e; }
.sys-bar-fill.yellow { background: #eab308; }
.sys-bar-fill.orange { background: #f97316; }
.sys-bar-fill.red { background: #ef4444; }
.sys-metric-sub {
  font-size: 0.7rem;
  color: #888;
  margin-top: 0.1rem;
}

/* === RESPONSIVE === */
@media (min-width: 600px) {
  html { font-size: 17px; }
  main { padding: 1.5rem; }
  .cards { gap: 1rem; }
  .action-grid { flex-direction: row; flex-wrap: wrap; }
  .action-btn { width: auto; min-width: 200px; flex: 1; }
  .output-block { max-height: 50vh; }
}
@media (min-width: 900px) {
  html { font-size: 18px; }
}