/* === GNISTER WORKSPACE THEME ===
   Based on controller project design system */

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

:root {
    --base-color: white;
    --base-variant: #d9d9d9;
    --text-color: #0f172a;
    --secondary-text: #3a4a60;
    --border-color: #9c9c9c;
    --primary-color: #dc722c;
    --accent-color: #198920;
    --online: #22c55e;
    --offline: #ef4444;
    --grid-c: #707070;
    --home-c: #0062ff;
    --solar-c: #c7a001;
    --bess-c: #22c55e;
}

[data-theme="dark"] {
    --base-color: #232022;
    --base-variant: #3b3a43;
    --text-color: #d3d3d3;
    --secondary-text: #a7afbc;
    --border-color: #566377;
    --solar-c: #facc15;
}

body {
    background-color: var(--base-color);
    color: var(--text-color);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: medium;
    margin: 0;
    padding: 0;
}

a {
    text-decoration: none;
}

/* ---- Top Bar ---- */

.top-menu-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 50px;
    align-items: center;
    position: relative;
}

.top-menu-style {
    background-color: var(--base-variant);
    border-bottom: 1px solid var(--border-color);
}

.top-menu-style * {
    text-decoration: none;
}

.top-menu-layout .top-menu-left-layout {
    grid-column: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 100%;
}

.top-menu-layout .top-menu-right-layout {
    grid-column: 2;
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    height: 100%;
}

.top-menu-style .menu-item-style {
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.top-menu-style button.menu-item-style {
    background: none;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: inherit;
}

.top-menu-style .menu-item-style:hover {
    background-color: var(--base-color);
}

.top-menu-style .menu-active-item-style {
    background-color: var(--accent-color);
    color: white;
}

.top-menu-style .menu-active-item-style:hover {
    background-color: #146f1a;
    color: white;
}

/* ---- Workspace Switcher ---- */

.ws-switcher-layout {
    position: relative;
    display: inline-flex;
    align-items: center;
    height: 100%;
}

.ws-switcher-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
}

.ws-switcher-trigger:hover {
    background-color: var(--base-color);
}

.ws-switcher-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 16px;
    flex-shrink: 0;
}

.ws-switcher-name {
    max-width: min(180px, 28vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-icon-btn {
    font-size: 1.2rem;
    padding: 6px 8px;
    line-height: 1;
}

.ws-switcher-chevron {
    color: var(--secondary-text);
    font-size: 0.8rem;
}

.ws-switcher-dropdown {
    display: none;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 100;
    background: var(--base-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 260px;
    padding: 8px 0;
    overflow: hidden;
}

.ws-switcher-list {
    display: flex;
    flex-direction: column;
}

.ws-switcher-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--text-color);
    text-decoration: none;
    cursor: pointer;
}

.ws-switcher-row:hover {
    background-color: var(--base-variant);
}

.ws-switcher-current {
    font-weight: 600;
    cursor: default;
}

.ws-switcher-current:hover {
    background: none;
}

.ws-switcher-row-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 22px;
    flex-shrink: 0;
}

.ws-switcher-row-name {
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.ws-switcher-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    color: var(--secondary-text, #6b7280);
    border-radius: 4px;
    flex-shrink: 0;
    text-decoration: none;
}

.ws-switcher-action-btn:hover {
    background: var(--base-variant);
    color: var(--text-color);
}

.ws-switcher-action-btn .material-symbols-outlined {
    font-size: 20px;
}

.ws-switcher-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 6px 0;
}

.ws-switcher-add-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: none;
    border: none;
    padding: 10px 16px;
    cursor: pointer;
    color: var(--secondary-text);
    font-size: 0.95rem;
    font-family: inherit;
    text-align: left;
}

.ws-switcher-add-btn:hover {
    background-color: var(--base-variant);
    color: var(--text-color);
}

.ws-switcher-add-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background-color: var(--base-variant);
    font-size: 22px;
    font-weight: 300;
    flex-shrink: 0;
}


