/*
 * ORIScore Home UI
 * Readable semantic CSS. The palette and spacing follow ORIScore PRO.
 */

:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --primary-soft: #eef2ff;
    --bg: #f9fafb;
    --card-bg: #ffffff;
    --nav-bg: #1f2937;
    --nav-hover: #374151;
    --text: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --success: #10b981;
    --success-dark: #065f46;
    --success-soft: #d1fae5;
    --danger: #ef4444;
    --danger-dark: #991b1b;
    --danger-soft: #fee2e2;
    --warning: #f59e0b;
    --info-soft: #eff6ff;
    --info-border: #bfdbfe;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.10);
    --radius: 10px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.2rem;
    font-size: 1.65rem;
    font-weight: 700;
}

h2 {
    margin-bottom: 1rem;
    font-size: 1.05rem;
    font-weight: 700;
}

h3 {
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

code,
pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

[hidden] {
    display: none !important;
}

/* Header and navigation ---------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    color: #fff;
    background: var(--nav-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.topbar-inner,
.nav-inner {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.topbar-inner {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand-group,
.topbar-status,
.button-row,
.page-heading,
.card-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand {
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
}

.version {
    color: #d1d5db;
    font-size: 0.75rem;
}

.topbar-link {
    color: #d1d5db;
    text-decoration: none;
    font-size: 0.9rem;
}

.topbar-link:hover {
    color: #fff;
}

.main-nav {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-inner {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    scrollbar-width: thin;
}

.navbtn {
    flex: 0 0 auto;
    padding: 0.65rem 0.9rem;
    color: #d1d5db;
    background: transparent;
    border: 0;
    border-radius: 5px 5px 0 0;
    font-size: 0.9rem;
}

.navbtn:hover {
    color: #fff;
    background: var(--nav-hover);
}

.navbtn.active {
    color: #fff;
    background: var(--primary);
}

/* Layout ------------------------------------------------------------------ */

.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.page-heading {
    justify-content: space-between;
    margin-bottom: 1rem;
}

.page-subtitle,
.muted {
    color: var(--text-muted);
}

.page-subtitle {
    margin-bottom: 0;
    font-size: 0.9rem;
}

.small-text {
    font-size: 0.75rem;
}

.grid-2,
.form-grid,
.status-grid,
.diag-grid,
.service-grid {
    display: grid;
    gap: 1rem;
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.status-grid,
.diag-grid,
.service-grid {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.card {
    margin-bottom: 1rem;
    padding: 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-heading {
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.card-heading h2 {
    margin-bottom: 0;
}

.disabled-card {
    opacity: 0.62;
    background: #f8fafc;
}

.separator {
    margin: 1.2rem 0;
    border: 0;
    border-top: 1px solid var(--border);
}

.top-gap {
    margin-top: 1rem;
}

.top-gap-small {
    margin-top: 0.6rem;
}

/* Forms and buttons ------------------------------------------------------- */

.field {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.field label,
.update-block > label {
    color: #374151;
    font-size: 0.78rem;
    font-weight: 600;
}

.compact-field {
    min-width: 180px;
}

.button-field {
    justify-content: flex-end;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 0.55rem 0.65rem;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.13);
}

textarea {
    min-height: 110px;
    resize: vertical;
}

input[type="checkbox"] {
    width: auto;
    min-height: 0;
}

.button-row {
    flex-wrap: wrap;
}

.align-end {
    align-self: end;
}

.btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    border-radius: 5px;
    border: 1px solid transparent;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
    cursor: default;
    opacity: 0.55;
}

.btn-small {
    min-height: 32px;
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

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

.btn-primary:hover,
.primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-secondary,
.ghost {
    color: #374151;
    background: #fff;
    border-color: var(--border-strong);
}

.btn-secondary:hover,
.ghost:hover {
    background: #f3f4f6;
}

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

.btn-danger:hover,
.danger:hover {
    background: #dc2626;
}

/* Legacy class aliases used by generated rows. */
.primary,
.ghost,
.danger {
    min-height: 34px;
    padding: 0.45rem 0.75rem;
    border-radius: 5px;
    font-weight: 600;
}

.check-row {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    white-space: nowrap;
}

.automation-row {
    display: grid;
    grid-template-columns: auto minmax(150px, 1fr) minmax(130px, auto) minmax(120px, 1fr);
    align-items: center;
    gap: 0.6rem;
}

.schedule-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.compact-row {
    flex-wrap: nowrap;
    gap: 0.5rem;
}

.compact-row input {
    flex: 1 1 auto;
    min-width: 0;
}

.compact-row select {
    flex: 0 0 auto;
    width: auto;
    min-width: 90px;
}

/* Tables ------------------------------------------------------------------ */

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-w,
.list {
    width: 100%;
    border-collapse: collapse;
}

.table-w th,
.table-w td,
.list th,
.list td {
    padding: 0.65rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.table-w th,
.list th {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.035em;
}

/* Badges and messages ----------------------------------------------------- */

.status-badge,
.pill {
    display: inline-flex;
    align-items: center;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    background: #e5e7eb;
    color: #374151;
    font-size: 0.72rem;
    font-weight: 600;
}

.status-online,
.pill-ok {
    color: var(--success-dark);
    background: var(--success-soft);
}

.status-offline,
.pill-off {
    color: var(--danger-dark);
    background: var(--danger-soft);
}

.ok {
    color: #047857;
}

.bad {
    color: #b91c1c;
}

.notice {
    padding: 0.65rem 0.8rem;
    background: var(--info-soft);
    border: 1px solid var(--info-border);
    border-radius: 6px;
}

.notice-error {
    color: var(--danger-dark);
    background: var(--danger-soft);
    border-color: #fecaca;
}

.result-box {
    min-height: 90px;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    white-space: pre-wrap;
}

.loading-placeholder {
    color: var(--text-muted);
    padding: 0.75rem;
}

/* Dashboard --------------------------------------------------------------- */

.room-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.room-tab {
    flex: 0 0 auto;
    padding: 0.5rem 0.85rem;
    color: #4b5563;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-weight: 600;
}

.room-tab:hover {
    background: #f3f4f6;
}

.room-tab.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.widget {
    min-height: 120px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.widget-width-2 {
    grid-column: span 2;
}

.widget-width-3 {
    grid-column: span 3;
}

.widget-width-4 {
    grid-column: span 4;
}

.widget-title {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.widget-value {
    margin-top: 0.7rem;
    font-size: 1.8rem;
    font-weight: 700;
}

.switch-button {
    align-self: flex-start;
    margin-top: 0.8rem;
    padding: 0.48rem 0.9rem;
    color: #fff;
    border: 0;
    border-radius: 999px;
    font-weight: 700;
}

.switch-on {
    background: #16a34a;
}

.switch-off {
    background: #6b7280;
}

.room-editor {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 2fr) auto;
    gap: 0.75rem;
    align-items: end;
}

.dashboard-editor-list {
    display: grid;
    gap: 0.5rem;
    margin-top: 1rem;
}

.widget-editor-item {
    display: grid;
    grid-template-columns: 28px minmax(150px, 1.4fr) minmax(120px, 1fr) minmax(130px, 0.8fr) 90px 90px auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.6rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.widget-editor-item.dragging {
    opacity: 0.45;
}

.drag-handle {
    color: var(--text-muted);
    cursor: grab;
    font-size: 1.2rem;
    text-align: center;
    user-select: none;
}

/* Diagnostics ------------------------------------------------------------- */

.status-card,
.diag-item,
.service-item {
    min-width: 0;
    padding: 0.75rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.status-card,
.diag-item,
.service-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.status-card span,
.diag-item span,
.service-item span {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.service-item strong {
    font-size: 0.9rem;
}

/* Update progress --------------------------------------------------------- */

.update-block {
    margin-top: 1rem;
}

.update-block > label {
    display: block;
    margin-bottom: 0.45rem;
}

.update-progress {
    margin-top: 1rem;
    padding: 0.8rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.progress-track {
    height: 10px;
    overflow: hidden;
    background: #e5e7eb;
    border-radius: 999px;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: var(--primary);
    border-radius: inherit;
    transition: width 0.2s ease;
}

.progress-bar.indeterminate {
    width: 35%;
    animation: progress-indeterminate 1.2s ease-in-out infinite;
}

.progress-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.45rem;
    font-size: 0.8rem;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-110%); }
    50% { transform: translateX(90%); }
    100% { transform: translateX(290%); }
}

.api-endpoints {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.api-endpoint {
    padding: 0.25rem 0.5rem;
    color: #374151;
    background: #f3f4f6;
    border-radius: 4px;
    font: 0.75rem/1.4 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.api-endpoint-error {
    color: var(--danger-dark);
    background: var(--danger-soft);
}

/* Login / setup / service ------------------------------------------------- */

.login-wrap,
.setup-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
}

.login-card,
.setup-card {
    width: 100%;
    max-width: 560px;
    padding: 1.5rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.service-content {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.25rem;
}

.log-view {
    min-height: 65vh;
    max-height: 78vh;
    overflow: auto;
    padding: 1rem;
    color: #e5e7eb;
    background: #111827;
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8rem;
    line-height: 1.45;
}

/* Responsive -------------------------------------------------------------- */

@media (max-width: 1000px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .widget-width-3,
    .widget-width-4 {
        grid-column: span 2;
    }

    .widget-editor-item {
        grid-template-columns: 28px 1fr 1fr;
    }

    .widget-editor-item .editor-extra {
        grid-column: auto;
    }

    .room-editor {
        grid-template-columns: 1fr 1fr;
    }

    .room-editor .button-row {
        grid-column: 1 / -1;
    }
}

@media (max-width: 700px) {
    .topbar-inner {
        align-items: flex-start;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .brand-group {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.1rem;
    }

    .container {
        padding: 1rem 0.7rem 2rem;
    }

    .grid-2,
    .room-editor,
    .automation-row {
        grid-template-columns: 1fr;
    }

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

    .widget-width-2,
    .widget-width-3,
    .widget-width-4 {
        grid-column: span 1;
    }

    .widget-editor-item {
        grid-template-columns: 28px 1fr;
    }

    .widget-editor-item > *:not(.drag-handle) {
        grid-column: 2;
    }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Settings subnavigation ------------------------------------------------- */
.settings-tabs,
.network-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 1rem;
    padding: 0.45rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.settings-tab,
.network-tab {
    width: auto;
    min-height: 38px;
    padding: 0.5rem 0.8rem;
    color: #4b5563;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    font-weight: 600;
}

.settings-tab:hover,
.network-tab:hover {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.settings-tab.active,
.network-tab.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.settings-panel,
.network-panel {
    display: none;
}

.settings-panel.active,
.network-panel.active {
    display: block;
}

.code-editor {
    min-height: 280px;
    white-space: pre;
    tab-size: 4;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.84rem;
}

/* PRO-like device manager ------------------------------------------------ */
.device-config-table th {
    white-space: nowrap;
}

.device-type-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.text-primary {
    color: var(--primary);
}

.pill-success {
    color: #047857;
    background: #d1fae5;
}

.btn-link-danger {
    width: auto;
    min-height: auto;
    padding: 0.25rem 0;
    color: #dc2626;
    background: transparent;
    border: 0;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.device-scanner {
    position: relative;
    overflow: hidden;
    margin-bottom: 1rem;
    padding: 1.5rem;
    color: #fff;
    background: #111827;
    border: 1px solid #1f2937;
    border-radius: var(--radius);
    box-shadow: 0 14px 28px rgba(17, 24, 39, 0.16);
}

.device-scanner::after {
    content: "";
    position: absolute;
    top: -90px;
    right: -70px;
    width: 240px;
    height: 240px;
    border-radius: 50%;
    background: rgba(79, 70, 229, 0.22);
    filter: blur(55px);
    pointer-events: none;
}

.scanner-heading,
.device-card-top,
.device-card-bottom,
.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.scanner-heading,
.scanner-probe,
.device-discovery-grid {
    position: relative;
    z-index: 1;
}

.scanner-heading h2 {
    margin-bottom: 0.2rem;
    font-size: 1.3rem;
}

.scanner-heading p {
    margin-bottom: 0;
    color: #9ca3af;
}

.scanner-dot {
    color: #34d399;
}

.scanner-status {
    text-align: right;
}

.scanner-status span {
    display: block;
    color: #6b7280;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.scanner-status strong {
    color: #6ee7b7;
    font-size: 0.75rem;
}

.scanner-probe {
    display: grid;
    grid-template-columns: minmax(180px, 330px) auto minmax(0, 1fr);
    align-items: center;
    gap: 0.65rem;
    margin: 1rem 0;
}

.scanner-probe input {
    color: #e5e7eb;
    background: #1f2937;
    border-color: #374151;
}

.scanner-probe-result {
    color: #c7d2fe;
    font-size: 0.82rem;
}

.device-discovery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.8rem;
}

.device-card {
    padding: 1rem;
    background: rgba(31, 41, 55, 0.76);
    border: 1px solid #374151;
    border-radius: 8px;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.device-card:hover {
    border-color: rgba(99, 102, 241, 0.75);
    transform: translateY(-1px);
}

.device-card h3 {
    margin-bottom: 0.15rem;
    color: #fff;
}

.device-card p {
    margin-bottom: 0;
    color: #9ca3af;
    font-size: 0.75rem;
}

.device-capabilities {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.25rem;
}

.device-capability {
    display: inline-flex;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    background: rgba(79, 70, 229, 0.18);
    border-radius: 5px;
}

.device-card-bottom {
    margin-top: 1rem;
}

.device-ip {
    padding: 0.25rem 0.45rem;
    color: #9ca3af;
    background: #0f172a;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
}

.scanner-empty {
    padding: 1rem;
    color: #9ca3af;
    border: 1px dashed #374151;
    border-radius: 6px;
}

/* Pairing modal ---------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(17, 24, 39, 0.76);
    backdrop-filter: blur(3px);
}

.modal-card {
    width: min(560px, 100%);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 1rem 1.25rem;
    color: #fff;
    background: var(--primary);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.modal-close {
    width: auto;
    min-height: auto;
    padding: 0.15rem 0.35rem;
    color: #fff;
    background: transparent;
    border: 0;
    font-size: 1.6rem;
    line-height: 1;
}

.modal-body {
    display: grid;
    gap: 0.9rem;
    padding: 1.25rem;
}

.modal-footer {
    justify-content: flex-end;
    padding: 0 1.25rem 1.25rem;
}

@media (max-width: 720px) {
    .scanner-heading,
    .device-card-top,
    .device-card-bottom {
        align-items: flex-start;
        flex-direction: column;
    }

    .scanner-status {
        text-align: left;
    }

    .scanner-probe {
        grid-template-columns: 1fr;
    }
}

/* Mobile navigation / Plugin Store --------------------------------------- */
.nav-toggle {
    display: none;
    width: 42px;
    min-height: 38px;
    padding: 0.25rem 0.6rem;
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: 6px;
    font-size: 1.45rem;
    line-height: 1;
}

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

.plugin-card {
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.plugin-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.plugin-card h3 { margin-bottom: 0.15rem; }
.plugin-card p { min-height: 2.6em; margin: 0.75rem 0; }
.plugin-actions { flex-wrap: wrap; }

@media (max-width: 760px) {
    .topbar-inner {
        align-items: center;
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }

    .topbar-status {
        margin-left: auto;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }

    .main-nav { display: none; }
    .main-nav.mobile-open { display: block; }
    .main-nav .nav-inner {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0.4rem 0.7rem 0.7rem;
        overflow: visible;
    }
    .main-nav .navbtn {
        width: 100%;
        padding: 0.8rem 0.9rem;
        text-align: left;
        border-radius: 6px;
    }

    .settings-tabs,
    .network-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .settings-tab,
    .network-tab { flex: 0 0 auto; white-space: nowrap; }

    .status-grid,
    .form-grid,
    .diag-grid,
    .service-grid,
    .plugin-grid {
        grid-template-columns: 1fr !important;
    }

    .button-row { flex-wrap: wrap; }
    .button-row > .btn,
    .button-row > button.btn { max-width: 100%; }

    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .code-editor { min-height: 260px; }
}

@media (max-width: 480px) {
    .topbar-link { display: none; }
    .status-badge { font-size: 0.65rem; }
    .brand { font-size: 1rem; }
    .version { font-size: 0.68rem; }
    h1 { font-size: 1.35rem; }
    .card { padding: 0.9rem; }
    .btn { padding-left: 0.7rem; padding-right: 0.7rem; }
}


/* 0.1.12 - Number item history */
.item-history-chart-wrap {
    position: relative;
    width: 100%;
    height: 340px;
    min-height: 260px;
    margin-top: 12px;
}
.button-row-end {
    justify-content: flex-end;
}
@media (max-width: 760px) {
    .item-history-chart-wrap { height: 280px; }
}

/* Plugin item mapping ---------------------------------------------------- */
.plugin-map-warning { margin: .6rem 0; }
.plugin-item-map-row { display:grid; grid-template-columns:minmax(220px,.8fr) minmax(340px,1.4fr); gap:1rem; align-items:start; padding:1rem 0; border-bottom:1px solid var(--border, #e2e8f0); }
.plugin-item-map-info { display:flex; flex-direction:column; gap:.25rem; }
.plugin-item-map-controls { display:grid; gap:.55rem; }
.plugin-item-map-controls select,.plugin-item-map-controls input { width:100%; }
.plugin-item-new { display:grid; grid-template-columns:minmax(160px,1fr) 130px minmax(130px,.8fr); gap:.5rem; }
@media(max-width:800px){.plugin-item-map-row{grid-template-columns:1fr}.plugin-item-new{grid-template-columns:1fr}}

/* 0.1.16 - AI chat + dashboard history --------------------------------- */
.ai-chat-shell {
    min-height: 610px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #111827;
    border: 1px solid #263449;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.15rem;
    color: #f8fafc;
    background: #1f2d42;
    border-bottom: 1px solid #314157;
}

.ai-chat-identity {
    display: flex;
    align-items: center;
    gap: .7rem;
}

.ai-avatar {
    display: flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: #172235;
    font-size: 1.2rem;
}

.ai-chat-presence {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-top: .15rem;
    color: #6ee7b7;
    font-size: .72rem;
}

.ai-chat-presence.offline { color: #fca5a5; }
.ai-online-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.ai-chat-clear {
    width: 34px;
    height: 34px;
    padding: 0;
    color: #9fb0c7;
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 1.25rem;
}
.ai-chat-clear:hover { color: #fff; background: #2a3a51; }

.ai-chat-messages {
    flex: 1 1 auto;
    min-height: 430px;
    max-height: 62vh;
    overflow-y: auto;
    padding: 1rem;
    background: #172235;
}

.ai-message-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: .8rem;
}
.ai-message-row.user { align-items: flex-end; }
.ai-message {
    max-width: min(78%, 760px);
    padding: .68rem .82rem;
    border-radius: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.45;
    font-size: .93rem;
}
.ai-message-assistant {
    color: #e5e7eb;
    background: #243247;
    border: 1px solid #33435a;
    border-top-left-radius: 5px;
}
.ai-message-user {
    color: #fff;
    background: #4f46e5;
    border-top-right-radius: 5px;
}
.ai-message-time {
    margin-top: .25rem;
    color: #8190a6;
    font-size: .65rem;
}
.ai-typing { opacity: .72; font-style: italic; }

.ai-chat-composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: .55rem;
    align-items: end;
    padding: .85rem 1rem;
    background: #1f2d42;
    border-top: 1px solid #314157;
}
.ai-chat-composer textarea {
    min-height: 44px;
    max-height: 130px;
    resize: vertical;
    color: #e5e7eb;
    background: #111827;
    border-color: #3b4a61;
    border-radius: 22px;
    padding: .72rem 1rem;
}
.ai-chat-composer textarea::placeholder { color: #7f8da3; }
.ai-chat-send {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    color: #fff;
    background: var(--primary);
    border: 0;
    border-radius: 50%;
    font-size: 1.3rem;
}
.ai-chat-send:disabled { opacity: .55; cursor: wait; }

.widget-value-button {
    align-self: flex-start;
    width: auto;
    min-height: auto;
    margin-top: .7rem;
    padding: 0;
    color: inherit;
    background: transparent;
    border: 0;
    border-radius: 5px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.widget-value-button:hover { text-decoration: underline; }

.history-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .45rem;
}
.history-date { width: auto; min-width: 145px; }
.history-modal-card { width: min(980px, 100%); }
.dashboard-history-chart-wrap { height: min(52vh, 480px); min-height: 320px; }
.modal-header-subtitle { margin-top: .15rem; color: #dbeafe; font-size: .72rem; }

@media (max-width: 760px) {
    .ai-chat-shell { min-height: calc(100vh - 175px); }
    .ai-chat-messages { min-height: 360px; max-height: none; }
    .ai-message { max-width: 90%; }
    .history-card-heading { align-items: flex-start; flex-direction: column; }
    .history-toolbar { width: 100%; }
    .history-toolbar select, .history-toolbar .history-date { flex: 1 1 160px; }
    .dashboard-history-chart-wrap { height: 340px; min-height: 260px; }
}

/* ORIS AI 0.1.17 --------------------------------------------------------- */
.ai-chat-composer {
    grid-template-columns: auto minmax(0, 1fr) 48px;
}

.ai-chat-mic {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    align-self: end;
    color: #cbd5e1;
    background: #172235;
    border: 1px solid #3b4a61;
    border-radius: 50%;
    font-size: 1.05rem;
}
.ai-chat-mic:hover { color: #fff; background: #26364d; }
.ai-chat-mic.listening {
    color: #fff;
    background: #dc2626;
    border-color: #ef4444;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, .18);
}

.ai-floating-button {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1200;
    width: 56px;
    height: 56px;
    min-height: 56px;
    padding: 0;
    color: #fff;
    background: var(--primary);
    border: 0;
    border-radius: 50%;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .32);
    font-size: 1.45rem;
}
.ai-floating-button:hover,
.ai-floating-button.active { transform: translateY(-1px); filter: brightness(1.05); }

.ai-floating-panel {
    position: fixed;
    right: 22px;
    bottom: 88px;
    z-index: 1199;
    width: min(430px, calc(100vw - 28px));
    height: min(610px, calc(100vh - 130px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #111827;
    border: 1px solid #314157;
    border-radius: 14px;
    box-shadow: 0 20px 55px rgba(15, 23, 42, .45);
}

.ai-floating-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .78rem .9rem;
    color: #f8fafc;
    background: #1f2d42;
    border-bottom: 1px solid #314157;
}

.ai-floating-messages {
    min-height: 0;
    max-height: none;
    padding: .75rem;
}

.ai-floating-panel .ai-message {
    max-width: 88%;
    font-size: .86rem;
}
.ai-floating-panel .ai-message-time { font-size: .6rem; }
.ai-floating-composer { padding: .65rem .7rem; }
.ai-floating-composer textarea {
    min-height: 42px;
    padding: .65rem .85rem;
}
.ai-floating-composer .ai-chat-send,
.ai-floating-composer .ai-chat-mic {
    width: 42px;
    height: 42px;
    min-height: 42px;
}

@media (max-width: 760px) {
    .ai-floating-button { right: 14px; bottom: 14px; }
    .ai-floating-panel {
        right: 10px;
        bottom: 78px;
        width: calc(100vw - 20px);
        height: min(620px, calc(100vh - 100px));
    }
}
