:root {
  --primary-color: #336633;
  --primary-dark: #255425;
  --primary-light: rgba(51, 102, 51, 0.12);
  --secondary-color: #4a90e2;
  --success-color: #67c23a;
  --error-color: #cc0000;
  --warning-color: #e6a23c;
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --border-color: #dddddd;
  --text-color: #333333;
  --text-light: #666666;
  --sidebar-bg: #336633;
  --sidebar-bg-hover: rgba(255, 255, 255, 0.12);
  --sidebar-text: rgba(255, 255, 255, 0.78);
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --gradient: linear-gradient(135deg, #336633 0%, #255425 50%, #4a6e4a 100%);
  --sidebar-width: 230px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text-color);
  background: var(--bg);
}

/* ─── Loading ────────────────────────────────────────────────────── */

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gradient);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Login ──────────────────────────────────────────────────────── */

.login-screen {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
  background: var(--gradient);
}

.login-box {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-brand { text-align: center; }
.login-logo { font-size: 1.5rem; font-weight: 700; color: var(--primary-color); letter-spacing: 0.3px; }
.login-subtitle { font-size: 0.85rem; color: var(--text-light); margin-top: 2px; }

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-box input {
  padding: 11px 14px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 0.95rem;
}
.login-box input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.login-box button[type="submit"] {
  padding: 11px 14px;
  border: none;
  border-radius: 12px;
  background: var(--primary-color);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.login-box button[type="submit"]:hover { background: var(--primary-dark); }

.login-error {
  color: var(--error-color);
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* ─── App shell (sidebar + content) ─────────────────────────────── */

.main-app { display: none; }
.main-app.authenticated { display: block; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar-logo { font-size: 1.2rem; font-weight: 700; color: #fff; letter-spacing: 0.3px; }
.sidebar-subtitle { font-size: 0.75rem; color: var(--sidebar-text); margin-top: 2px; }

.nav-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: var(--sidebar-bg-hover); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, 0.18); color: #fff; }
.nav-item.active .nav-icon { opacity: 1; }

/* ─── Main area / topbar ─────────────────────────────────────────── */

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.mobile-nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.mobile-nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--text-color);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--error-color);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--success-color); }

.dry-run-badge {
  display: none;
  background: var(--warning-color);
  color: #fff;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
}
.dry-run-badge.visible { display: inline-block; }

.topbar-service {
  display: flex;
  align-items: center;
  gap: 14px;
}

.account-menu {
  position: relative;
}

.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(16, 24, 20, 0.45);
}

.mobile-nav-overlay.active { display: block; }

.mobile-nav-panel {
  width: min(320px, calc(100vw - 32px));
  height: 100%;
  padding: 20px 16px 16px;
  background: var(--sidebar-bg);
  color: #fff;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mobile-nav-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.mobile-nav-close {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.mobile-nav-user {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.78);
  word-break: break-all;
}

.mobile-nav-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mobile-nav-item {
  width: 100%;
  color: #fff;
}

.mobile-logout-btn {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  width: 100%;
}

.mobile-logout-btn:hover,
.mobile-nav-close:hover { background: rgba(255, 255, 255, 0.14); }

.account-menu-btn {
  max-width: 240px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #fff;
  color: var(--text-color);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: left;
}
.account-menu-btn:hover { background: var(--bg); }

#accountMenuLabel {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
}
.account-dropdown.active { display: block; }

.account-dropdown-item {
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-color);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: left;
}
.account-dropdown-item:hover { background: var(--bg); }
.account-dropdown-item:disabled {
  color: var(--text-light);
  cursor: not-allowed;
}

.clock { font-variant-numeric: tabular-nums; color: var(--text-light); font-size: 0.9rem; }

.service-status-text {
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
}
.service-status-text.active { background: rgba(103, 194, 58, 0.12); color: var(--success-color); }
.service-status-text.stopped { background: rgba(204, 0, 0, 0.1); color: var(--error-color); }

.uptime { font-variant-numeric: tabular-nums; color: var(--text-light); font-size: 0.85rem; }

.service-toggle {
  padding: 8px 22px;
  border: none;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  color: #fff;
}
.service-toggle.start { background: var(--success-color); }
.service-toggle.stop { background: var(--error-color); }
.service-toggle:disabled { background: var(--border-color); cursor: not-allowed; }

/* ─── Config warning ─────────────────────────────────────────────── */