.ws-icon-grid,
.ws-color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ws-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid transparent;
    background: var(--base-variant);
    cursor: pointer;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.ws-icon-btn:hover,
.ws-icon-btn.selected {
    border-color: var(--text-color);
}

.ws-color-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}

.ws-color-btn:hover,
.ws-color-btn.selected {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.ws-create-submit {
    margin-top: 4px;
}

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

.frame-layout {
    display: grid;
    grid-template-columns: 150px 1fr;
    height: calc(100vh - 50px);
}

.frame-layout .frame-left-layout {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--base-variant);
    border-right: 1px solid var(--border-color);
    padding: 8px;
    overflow-y: auto;
}

.frame-layout .frame-right-layout {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: auto;
}

.frame-style .menu-item-style {
    color: var(--secondary-text);
    display: block;
    padding: 10px;
    border-radius: 6px;
    font-size: medium;
    margin-bottom: 2px;
}

.frame-style .menu-item-style:hover {
    background-color: var(--base-color);
    color: var(--text-color);
}

.frame-style .selected-menu-item-style {
    background-color: var(--accent-color);
    color: white;
}

.frame-style .selected-menu-item-style:hover {
    background-color: #146f1a;
    color: white;
}

.frame-style p {
    margin: 4px 0;
    padding: 0;
}

/* ---- Device Panels ---- */

.dev-panel-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    flex-direction: row;
}

.dev-panel-layout .dev-field-layout {
    flex: 1;
    flex-basis: 80px;
    display: flex;
    flex-direction: column;
}

.dev-panel-style {
    background: var(--base-variant);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 8px;
    color: var(--text-color);
    font-size: medium;
}

.dev-inactive-style {
    opacity: 0.45;
}

.dev-panel-style .dev-field-header-style {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--secondary-text);
    margin: 0 0 2px 0;
    padding: 0 4px;
}

.dev-panel-style .dev-field-style {
    text-align: left;
    font-size: medium;
    margin: 0;
    padding: 0 4px;
}

.dev-panel-style .dev-field-editable {
    border-radius: 3px;
    border-bottom: 2px solid transparent;
    outline: none;
}

.dev-panel-style .dev-field-editable:hover {
    border-bottom: 2px solid var(--border-color);
}

.dev-field-identifier {
    width: calc(min(340px, 50vw));
    word-wrap: break-word;
    word-break: break-all;
    font-size: 0.75rem;
    color: var(--secondary-text);
    padding: 0 4px;
}

.dev-panel-style .dev-field-button-style {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid;
    text-decoration: none;
    margin-left: 4px;
}

.dev-panel-style .remove-button {
    background-color: color-mix(in srgb, #ef4444 15%, transparent);
    color: #ef4444;
    border-color: color-mix(in srgb, #ef4444 30%, transparent);
}

.dev-panel-style .remove-button:hover {
    background-color: #ef4444;
    color: white;
}

.dev-panel-style .add-button {
    background-color: color-mix(in srgb, #22c55e 15%, transparent);
    color: #22c55e;
    border-color: color-mix(in srgb, #22c55e 30%, transparent);
}

.dev-panel-style .add-button:hover {
    background-color: #22c55e;
    color: white;
}

/* ---- Overview Cards ---- */

.card-grid-layout {
    display: flex;
    flex-direction: row;
    row-gap: 16px;
    column-gap: 16px;
    flex-wrap: wrap;
    padding: 4px;
}

.card-grid-layout>* {
    flex-basis: 180px;
    display: flex;
    flex-direction: column;
}

.card-grid-style .card-divider-style {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--secondary-text);
    flex-basis: 100%;
    padding: 4px 2px;
    border-bottom: 1px solid var(--border-color);
}

.card-grid-style .card-style {
    background: var(--base-variant);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.card-grid-style .card-header-style {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--secondary-text);
    margin: 0;
}

.card-grid-style .card-content-style {
    font-size: 1.4rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-color);
    margin: 0;
}

/* ---- Status dot ---- */

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--online);
    box-shadow: 0 0 6px var(--online);
}

