@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=DM+Mono:wght@400;500&display=swap');

:root {
    --bg: #0e1519;
    --bg-soft: #111b20;
    --panel: #f5f2ec;
    --panel-dark: #1d2b30;
    --accent: #e68a2e;
    --accent-2: #47b39c;
    --ink: #142329;
    --ink-light: #f7f1e6;
    --muted: rgba(20, 35, 41, 0.6);
    --shadow: 0 20px 45px rgba(10, 18, 22, 0.35);
    --radius: 18px;

    /* theme mapping */
    --page-bg: radial-gradient(circle at 10% 20%, rgba(71, 179, 156, 0.25), transparent 55%),
        radial-gradient(circle at 85% 15%, rgba(230, 138, 46, 0.35), transparent 50%),
        linear-gradient(120deg, #f7f1e6 0%, #eef3f0 40%, #cfe7e0 100%);
    --surface: var(--panel);
    --surface-2: rgba(255, 255, 255, 0.6);
    --surface-3: rgba(255, 255, 255, 0.82);
    --text: var(--ink);
    --success: #0f7a43;
    --danger: #b42318;
    --info: #155eef;
    --text-muted: var(--muted);
    --nav-surface: rgba(245, 242, 236, 0.9);
    --border: rgba(20, 35, 41, 0.1);
    --chip-bg: rgba(20, 35, 41, 0.1);
}

.theme-dark {
    --page-bg: radial-gradient(circle at 10% 20%, rgba(71, 179, 156, 0.15), transparent 55%),
        radial-gradient(circle at 85% 15%, rgba(230, 138, 46, 0.18), transparent 50%),
        linear-gradient(120deg, #0b1013 0%, #0e1519 45%, #0b1614 100%);
    --surface: #0f181c;
    --surface-2: rgba(15, 24, 28, 0.72);
    --surface-3: rgba(247, 241, 230, 0.08);
    --text: #f7f1e6;
    --text-muted: rgba(247, 241, 230, 0.68);
    --nav-surface: rgba(15, 24, 28, 0.82);
    --border: rgba(247, 241, 230, 0.12);
    --chip-bg: rgba(247, 241, 230, 0.1);
}

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

body {
    font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
    color: var(--text);
    background: var(--page-bg);
    min-height: 100vh;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(rgba(20, 35, 41, 0.08) 1px, transparent 1px);
    background-size: 22px 22px;
    pointer-events: none;
    opacity: 0.5;
}

.theme-dark body::before {
    background-image: radial-gradient(rgba(247, 241, 230, 0.06) 1px, transparent 1px);
    opacity: 0.35;
}

a {
    color: inherit;
    text-decoration: none;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 1.5rem 6vw 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    background: var(--nav-surface);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.nav {
    display: flex;
    gap: 1.25rem;
    font-weight: 600;
    align-items: center;
}

.nav a {
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    transition: all 0.2s ease;
}

.nav a:hover {
    background: var(--panel-dark);
    color: var(--ink-light);
}

.pill {
    font-family: "DM Mono", "Courier New", monospace;
    font-size: 0.85rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    background: rgba(29, 43, 48, 0.9);
    color: var(--ink-light);
}

.main {
    flex: 1;
    padding: 3.5rem 6vw 4rem;
    display: grid;
    gap: 2rem;
}

.hero {
    display: grid;
    gap: 1rem;
    max-width: 780px;
}

.hero h1 {
    font-size: clamp(2.2rem, 4vw, 3.6rem);
    line-height: 1.05;
}

.hero p {
    color: var(--muted);
    font-size: 1.05rem;
}

.grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: grid;
    gap: 0.75rem;
}

.card h3 {
    font-size: 1.15rem;
}

.card p {
    color: var(--muted);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 3rem 1.5rem;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    display: grid;
    gap: 1.25rem;
}

.auth-card h1 {
    font-size: 2rem;
}

.field {
    display: grid;
    gap: 0.35rem;
}

.field label {
    font-weight: 600;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    border: 1px solid rgba(20, 35, 41, 0.2);
    border-radius: 12px;
    padding: 0.72rem 0.9rem;
    font-size: 1rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.field textarea {
    min-height: 120px;
    resize: vertical;
}

.theme-dark .field input,
.theme-dark .field select,
.theme-dark .field textarea {
    background: rgba(247, 241, 230, 0.08);
    border-color: rgba(247, 241, 230, 0.22);
    color: var(--text);
}

.password-field {
    position: relative;
    display: flex;
    align-items: center;
}

.password-field input {
    width: 100%;
    padding-right: 3rem;
}

.eye-button {
    position: absolute;
    right: 0.5rem;
    border: none;
    background: rgba(20, 35, 41, 0.08);
    color: var(--ink);
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.eye-button:hover {
    background: rgba(20, 35, 41, 0.16);
    transform: scale(1.02);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid rgba(230, 138, 46, 0.4);
    border-color: rgba(230, 138, 46, 0.4);
}

.button {
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.78rem 1.5rem;
    font-weight: 700;
    cursor: pointer;
    background: var(--panel-dark);
    color: var(--ink-light);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.button:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 25px rgba(16, 24, 29, 0.2);
}

.button.secondary {
    background: var(--accent-2);
    color: #08231c;
}

.button.ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.helper-text {
    font-size: 0.95rem;
    color: var(--text-muted);
}


.toast-stack {
    position: fixed;
    top: 1.2rem;
    right: 1.2rem;
    display: grid;
    gap: 0.75rem;
    z-index: 3000;
    width: min(360px, calc(100vw - 2rem));
}

.toast-message {
    padding: 0.95rem 1rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 14px 30px rgba(16, 24, 29, 0.18);
    font-size: 0.95rem;
    line-height: 1.45;
    animation: toastIn 0.18s ease;
}

.toast-message.ok,
.toast-message.success {
    color: var(--success);
    border-color: rgba(15, 122, 67, 0.28);
    background: rgba(15, 122, 67, 0.08);
}

.toast-message.bad,
.toast-message.error {
    color: var(--danger);
    border-color: rgba(180, 35, 24, 0.28);
    background: rgba(180, 35, 24, 0.08);
}

.toast-message.info,
.toast-message.loading {
    color: var(--info);
    border-color: rgba(21, 94, 239, 0.24);
    background: rgba(21, 94, 239, 0.08);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.status-message {
    min-height: 1.4rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.status-message.ok,
.status-message.success {
    color: var(--success);
}

.status-message.bad,
.status-message.error {
    color: var(--danger);
}

.status-message.info {
    color: var(--info);
}

.modal-status,
.inline-status {
    min-height: 1.4rem;
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.95rem;
    color: var(--text-muted);
}

.modal-status[hidden],
.inline-status[hidden] {
    display: none !important;
}

.modal-status.ok,
.inline-status.ok {
    color: var(--success);
    border-color: rgba(15, 122, 67, 0.28);
    background: rgba(15, 122, 67, 0.08);
}

.modal-status.bad,
.inline-status.bad {
    color: var(--danger);
    border-color: rgba(180, 35, 24, 0.28);
    background: rgba(180, 35, 24, 0.08);
}

.modal-status.info,
.inline-status.info {
    color: var(--info);
    border-color: rgba(21, 94, 239, 0.24);
    background: rgba(21, 94, 239, 0.08);
}

.auth-help-box {
    margin-top: 0.9rem;
    padding: 0.95rem 1rem;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.92rem;
    line-height: 1.55;
}


.dashboard {
    display: grid;
    gap: 2rem;
}

.dashboard-hero {
    display: grid;
    gap: 1.5rem;
    align-items: start;
    grid-template-columns: 1.2fr 0.8fr;
}

.dashboard-hero-left {
    display: grid;
    gap: 0.85rem;
}

.dashboard-hero-left h1 {
    font-size: clamp(2rem, 3.5vw, 3.2rem);
    line-height: 1.05;
}

.dashboard-hero-left .helper-text {
    max-width: 720px;
}

.status-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem;
    display: grid;
    gap: 1rem;
    border: 1px solid var(--border);
}

.status-row,
.theme-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.status-label {
    font-weight: 700;
    letter-spacing: 0.02em;
}

.status-badge {
    font-family: "DM Mono", "Courier New", monospace;
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.status-badge[data-state="connected"],
.status-badge[data-state="subscribed"] {
    border-color: rgba(71, 179, 156, 0.55);
}

.status-badge[data-state="error"],
.status-badge[data-state="subscribe_error"] {
    border-color: rgba(200, 70, 70, 0.55);
}

.status-hint {
    font-size: 0.92rem;
    color: var(--text-muted);
    line-height: 1.25;
    min-height: 2.2rem;
}

.status-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.switch {
    position: relative;
    display: inline-block;
    width: 54px;
    height: 30px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(20, 35, 41, 0.18);
    border-radius: 999px;
    transition: 0.2s ease;
    border: 1px solid var(--border);
}

.slider:before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface);
    border-radius: 50%;
    transition: 0.2s ease;
    box-shadow: 0 6px 16px rgba(10, 18, 22, 0.25);
}

.switch input:checked + .slider {
    background: rgba(71, 179, 156, 0.35);
}

.switch input:checked + .slider:before {
    transform: translate(24px, -50%);
}

.kpi-grid {
    display: grid;
    gap: 1.2rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kpi {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem;
    display: grid;
    gap: 0.55rem;
    border: 1px solid var(--border);
}

.kpi-title {
    font-weight: 700;
}

.kpi-value {
    font-family: "DM Mono", "Courier New", monospace;
    font-size: 2.2rem;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.kpi-unit {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.kpi-sub {
    font-size: 0.95rem;
    color: var(--text-muted);
}

.dashboard-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1.15fr 0.85fr;
}

.panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    display: grid;
    gap: 0.85rem;
    border: 1px solid var(--border);
}

.panel-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.panel-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.panel-note {
    font-size: 0.92rem;
    color: var(--text-muted);
}

.panel-body {
    background: var(--surface-2);
    border: 1px dashed rgba(20, 35, 41, 0.22);
    border-radius: 14px;
    padding: 0.9rem;
}

.theme-dark .panel-body {
    border-color: rgba(247, 241, 230, 0.18);
}

.plot {
    width: 100%;
    min-height: 280px;
}

.gauge-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.frame-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.frame {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 1.4rem;
    box-shadow: var(--shadow);
    display: grid;
    gap: 1rem;
}

.frame-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.frame-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.frame-body {
    border: 1px dashed rgba(20, 35, 41, 0.2);
    border-radius: 14px;
    padding: 1.2rem;
    display: grid;
    gap: 0.6rem;
    background: rgba(255, 255, 255, 0.6);
}

.temperature-preview {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    font-family: "DM Mono", "Courier New", monospace;
}

.temperature-value {
    font-size: 2.6rem;
    font-weight: 600;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.chip {
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: var(--chip-bg);
    font-size: 0.85rem;
}

.footer {
    padding: 1.5rem 6vw 2.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

@media (max-width: 720px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .nav {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .main {
        padding: 2.5rem 6vw 3.5rem;
    }
}

@media (max-width: 980px) {
    .dashboard-hero {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .plot {
        min-height: 260px;
    }
}

/* ===== MQTT dashboard additions (log + status lines) ===== */
.status-lines {
    display: grid;
    gap: 0.55rem;
    margin-top: 1.25rem;
    max-width: 520px;
}

.status-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1rem;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.status-line code {
    font-family: "DM Mono", "Courier New", monospace;
    font-size: 0.9rem;
    padding: 0.15rem 0.45rem;
    border-radius: 10px;
    background: var(--chip-bg);
}

.status-value {
    font-family: "DM Mono", "Courier New", monospace;
    color: var(--text-muted);
}

.status-error {
    font-family: "DM Mono", "Courier New", monospace;
    font-size: 0.9rem;
    color: rgba(170, 30, 30, 0.95);
    padding: 0.25rem 0.1rem;
}

.live-log {
    height: min(52vh, 520px);
    overflow: auto;
    border-radius: 16px;
    padding: 1rem;
    background: rgba(15, 24, 28, 0.06);
    border: 1px solid var(--border);
    font-family: "DM Mono", "Courier New", monospace;
    font-size: 0.9rem;
    line-height: 1.35;
    white-space: pre-wrap;
}

.theme-dark .live-log {
    background: rgba(247, 241, 230, 0.06);
}


/* ===== Dashboard layout (sketch-based) ===== */

.nav .profile-btn {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.nav .profile-btn .pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dashboard-top {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
  align-items: stretch;
  margin-top: 18px;
}

@media (max-width: 980px) {
  .dashboard-top {
    grid-template-columns: 1fr;
  }
}

.sensor-panel .panel-body {
  padding-top: 10px;
}

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

.sensor-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 14px;
  box-shadow: var(--shadow-soft);
}

.sensor-card.add-card {
  opacity: 0.7;
  text-align: center;
}

.sensor-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.sensor-name {
  font-weight: 700;
  letter-spacing: 0.2px;
}

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

.sensor-values {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 520px) {
  .sensor-values {
    grid-template-columns: 1fr;
  }
}

.sv {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 10px;
  background: var(--surface-2);
}

.sv-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sv-value {
  font-size: 20px;
  font-weight: 700;
}

.add-plus {
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  margin-top: 4px;
}

.add-text {
  font-weight: 700;
  margin-top: 10px;
}

.add-note {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 18px;
}

.panel-chart .plot {
  min-height: 360px;
}

.panel-log .panel-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title badge"
    "note badge";
  align-items: center;
  gap: 6px 12px;
}

.panel-log .panel-title { grid-area: title; }
.panel-log .panel-note { grid-area: note; }
.panel-log #modeBadge { grid-area: badge; justify-self: end; }

.mode-hint {
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Profile panel ===== */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
}

.profile-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  z-index: 50;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.profile-section {
  padding-top: 14px;
}

.profile-section h3 {
  margin: 8px 0 10px 0;
  font-size: 16px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.setting-title {
  font-weight: 700;
}

.setting-note {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.profile-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
}

.helper-credentials{margin-top:12px;color:var(--text-muted);}

/* ===== Dashboard v2 layout (10) ===== */

.nav-right { display: flex; align-items: center; gap: 12px; }

.profile-btn { border: 0; background: transparent; padding: 0; cursor: pointer; }
.profile-btn .pill { cursor: pointer; }

.user-menu { position: relative; display: inline-flex; align-items: center; }
.user-bubble {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 290px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 45px rgba(0,0,0,.12);
  padding: 14px;
  display: none;
  z-index: 40;
}
.user-menu.open .user-bubble,
.user-bubble.open { display: block; }

.bubble-title { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.bubble-items { display: grid; gap: 8px; }
.bubble-link {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.bubble-link:hover { background: var(--surface-3); }
.bubble-divider { height: 1px; background: var(--border); margin: 12px 0; }
.bubble-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.bubble-strong { font-weight: 700; font-size: 13px; }
.bubble-note { font-size: 12px; color: var(--muted); margin-top: 2px; }

.bubble-link-anchor {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.bubble-link-danger {
  color: var(--danger);
}

.panel-header-with-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.button.subtle {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.profile-section-panel[hidden] {
  display: none !important;
}

.profile-card {
  scroll-margin-top: 110px;
}

.profile-card.is-targeted {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(71, 179, 156, 0.14);
}

@media (max-width: 820px) {
  .panel-header-with-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .panel-header-with-actions .button {
    width: 100%;
  }
}

.dashboard-top {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 18px;
  align-items: start;
  margin-top: 16px;
}

@media (max-width: 980px) {
  .dashboard-top { grid-template-columns: 1fr; }
}

.status-lines { margin-top: 12px; display: grid; gap: 8px; }
.status-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.status-label { font-size: 13px; color: var(--muted); min-width: 160px; }
.status-value { font-size: 13px; }
.status-error { color: var(--danger); font-size: 13px; }

.sensor-panel .panel-body { padding-top: 10px; }

.devices-grid {
  display: grid;
  /* Cieľ: aby sa do bloku "Zariadenia" vizuálne zmestili maximálne 3 väčšie karty vedľa seba. */
  grid-template-columns: repeat(3, minmax(280px, 1fr));
  gap: 16px;
}

@media (max-width: 980px) {
  .devices-grid { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
}

@media (max-width: 720px) {
  .devices-grid { grid-template-columns: 1fr; }
}

.device-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-2);
  padding: 16px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.device-card:hover { transform: translateY(-1px); }
.device-card.active { border-color: var(--accent); background: var(--surface-3); }

.device-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.device-title {
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
}

.device-gear {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.device-body {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 12px;
  align-items: center;
}

.device-circle {
  width: 68px;
  height: 68px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  background: var(--surface);
}
.device-circle .circle-value { font-weight: 900; font-size: 18px; }
.device-circle .circle-unit { font-size: 11px; color: var(--muted); margin-top: 2px; }

.device-lines { display: grid; gap: 10px; }
.device-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.device-line .k { font-size: 12px; color: var(--muted); }
.device-line .v { font-weight: 800; }
.device-divider { height: 1px; background: var(--border); }

.add-card {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 156px;
  background: var(--surface);
}
.add-card .add-plus {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 1px dashed var(--border);
  display: grid;
  place-items: center;
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
}
.add-card .add-text { font-weight: 800; }
.add-card .add-note { font-size: 12px; color: var(--muted); text-align: center; }

.dashboard-layout-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
  margin-top: 18px;
}

@media (max-width: 980px) {
  .dashboard-layout-2col { grid-template-columns: 1fr; }
}

.live-log {
  margin: 0;
  background: var(--surface-3);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 12px;
  max-height: 520px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.status-badge {
  margin-left: auto;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 28px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 55px rgba(0,0,0,.18);
  z-index: 60;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.modal-intro {
  margin: 0;
}

.modal-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.modal-section-title {
  font-size: 1rem;
  font-weight: 700;
}

.modal-section-text {
  color: var(--text-muted);
  font-size: 0.94rem;
  line-height: 1.5;
}


.field-note { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* jednoduché rozloženie 2 stĺpcov pre formuláre */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.modal-actions .spacer { flex: 1; }

/* Profil modal */
.profile-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-tab {
  display: grid;
  gap: 14px;
}

.profile-tab-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.theme-dark .profile-tab-btn {
  border-color: rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.22);
}

.profile-tab-btn.active {
  border-color: var(--accent-2);
  background: rgba(71, 179, 156, 0.12);
  box-shadow: 0 0 0 3px rgba(71, 179, 156, 0.14);
}

.field-readonly {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.10);
}

.theme-dark .field-readonly {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.14);
}

.field-note {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.8;
}

.admin-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: 14px;
  border: 1px dashed rgba(0,0,0,0.18);
  background: rgba(255,255,255,0.5);
}

.theme-dark .admin-box {
  border-color: rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.18);
}

.admin-box h3 {
  margin: 0 0 6px 0;
  font-size: 14px;
}

.admin-box .kv {
  display: grid;
  gap: 4px;
  font-size: 13px;
}


/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 30px;
}

.switch input { display: none; }

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.18);
  transition: 0.2s;
  border-radius: 999px;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 3px;
  top: 3px;
  background: #fff;
  transition: 0.2s;
  border-radius: 999px;
}

.switch input:checked + .slider {
  background: rgba(71, 123, 185, 0.55);
}

.switch input:checked + .slider:before {
  transform: translateX(24px);
}

/* ===== Dashboard: jemné úpravy (accent + šírky) ===== */

/* Panel so zariadeniami nech ide cez celú šírku gridu. */
.dashboard-top .devices-panel {
  grid-column: 1 / -1;
}

/* Status panel o niečo kompaktnejší (cca polovica výšky). */
.status-panel .panel-body {
  padding: 12px 14px;
}
.status-panel .status-lines {
  margin-top: 8px;
  gap: 8px;
}
.status-panel .status-line {
  padding: 10px 12px;
}

/* Nastavenia teplomeru: pole názvu + accent ovládače v jednom riadku. */
.field-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}
.field-inline input[type="text"] {
  flex: 1;
  min-width: 0;
}
.accent-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}
.accent-swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f2793b;
}
.accent-width {
  width: 70px;
}

/* Accent okraj karty zariadenia. */
.device-card {
  position: relative;
}
.device-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18px;
  pointer-events: none;
  box-shadow: inset 0 0 0 var(--card-accent-w, 0px) var(--card-accent-color, transparent);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.admin-link {
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: rgba(230, 138, 46, 0.12);
}

.admin-main {
    padding-top: 2rem;
}

.admin-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 1.5rem;
}

.admin-sidebar {
    border-right: 1px solid var(--border);
    padding-right: 1rem;
}

.admin-sidebar-title {
    font-weight: 700;
    margin-bottom: 0.8rem;
}

.admin-tables-list {
    display: grid;
    gap: 0.6rem;
}

.admin-table-link {
    text-align: left;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 0.8rem 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    font: inherit;
}

.admin-table-link.active {
    border-color: rgba(230, 138, 46, 0.7);
    box-shadow: inset 0 0 0 1px rgba(230, 138, 46, 0.35);
}

.admin-content {
    min-width: 0;
    display: grid;
    gap: 1rem;
}

.admin-content-header,
.admin-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.admin-table-wrap {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
    background: var(--surface);
}

.admin-table th,
.admin-table td {
    padding: 0.8rem 0.9rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.admin-actions-cell {
    white-space: nowrap;
}

.admin-empty {
    text-align: center;
    color: var(--text-muted);
}

.admin-edit-form {
    display: grid;
    gap: 0.9rem;
    max-height: 60vh;
    overflow: auto;
    padding-right: 0.4rem;
}

.admin-edit-form .field {
    gap: 0.45rem;
}

.admin-modal-status {
    margin-top: 0.25rem;
}

.button.small {
    padding: 0.45rem 0.9rem;
    font-size: 0.92rem;
}

.button.danger {
    background: #b42318;
    color: #fff;
}

.status-message {
    min-height: 1.4rem;
}

@media (max-width: 980px) {
    .admin-shell {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        border-right: 0;
        padding-right: 0;
        border-bottom: 1px solid var(--border);
        padding-bottom: 1rem;
    }
}


.admin-panel-full {
  width: 100%;
}

.admin-stacked-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.admin-stacked-body {
  display: grid;
  gap: 22px;
}

.admin-table-section {
  border: 1px solid rgba(120, 130, 170, 0.18);
  border-radius: 20px;
  padding: 18px;
  background: rgba(255,255,255,0.58);
}

.admin-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.admin-section-head h2 {
  margin: 0 0 6px 0;
  font-size: 1.15rem;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}


.field-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.field-error {
  font-size: 0.86rem;
  color: var(--danger);
  margin-top: 0.2rem;
}

.device-meta {
  display: grid;
  gap: 0.7rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.device-state-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.device-state-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.device-state-pill.online {
  background: rgba(15, 122, 67, 0.14);
  color: var(--success);
}

.device-state-pill.offline {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
}

.device-conn-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.device-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 0.8rem;
}

.device-meta-grid div {
  display: grid;
  gap: 0.15rem;
}

.device-meta-grid span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.device-meta-grid strong {
  font-size: 0.92rem;
  word-break: break-word;
}

.device-warning {
  display: none;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  background: rgba(230, 138, 46, 0.14);
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
}

.device-warning.show {
  display: block;
}

@media (max-width: 760px) {
  .device-meta-grid {
    grid-template-columns: 1fr;
  }
}


.admin-audit-table {
  min-width: 980px;
}

.admin-audit-table td:nth-child(1) {
  white-space: nowrap;
}

.admin-audit-table td:nth-child(3) {
  font-weight: 700;
}


.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.88;
}
.theme-dark .field input::placeholder,
.theme-dark .field textarea::placeholder {
  color: rgba(247,241,230,0.62);
}
.theme-dark .eye-button,
.theme-dark .device-gear,
.theme-dark .icon-btn,
.theme-dark .bubble-link {
  color: var(--text);
  background: rgba(247,241,230,0.08);
  border-color: rgba(247,241,230,0.18);
}
.theme-dark .field input:focus,
.theme-dark .field select:focus,
.theme-dark .field textarea:focus {
  outline: 2px solid rgba(71,179,156,0.45);
  border-color: rgba(71,179,156,0.48);
  box-shadow: 0 0 0 3px rgba(71,179,156,0.14);
}
.field-invalid { border-color: rgba(180,35,24,0.55) !important; box-shadow: 0 0 0 3px rgba(180,35,24,0.08); }
.field-error { font-size: 0.85rem; color: var(--danger); }
.theme-dark .admin-table,
.theme-dark .admin-table th,
.theme-dark .admin-table td,
.theme-dark .modal,
.theme-dark .panel,
.theme-dark .status-card,
.theme-dark .device-card,
.theme-dark .live-log { color: var(--text); }
.dashboard-summary {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}
@media (max-width: 980px) { .dashboard-summary { grid-template-columns: 1fr; } }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
@media (max-width: 720px) { .summary-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); } }
.summary-card {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: grid;
  gap: 8px;
}
.summary-card span { color: var(--text-muted); font-size: 0.9rem; }
.summary-card strong { font-size: 1.6rem; }
.dashboard-filters {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
@media (max-width: 720px) { .dashboard-filters { grid-template-columns: 1fr; } }
.recent-list { display: grid; gap: 10px; }
.recent-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.recent-item.warning { border-color: rgba(230,138,46,0.34); }
.recent-item span { color: var(--text-muted); font-size: 0.88rem; white-space: nowrap; }
.profile-section-panel .panel-body { display: grid; gap: 14px; }
.profile-section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .profile-section-grid { grid-template-columns: 1fr; } }
.device-meta { margin-top: 12px; display: grid; gap: 10px; }
.device-state-row { display: flex; align-items: center; gap: 10px; }
.device-state-pill { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; text-transform: uppercase; }
.device-state-pill.online { background: rgba(15,122,67,0.12); color: var(--success); }
.device-state-pill.offline { background: rgba(180,35,24,0.12); color: var(--danger); }
.device-conn-text { color: var(--text-muted); font-size: 0.9rem; }
.device-meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
@media (max-width: 600px) { .device-meta-grid { grid-template-columns: 1fr; } }
.device-meta-grid span { display: block; color: var(--text-muted); font-size: 0.8rem; margin-bottom: 4px; }
.device-warning { display: none; padding: 10px 12px; border-radius: 12px; background: rgba(230,138,46,0.12); border: 1px solid rgba(230,138,46,0.28); color: #9a5c16; }
.theme-dark .device-warning { color: #ffd39a; }
.device-warning.show { display: block; }
.theme-dark .toast-message,
.theme-dark .modal-status,
.theme-dark .inline-status { box-shadow: 0 14px 30px rgba(0,0,0,0.35); }


/* ===== Final responsive + states polish ===== */
.empty-state-card,
.chart-empty-state,
.admin-empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  min-height: 150px;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text-muted);
}
.empty-state-title {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text);
}
.empty-state-text {
  max-width: 42ch;
}
.chart-empty-state {
  min-height: 320px;
  width: 100%;
}
.admin-empty-state.bad,
.chart-empty-state.bad {
  border-color: rgba(180,35,24,0.35);
  color: var(--danger);
}
.theme-dark .empty-state-card,
.theme-dark .chart-empty-state,
.theme-dark .admin-empty-state {
  background: rgba(255,255,255,0.03);
}
.plot {
  min-height: 320px;
}
@media (max-width: 1100px) {
  .dashboard-top,
  .dashboard-summary,
  .dashboard-layout-2col,
  .profile-section-grid {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 820px) {
  .header {
    position: static;
    padding: 1rem 4vw 0.85rem;
  }
  .main,
  .footer {
    padding-left: 4vw;
    padding-right: 4vw;
  }
  .nav {
    width: 100%;
    gap: 0.55rem;
    align-items: stretch;
  }
  .nav a,
  .admin-link,
  .logout {
    white-space: nowrap;
  }
  .nav-right {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .user-menu {
    order: 10;
  }
  .user-bubble {
    right: auto;
    left: 0;
    width: min(92vw, 320px);
  }
  .status-line {
    align-items: flex-start;
  }
  .status-label {
    min-width: 0;
    width: 100%;
  }
  .modal {
    width: min(100vw - 20px, 620px);
    max-height: calc(100vh - 20px);
    overflow: auto;
  }
  .modal-actions {
    flex-wrap: wrap;
  }
  .modal-actions .button,
  .modal-actions .spacer {
    width: 100%;
  }
  .modal-actions .spacer {
    display: none;
  }
}
@media (max-width: 640px) {
  .devices-grid,
  .summary-grid,
  .dashboard-filters,
  .device-meta-grid {
    grid-template-columns: 1fr;
  }
  .device-body {
    grid-template-columns: 1fr;
  }
  .device-circle {
    width: 82px;
    height: 82px;
  }
  .recent-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .admin-table {
    min-width: 680px;
  }
  .admin-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.admin-export-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

.admin-export-group .button {
    white-space: nowrap;
}


.admin-email-section {
  background: rgba(248, 249, 252, 0.86);
}

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

.admin-email-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.field-compact {
  max-width: 220px;
}

.field-checkbox {
  display: flex;
  align-items: flex-end;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

@media (max-width: 860px) {
  .admin-email-grid {
    grid-template-columns: 1fr;
  }

  .field-compact {
    max-width: none;
  }
}


.device-updated-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.device-meta-inline-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem 1rem;
}

.device-meta-inline-item {
  min-width: 0;
}

.device-meta-inline-item span {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.device-meta-inline-item strong {
  display: block;
  font-size: 0.92rem;
  word-break: break-word;
}

@media (max-width: 760px) {
  .device-meta-inline-grid {
    grid-template-columns: 1fr;
  }
}