.config-warning {
  display: none;
  background: rgba(230, 162, 60, 0.12);
  color: #95650f;
  padding: 10px 24px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

/* ─── Content / pages ────────────────────────────────────────────── */

.content {
  padding: 24px;
  flex: 1;
}

.page { display: none; }
.page.active { display: block; }

.page-header { margin-bottom: 18px; }
.page-title { margin: 0; font-size: 1.35rem; font-weight: 700; }

.page-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 720px;
}

.errors-page-content {
  max-width: none;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  grid-auto-flow: row dense;
  max-width: 1200px;
}

.action-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.action-group--wide {
  grid-column: 1 / -1;
}

.page-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-label {
  margin: 4px 0 -6px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
}

/* ─── Action lists ───────────────────────────────────────────────── */

.action-list {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.action-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}
.action-item:last-child { border-bottom: none; }

.action-item-info { min-width: 0; }
.action-item-title { font-weight: 600; font-size: 0.95rem; }
.action-item-desc { margin-top: 2px; font-size: 0.82rem; color: var(--text-light); }

.action-item-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ntp-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

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

.ntp-clock-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ntp-clock-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border-color);
}

.ntp-clock-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-light);
}

.ntp-live-clock {
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-color);
}

.ntp-live-clock.secondary {
  color: var(--text-light);
}

.ntp-live-date {
  font-size: 0.85rem;
  color: var(--text-light);
}

.ntp-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ntp-meta-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border-color);
}

.ntp-meta-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
}

.ntp-meta-value {
  font-size: 0.92rem;
  color: var(--text-color);
  word-break: break-word;
}

@media (max-width: 860px) {
  .ntp-clock-grid,
  .ntp-meta-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Grid / panels ──────────────────────────────────────────────── */

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

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-wide { grid-column: 1 / -1; }

.panel h2 {
  margin: 0 0 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text-color);
}

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

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

.panel-subtitle {
  font-size: 0.82rem;
  color: var(--text-light);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(230, 162, 60, 0.14);
  color: #95650f;
  font-size: 0.8rem;
  font-weight: 600;
}

label { font-size: 0.85rem; color: var(--text-light); }

.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }

input[type="text"], input[type="number"], input[type="email"], input[type="password"] {
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.95rem;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}
input[type="text"]:disabled, input[type="number"]:disabled, input[type="email"]:disabled, input[type="password"]:disabled {
  background: var(--bg);
  color: var(--text-light);
  cursor: not-allowed;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-color);
  font-size: 0.9rem;
}

.button-small {
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
.button-small:hover { background: var(--bg); }
.button-small:disabled { opacity: 0.6; cursor: not-allowed; }

.warning-btn { border-color: var(--warning-color); color: #95650f; }
.warning-btn:hover { background: rgba(230, 162, 60, 0.1); }

.danger-btn { border-color: var(--error-color); color: var(--error-color); }
.danger-btn:hover { background: rgba(204, 0, 0, 0.08); }

.button-small.active {
  background: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
}
.button-small.active:hover { background: var(--primary-dark); }

.test-result {
  display: none;
  padding: 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.test-result.success { display: block; background: rgba(103, 194, 58, 0.12); color: var(--success-color); }
.test-result.error { display: block; background: rgba(204, 0, 0, 0.08); color: var(--error-color); }

.device-id {
  font-size: 0.8rem;
  color: var(--text-light);
  word-break: break-all;
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  text-align: center;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 6px;
}

.stat-value { font-size: 1.3rem; font-weight: 700; }
.stat-label { font-size: 0.7rem; color: var(--text-light); }

#failedCount.has-errors { color: var(--error-color); }

.endpoint-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.endpoint-card {
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: bold;
  background: var(--bg);
  color: var(--text-light);
}
.endpoint-card span { font-size: 0.75rem; font-weight: normal; }
.endpoint-card.ok { background: rgba(103, 194, 58, 0.12); color: var(--success-color); }
.endpoint-card.error { background: rgba(204, 0, 0, 0.08); color: var(--error-color); }
.endpoint-card.disabled { background: var(--bg); color: var(--text-light); }

.class-counters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.class-counter-badge {
  background: var(--bg);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* ─── Server charts ──────────────────────────────────────────────── */

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

.chart-box {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 6px;
}

.chart-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-color);
}

.chart-sub {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-light);
  opacity: 0.7;
}

.chart-canvas {
  display: block;
  width: 100%;
  height: 80px;
}

.server-meta {
  display: flex;
  gap: 24px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-light);
}

/* ─── Actions / import ───────────────────────────────────────────── */