.status-dot.offline {
    background: var(--offline);
    box-shadow: 0 0 6px var(--offline);
}

/* ---- Theme toggle ---- */

#theme-toggle {
    color: var(--secondary-text);
}

#theme-toggle svg:last-child {
    display: none;
}

[data-theme="dark"] #theme-toggle svg:first-child {
    display: none;
}

[data-theme="dark"] #theme-toggle svg:last-child {
    display: inline;
}

/* ---- Metric label ---- */

.metric-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ---- Utility: Buttons & Cards ---- */

.card {
    background: var(--base-variant);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.btn {
    padding: 0.5em;
    cursor: pointer;
    border-radius: 8px;
    border: none;
    width: 100%;
    font-size: 1rem;
    font-family: inherit;
}

.btn-primary {
    background-color: #00ab0b;
    color: white;
}

.btn-primary:hover {
    background-color: #008a09;
}

.btn-secondary {
    background-color: transparent;
    color: var(--secondary-text);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--base-color);
    color: var(--text-color);
}

/* ---- Overview layout ---- */

.overview-layout {
    display: flex;
    flex-direction: row;
    height: calc(100vh - 50px);
    overflow: hidden;
}

.overview-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.overview-stats {
    padding: 16px;
    flex-shrink: 0;
}

.overview-devices-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ---- Devices view ---- */

.device-row {
    display: flex;
    flex-direction: column;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    gap: 3px;
}

.device-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.device-row-metrics {
    display: flex;
    gap: 10px;
    font-size: 0.78rem;
    color: var(--secondary-text, #6b7280);
}

.device-row:hover {
    background-color: var(--base-variant);
}

.device-row.selected {
    background-color: var(--base-variant);
    border-color: var(--border-color);
}

.device-row-name {
    font-weight: 500;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: inherit;
}

.device-row-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.device-row-status--running {
    background: color-mix(in srgb, var(--online) 15%, transparent);
    color: color-mix(in srgb, var(--online) 70%, #000);
}

.device-row-status--offline {
    background: color-mix(in srgb, #9ca3af 15%, transparent);
    color: #6b7280;
}

.device-row-status--error {
    background: color-mix(in srgb, var(--offline) 15%, transparent);
    color: color-mix(in srgb, var(--offline) 70%, #000);
}

.device-detail-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    padding: 16px;
    font-size: 0.85rem;
    width: 300px;
    flex-shrink: 0;
    border-left: 1px solid var(--border-color);
}

.settings-panel {
    width: 480px;
}

.device-detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.device-detail-name {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-detail-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted, #9ca3af);
    font-size: 0.85rem;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
}

.device-detail-close:hover {
    color: var(--text-color);
    background: var(--base-variant);
}

.device-detail-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.device-detail-status--running {
    background: color-mix(in srgb, var(--online) 15%, transparent);
    color: color-mix(in srgb, var(--online) 70%, #000);
}

.device-detail-status--offline {
    background: color-mix(in srgb, #9ca3af 15%, transparent);
    color: #6b7280;
}

.device-detail-status--error {
    background: color-mix(in srgb, var(--offline) 15%, transparent);
    color: color-mix(in srgb, var(--offline) 70%, #000);
}

.device-detail-section {
    padding: 7px 0;
    border-bottom: 1px solid var(--border-color);
}

.device-detail-section .dev-field-header-style {
    margin: 0 0 4px;
}

.device-detail-section .dev-field-style {
    margin: 0;
}

.device-detail-admin {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 2px solid var(--border-color);
}

/* ---- Sign-in ---- */

.signin-input {
    width: 100%;
    padding: 0.5em;
    font-size: 1rem;
    font-family: inherit;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: var(--base-color);
    color: var(--text-color);
}

.signin-divider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--secondary-text);
    font-size: 0.9rem;
}

.signin-divider hr {
    flex: 1;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* ---- Topbar responsive truncation ---- */

.topbar-username {
    max-width: min(180px, 22vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 500px) {
    .topbar-title {
        display: none;
    }
}