:root {
  --ink: #2a241c;
  --ink-soft: #5a5146;
  --muted: #7a7166;
  --paper: #f4efe6;
  --paper-strong: rgba(248, 244, 236, 0.88);
  --panel: rgba(255, 252, 246, 0.82);
  --line: rgba(70, 58, 42, 0.16);
  --accent: #8a5a22;
  --accent-deep: #6b4316;
  --accent-soft: rgba(138, 90, 34, 0.12);
  --warn: #b8860b;
  --danger: #a94438;
  --ok: #3d6b4f;
  --sidebar: rgba(250, 246, 238, 0.92);
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 16px;
  --sidebar-w: 260px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--mono);
}

.muted {
  color: var(--muted);
}

.blueprint-bg,
.blueprint-wash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.blueprint-bg {
  background-image: url("assets/planta.png");
  background-size: cover;
  background-position: center 30%;
  background-repeat: no-repeat;
  filter: grayscale(0.35) contrast(0.95) brightness(1.08);
  opacity: 0.42;
}

.blueprint-wash {
  background:
    linear-gradient(180deg, rgba(248, 244, 236, 0.52) 0%, rgba(244, 239, 230, 0.58) 45%, rgba(240, 234, 222, 0.64) 100%),
    radial-gradient(ellipse 70% 50% at 80% 10%, rgba(138, 90, 34, 0.06), transparent 55%);
}

.page-login,
.page-app {
  position: relative;
  min-height: 100vh;
}

.page-login .login-shell,
.page-app .app-shell {
  position: relative;
  z-index: 1;
}

.brand,
.brand-title,
.page-title {
  font-family: var(--display);
  letter-spacing: -0.02em;
}

/* —— Login —— */
.page-login {
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}

.login-shell {
  width: min(100%, 420px);
  animation: rise 0.55s ease-out both;
}

.login-brand {
  margin-bottom: 1.5rem;
}