.import-status {
  font-size: 0.8rem;
  color: var(--text-light);
  min-height: 1.2em;
}
.import-status.loading { color: var(--secondary-color); }
.import-status.ok { color: var(--success-color); }
.import-status.error { color: var(--error-color); }

/* ─── Scroll lists (queue / log / failed) ───────────────────────── */

.scroll-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.85rem;
}

.empty {
  padding: 12px;
  color: var(--text-light);
  text-align: center;
}

.list-item {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-color);
}
.list-item:last-child { border-bottom: none; }
.list-item.processing { background: rgba(74, 144, 226, 0.1); }
.list-item.success { color: var(--success-color); }
.list-item.error { color: var(--error-color); }
.list-item.warning { color: #95650f; }

.fai-time { font-size: 0.7rem; color: var(--text-light); }

/* ─── Console / logging page ────────────────────────────────────── */

.console {
  max-height: 70vh;
  min-height: 320px;
  overflow-y: auto;
  background: #1e1e1e;
  border-radius: 8px;
  padding: 8px 4px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.8rem;
  line-height: 1.4;
}

.console .list-item {
  padding: 1px 8px;
  border-bottom: none;
  color: #d4d4d4;
  white-space: pre-wrap;
  word-break: break-word;
}
.console .list-item.success { color: #6fcf6f; }
.console .list-item.error { color: #ff6b6b; }
.console .list-item.warning { color: #e6c46a; }
.console .empty { color: var(--text-light); background: transparent; }

.remote-failed-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 420px));
  gap: 8px;
}

.remote-failed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--error-color);
  border-radius: 8px;
  background: var(--card-bg);
  min-width: 0;
}

.remote-failed-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.remote-failed-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.remote-failed-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-color);
}

.remote-failed-meta {
  font-size: 0.76rem;
  color: var(--text-light);
  white-space: nowrap;
  flex-shrink: 0;
}

.remote-failed-details {
  font-size: 0.8rem;
  color: var(--text-light);
}

.remote-failed-actions {
  flex-shrink: 0;
}

.remote-failed-payload summary {
  cursor: pointer;
  font-size: 0.76rem;
  color: var(--secondary-color);
}

.remote-failed-payload pre {
  margin: 6px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: #1e1e1e;
  color: #d4d4d4;
  font-size: 0.78rem;
  overflow-x: auto;
}

.local-failed-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 360px));
  gap: 8px;
}

.local-failed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--warning-color);
  border-radius: 8px;
  background: var(--card-bg);
  min-width: 0;
}

.local-failed-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.local-failed-title {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.local-failed-error {
  font-size: 0.76rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.local-failed-actions {
  flex-shrink: 0;
}

/* ─── Modals ─────────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(16, 24, 20, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header { font-size: 1.1rem; font-weight: bold; color: var(--primary-color); }
.modal-header.is-danger { color: var(--error-color); }

.modal-desc { font-size: 0.9rem; }

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.password-rules {
  font-size: 0.8rem;
  color: var(--text-light);
}

.confirm-modal-warning {
  display: none;
  font-size: 0.85rem;
  background: rgba(230, 162, 60, 0.15);
  color: #95650f;
  padding: 8px;
  border-radius: 6px;
}
.confirm-modal-warning.is-danger { background: rgba(204, 0, 0, 0.08); color: var(--error-color); }

.modal-status {
  font-size: 0.85rem;
  min-height: 1.2em;
}
.modal-status.ok { color: var(--success-color); }
.modal-status.error { color: var(--error-color); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 960px) {
  .app-shell { flex-direction: column; }

  .sidebar { display: none; }
  .mobile-nav-toggle { display: inline-flex; }

  .topbar {
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
  }

  .topbar-status {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 6px;
  }

  .topbar-service {
    width: 100%;
    flex-wrap: wrap;
    justify-content: space-between;
    padding-left: 0;
    gap: 10px;
  }

  .account-menu {
    margin-left: auto;
  }

  .grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .server-meta { gap: 16px; flex-wrap: wrap; }
  .content { padding: 16px; }
  .input-row { flex-direction: column; }
  .input-row input { width: 100%; }
  .topbar-service {
    align-items: center;
  }
  .account-menu-btn {
    max-width: min(48vw, 220px);
  }

  .action-item {
    flex-direction: column;
    align-items: stretch;
  }
  .action-item-controls {
    justify-content: flex-start;
  }
  .panel-header-inline,
  .remote-failed-item,
  .local-failed-item {
    flex-direction: column;
  }
  .panel-header-actions,
  .remote-failed-actions,
  .local-failed-actions {
    width: 100%;
  }
}
