/* Copyright (c) 2026 Desmund Yeng. Licensed under the MIT License. */
/* See LICENSE file in the project root for full license information. */

/* ===== WinUI3-inspired Design System ===== */
:root {
  --bg-solid: #f3f3f3;
  --bg-mica: rgba(243, 243, 243, 0.72);
  --layer-default: #ffffff;
  --layer-alt: #f9f9f9;
  --layer-on-acrylic: rgba(255, 255, 255, 0.7);
  --border-card: rgba(0, 0, 0, 0.0578);
  --border-default: rgba(0, 0, 0, 0.0837);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text-primary: #1a1a1a;
  --text-secondary: #616161;
  --text-tertiary: #9e9e9e;
  --accent: #005fb8;
  --accent-hover: #004c95;
  --accent-light: rgba(0, 95, 184, 0.08);
  --success: #0f7b0f;
  --success-bg: rgba(15, 123, 15, 0.08);
  --danger: #c42b1c;
  --danger-bg: rgba(196, 43, 28, 0.08);
  --warning: #9d5d00;
  --warning-bg: rgba(157, 93, 0, 0.08);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-4: 0 2px 4px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-8: 0 4px 8px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-16: 0 8px 16px rgba(0, 0, 0, 0.06), 0 4px 8px rgba(0, 0, 0, 0.08);
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 4px;
  --radius-xl: 8px;
  --nav-width: 220px;
  --type-http: #005fb8;
  --type-mqtt: #8764b8;
  --type-coap: #00758f;
  --type-ssl: #c27519;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-solid);
  -webkit-font-smoothing: antialiased;
}

/* ===== App Layout ===== */
.app-shell {
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  min-height: 100vh;
}

/* ===== Navigation Rail ===== */
.nav-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 12px;
  background: var(--bg-mica);
  border-right: 1px solid var(--border-card);
  backdrop-filter: blur(20px) saturate(125%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 16px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-card);
  margin-bottom: 8px;
}

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  text-align: left;
  width: 100%;
}

.nav-tab:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-primary);
}

.nav-tab.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.nav-tab.active svg {
  color: var(--accent);
}

/* ===== Content Area ===== */
.content-area {
  padding: 24px 32px 48px;
  min-width: 0;
}

/* ===== Top Bar ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.top-bar h1 {
  font-size: 28px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.top-bar-actions {
  display: flex;
  gap: 8px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, transform 0.08s;
  white-space: nowrap;
  font-family: inherit;
}

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

.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-subtle {
  background: var(--layer-default);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.btn-subtle:hover {
  background: var(--layer-alt);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

.btn-danger:hover {
  background: rgba(196, 43, 28, 0.14);
}

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

/* ===== Summary Bar ===== */
.summary-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 14px 20px;
  margin-bottom: 24px;
  background: var(--layer-default);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  overflow-x: auto;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 20px;
  white-space: nowrap;
}

.summary-item:first-child {
  padding-left: 4px;
}

.summary-item strong {
  font-size: 20px;
  font-weight: 600;
}

.summary-item .summary-text {
  font-size: 13px;
}

.summary-item.item-healthy strong { color: var(--success); }
.summary-item.item-failing strong { color: var(--danger); }
.summary-item.item-unknown strong { color: var(--warning); }

.summary-sep {
  width: 1px;
  height: 32px;
  background: var(--border-default);
  flex-shrink: 0;
}

.summary-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ===== Tabs ===== */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===== Panel ===== */
.panel {
  background: var(--layer-default);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-4);
  padding: 24px;
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.panel-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.panel-divider {
  height: 1px;
  background: var(--border-card);
  margin: 28px 0;
}

/* ===== Forms ===== */
.stack-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

input, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--layer-default);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.field-row {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, 1fr);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  accent-color: var(--accent);
}

.inline-checkbox {
  align-self: end;
  padding-bottom: 4px;
}

.protocol-fields {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--layer-alt);
  border: 1px solid var(--border-card);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hidden { display: none !important; }

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-card);
}

th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--layer-alt);
}

th:first-child { border-radius: var(--radius-md) 0 0 0; }
th:last-child { border-radius: 0 var(--radius-md) 0 0; }

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

tr:hover td {
  background: rgba(0, 0, 0, 0.015);
}

/* ===== Status Pills ===== */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.status-healthy { background: var(--success-bg); color: var(--success); }
.status-failing { background: var(--danger-bg); color: var(--danger); }
.status-unknown { background: var(--warning-bg); color: var(--warning); }

/* ===== Type Badges ===== */
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.type-http { background: rgba(0, 95, 184, 0.1); color: var(--type-http); }
.type-mqtt { background: rgba(135, 100, 184, 0.1); color: var(--type-mqtt); }
.type-coap { background: rgba(0, 117, 143, 0.1); color: var(--type-coap); }
.type-ssl { background: rgba(194, 117, 25, 0.1); color: var(--type-ssl); }

/* ===== Time Ago ===== */
.time-ago {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ===== Interval display ===== */
.interval-text {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-card);
}

.pagination button {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--layer-default);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
  font-family: inherit;
  padding: 0 10px;
}

.pagination button:hover {
  background: var(--layer-alt);
}

.pagination button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ===== Dialog ===== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}

.dialog {
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--layer-default);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-16);
  padding: 28px;
  animation: slideUp 0.2s ease;
}

.dialog-sm {
  max-width: 420px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.dialog-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.dialog-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  transition: background 0.1s;
}

.dialog-close:hover {
  background: rgba(0, 0, 0, 0.06);
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 8px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--text-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-16);
  z-index: 2000;
}

/* ===== Muted text ===== */
.muted { color: var(--text-secondary); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: 64px;
  }

  .nav-rail {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 1px solid var(--border-default);
    z-index: 900;
    background: var(--layer-default);
    backdrop-filter: blur(20px) saturate(125%);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  }

  .nav-brand { display: none; }

  .nav-tabs {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    gap: 0;
  }

  .nav-tab {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    font-size: 10px;
    min-width: 0;
    flex: 1;
    border-radius: var(--radius-md);
  }

  .nav-tab svg {
    width: 20px;
    height: 20px;
  }

  .nav-tab span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 72px;
    text-align: center;
  }

  .content-area {
    padding: 16px 12px 80px;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .top-bar h1 {
    font-size: 22px;
  }

  .top-bar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .summary-bar {
    padding: 10px 12px;
    gap: 0;
  }

  .summary-item {
    padding: 0 12px;
  }

  .summary-item strong {
    font-size: 16px;
  }

  .summary-sep {
    height: 24px;
  }

  .panel {
    padding: 16px;
    border-radius: var(--radius-lg);
  }

  .panel-header {
    flex-direction: column;
    gap: 12px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .dialog {
    width: 95%;
    padding: 20px;
    max-height: 90vh;
    border-radius: var(--radius-lg);
  }

  .table-wrap {
    margin: 0 -16px;
    padding: 0 16px;
  }

  table {
    font-size: 12px;
  }

  th, td {
    padding: 8px 6px;
  }

  .button-row {
    gap: 6px;
  }

  .btn-sm {
    padding: 4px 8px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .top-bar-actions .btn span {
    display: none;
  }

  .pagination button {
    min-width: 28px;
    height: 28px;
    font-size: 12px;
  }
}

/* ===== Info box ===== */
.info-box {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--accent-light);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
}

.info-box strong {
  color: var(--accent);
}

/* ===== Footer ===== */
.app-footer {
  padding: 20px 32px;
  border-top: 1px solid var(--border-card);
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.app-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