.brand {
  margin: 0;
  font-size: clamp(1.55rem, 3.4vw, 2.05rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
}

.login-sub,
.page-lead {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.login-form,
.panel-block,
.metric,
.ssl-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field input {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  padding: 0.75rem 0.9rem;
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus {
  border-color: rgba(138, 90, 34, 0.55);
  box-shadow: 0 0 0 3px rgba(138, 90, 34, 0.12);
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.btn-primary,
.btn-ghost,
.btn-menu {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  border: none;
  background: linear-gradient(180deg, #9a682c 0%, var(--accent-deep) 100%);
  color: #fff8ef;
  font-weight: 700;
  padding: 0.8rem 1.1rem;
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.btn-ghost,
.btn-menu {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-ghost:hover,
.btn-menu:hover {
  color: var(--ink);
  border-color: rgba(70, 58, 42, 0.28);
}

/* —— App shell / menu —— */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.4rem 1.1rem;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.sidebar-brand {
  padding: 0.25rem 0.4rem 0.5rem;
}

.brand-mark {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent-deep);
  line-height: 1;
}

.brand-title {
  margin: 0.4rem 0 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-link {
  display: block;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-deep);
  border-color: rgba(138, 90, 34, 0.18);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.user-chip {
  font-size: 0.82rem;
  color: var(--muted);
}

.app-main {
  min-width: 0;
  padding: 1.25rem clamp(1rem, 3vw, 2rem) 2.5rem;
}

.app-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
  animation: rise 0.45s ease-out both;
}

.btn-menu {
  display: none;
}

.page-title {
  margin: 0;
  font-size: clamp(1.45rem, 2.6vw, 1.9rem);
  font-weight: 700;
  color: var(--ink);
}

.host-line {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.page-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 1100px;
}

.panel-block {
  padding: 1.25rem 1.35rem 1.4rem;
  animation: rise 0.55s ease-out both;
}

.block-heading {
  margin: 0 0 0.55rem;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.section-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.certs-board .block-heading {
  margin-bottom: 0.25rem;
}

.certs-board td.is-ok {
  color: var(--ok);
  font-weight: 600;
}

.certs-board td.is-warn {
  color: #9a6b10;
  font-weight: 700;
}

.certs-board td.is-danger {
  color: var(--danger);
  font-weight: 700;
}

.certs-board .ssl-progress {
  margin-top: 0.85rem;
}

.block-text {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.action-row {
  margin-top: 1.1rem;
}

/* —— Metrics —— */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.metric {
  padding: 1.2rem 1.25rem 1.3rem;
  animation: rise 0.55s ease-out both;
}

.metric[data-metric="cpu"] { animation-delay: 0.05s; }
.metric[data-metric="memory"] { animation-delay: 0.12s; }
.metric[data-metric="disk"] { animation-delay: 0.19s; }

.metric-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metric-head h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric-value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--ink);
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(70, 58, 42, 0.08);
  overflow: hidden;
  border: 1px solid rgba(70, 58, 42, 0.08);
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-deep), #c08a45);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s ease;
}

.meter-fill.level-warn {
  background: linear-gradient(90deg, #8a6a10, var(--warn));
}

.meter-fill.level-danger {
  background: linear-gradient(90deg, #7a3228, var(--danger));
}

.metric-meta {
  margin: 0.85rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--mono);
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
  animation: rise 0.6s ease-out 0.25s both;
}

.status-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.status-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-value {
  font-size: 0.95rem;
  color: var(--ink);
}

/* —— Backups table —— */
.table-wrap {
  margin-top: 0.85rem;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.45);
}

.name-cell {
  word-break: break-all;
}

.ha-server-block {
  margin-top: 1.4rem;
}

.ha-server-block:first-child {
  margin-top: 0.6rem;
}

.ha-server-block .block-heading {
  margin-bottom: 0.15rem;
}

.actions-cell {
  text-align: right;
  white-space: nowrap;
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn-download,
.btn-danger {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.btn-danger {
  color: #8a1f1f;
  border-color: rgba(138, 31, 31, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(138, 31, 31, 0.08);
}

/* —— SSL —— */
.ssl-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 1.25rem;
}

.ssl-status {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.45);
}

.ssl-status-line {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.ssl-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ssl-fieldset {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.35);
}

.ssl-fieldset legend {
  padding: 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: 0.55rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.check input {
  margin-top: 0.2rem;
  accent-color: var(--accent);
}

.field-inline {
  max-width: 180px;
}

.ssl-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.ssl-hint.ssl-warn {
  color: #8a3b12;
  background: rgba(255, 196, 120, 0.28);
  border: 1px solid rgba(180, 90, 30, 0.28);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
}

.field-help {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.field-help code,
.ssl-fieldset code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85em;
}

.ssl-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ssl-progress {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.45);
}

.ssl-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.ssl-progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(70, 58, 42, 0.1);
  overflow: hidden;
  border: 1px solid rgba(70, 58, 42, 0.08);
}

.ssl-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-deep), #c08a45);
  transition: width 0.35s ease;
}

.ssl-msg {
  margin: 0;
  font-size: 0.92rem;
}

.ssl-msg.is-ok {
  color: var(--ok);
}

.ssl-msg.is-err {
  color: var(--danger);
}

.ssl-log {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* —— Omada —— */
.omada-top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.omada-config-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.omada-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}

.omada-config-grid .field input {
  width: 100%;
}

.omada-msg {
  margin: 0;
  font-size: 0.92rem;
}

.omada-msg.is-ok {
  color: var(--ok);
}

.omada-msg.is-err {
  color: var(--danger);
}

.omada-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0;
}

.omada-tab {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.omada-tab:hover {
  color: var(--ink);
}

.omada-tab.is-active {
  color: var(--accent-deep);
  border-bottom-color: var(--accent-deep);
}

.tab-count {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85em;
}

.omada-toolbar {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.omada-search {
  flex: 1 1 240px;
  max-width: 340px;
}

.omada-sort select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  padding: 0.6rem 2rem 0.6rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235a5146' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

.omada-sort select:focus,
.omada-search input:focus {
  border-color: rgba(138, 90, 34, 0.55);
  box-shadow: 0 0 0 3px rgba(138, 90, 34, 0.12);
}

.status-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.status-connected {
  color: var(--ok);
  background: rgba(61, 107, 79, 0.12);
  border: 1px solid rgba(61, 107, 79, 0.28);
}

.status-pill.status-disconnected {
  color: var(--danger);
  background: rgba(169, 68, 56, 0.1);
  border: 1px solid rgba(169, 68, 56, 0.28);
}

.status-pill.status-pending,
.status-pill.status-heartbeat,
.status-pill.status-isolated {
  color: #8a6a10;
  background: rgba(184, 134, 11, 0.12);
  border: 1px solid rgba(184, 134, 11, 0.3);
}

@media (max-width: 720px) {
  .omada-config-grid {
    grid-template-columns: 1fr;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 280px);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 12px 0 40px rgba(42, 36, 28, 0.12);
  }

  .app-shell.nav-open .sidebar {
    transform: translateX(0);
  }

  .btn-menu {
    display: inline-flex;
    margin-right: 0.25rem;
  }

  .app-top {
    flex-wrap: wrap;
  }

  .metrics,
  .status-row,
  .ssl-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
