.portal-app {
  min-height: 100vh;
  background: var(--bg);
}

.portal-body {
  display: flex;
  min-height: 100vh;
}

/* ── Device sidebar ── */
.portal-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 18px 14px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.portal-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px 4px;
}

.portal-sidebar-brand-logo-wrap {
  flex-shrink: 0;
}

.portal-sidebar-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
  display: block;
}

.portal-sidebar-brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.portal-sidebar-brand-sub {
  font-size: 13px;
  color: var(--text3);
  margin-top: 3px;
}

.portal-sidebar-add-device {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  padding: 0 16px;
  box-sizing: border-box;
  border: none;
  border-radius: 10px;
  background: var(--brand-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.portal-sidebar-add-device:hover {
  background: #e00909;
  box-shadow: 0 4px 14px rgba(255, 12, 12, 0.28);
  transform: translateY(-1px);
}

.portal-sidebar-add-device:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(255, 12, 12, 0.2);
}

.portal-sidebar-add-device-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  transition: transform 0.2s ease;
}

.portal-sidebar-add-device.is-open .portal-sidebar-add-device-icon {
  transform: rotate(45deg);
}

.portal-sidebar-add-device-wrap {
  position: relative;
  flex-shrink: 0;
}

.portal-add-device-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: transparent;
}

.portal-add-device-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 141;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 16px 40px rgba(16, 16, 16, 0.14);
  animation: portal-add-device-menu-in 0.16s ease;
}

@keyframes portal-add-device-menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.portal-add-device-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s ease;
}

.portal-add-device-menu-item:hover {
  background: rgba(255, 12, 12, 0.06);
}

.portal-add-device-menu-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 12, 12, 0.1);
  color: var(--brand-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.portal-add-device-menu-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.portal-add-device-menu-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.portal-add-device-menu-sub {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text3);
}

.portal-sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 4px;
  flex-shrink: 0;
}

.portal-sidebar-search {
  position: relative;
  flex-shrink: 0;
}

.portal-sidebar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text3);
  pointer-events: none;
}

.portal-sidebar-search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 36px;
  box-sizing: border-box;
  border: 1px solid rgba(255, 12, 12, 0.28);
  border-radius: 10px;
  background: #fff;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.portal-sidebar-search-input::placeholder {
  color: var(--text3);
}

.portal-sidebar-search-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(255, 12, 12, 0.08);
}

.portal-sidebar-count {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 4px;
}

.portal-device-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px 12px 16px 8px;
}

.portal-device-list-empty {
  font-size: 12px;
  color: var(--text3);
  text-align: center;
  padding: 24px 12px;
  line-height: 1.5;
}

/* Outer shell — flush border ring + shadow (no outline-offset gap) */
.portal-sidebar .portal-device-tile-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 2px solid transparent;
  overflow: hidden;
  background: #101010;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}

.portal-sidebar .portal-device-tile-shell.is-selected,
.portal-sidebar .portal-device-tile-shell[data-selected="true"],
.portal-sidebar .portal-device-tile-shell[data-selected="True"] {
  z-index: 5;
  transform: translateY(-4px);
  border-color: #ff0c0c;
  box-shadow: 0 8px 22px rgba(16, 16, 16, 0.16);
}

.portal-sidebar .portal-device-tile-shell:not(.is-selected):not([data-selected="true"]):not([data-selected="True"]):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(16, 16, 16, 0.1);
}

.portal-sidebar .portal-device-tile {
  position: relative;
  display: block;
  width: 100%;
  min-height: 96px;
  padding: 0;
  border: none;
  border-radius: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  background: transparent;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.portal-device-tile-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 8px 6px;
  margin-top: -2px;
  background: linear-gradient(180deg, rgba(16, 16, 16, 0.72) 0%, rgba(16, 16, 16, 0.92) 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.portal-device-tile-remove {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.88);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.portal-device-tile-shell:hover .portal-device-tile-remove,
.portal-device-tile-shell.is-selected .portal-device-tile-remove,
.portal-device-tile-shell[data-selected="true"] .portal-device-tile-remove,
.portal-device-tile-shell[data-selected="True"] .portal-device-tile-remove {
  opacity: 1;
  transform: translateY(0);
}

.portal-device-tile-remove:hover {
  background: rgba(255, 12, 12, 0.92);
  border-color: rgba(255, 12, 12, 0.4);
  color: #fff;
}

.portal-device-remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 12, 12, 0.16);
  border-radius: 10px;
  background: #fff;
  color: var(--brand-primary);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.portal-device-remove-btn:hover {
  background: #fff8f8;
  border-color: rgba(255, 12, 12, 0.28);
}

.portal-device-tile-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}

.portal-device-tile-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(16, 16, 16, 0.2) 0%,
    rgba(16, 16, 16, 0.55) 42%,
    rgba(16, 16, 16, 0.88) 100%
  );
  transition: background 0.2s ease;
}

.portal-device-tile-content {
  position: relative;
  z-index: 2;
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
  justify-content: flex-end;
  box-sizing: border-box;
}

.portal-device-tile-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.portal-device-tile-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.portal-device-tile-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}

.portal-device-tile-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.portal-device-tile-meta-line {
  display: block;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main content + section tabs ── */
.portal-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.portal-section-tabs {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.portal-section-tabs-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.portal-section-tabs-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-left: auto;
}

.portal-header-menu {
  position: relative;
  z-index: 210;
}

.portal-header-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.portal-header-menu-trigger:hover {
  border-color: rgba(255, 12, 12, 0.35);
  background: var(--brand-primary-bg);
}

.portal-header-menu-label {
  white-space: nowrap;
}

.portal-header-flag {
  font-size: 16px;
  line-height: 1;
}

.portal-header-chevron {
  width: 14px;
  height: 14px;
  color: var(--text3);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.portal-header-chevron.is-open {
  transform: rotate(180deg);
}

.portal-header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-primary-bg);
  color: var(--brand-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.portal-header-profile-trigger {
  padding-left: 6px;
}

.portal-header-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16, 16, 16, 0.12);
  z-index: 220;
  overflow: hidden;
  animation: dropdown-in 0.15s ease;
}

.portal-header-dropdown-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}

.portal-header-dropdown-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.portal-header-dropdown-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-header-dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: #fff;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.portal-header-dropdown-item:hover {
  background: var(--bg2);
  color: var(--text);
}

.portal-header-dropdown-item.active {
  background: var(--brand-primary-bg);
  color: var(--brand-primary);
  font-weight: 600;
}

.portal-header-dropdown-item.logout {
  color: var(--brand-primary);
  border-top: 1px solid var(--border);
}

.portal-header-dropdown-item.logout:hover {
  background: var(--brand-primary-bg);
}

.portal-tab-refresh {
  white-space: nowrap;
}

.portal-section-tab {
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.portal-section-tab:hover {
  background: var(--bg2);
  color: var(--text);
}

.portal-section-tab.active {
  background: var(--brand-primary-bg);
  border-color: var(--brand-primary-border);
  color: var(--brand-primary);
}

.portal-main-content {
  position: relative;
  flex: 1;
  padding: 20px 24px 32px;
}

.portal-content-loader {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 360px;
  background: var(--bg);
}

.portal-content-loader-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: portal-content-spin 0.75s linear infinite;
}

.portal-content-loader-text {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
}

@keyframes portal-content-spin {
  to {
    transform: rotate(360deg);
  }
}

.portal-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.portal-inverter-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.portal-inverter-heading-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.portal-inverter-heading-name {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-section-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.portal-section-sub {
  font-size: 13px;
  color: var(--text3);
  margin-top: 6px;
}

.portal-device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.portal-device-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.portal-device-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.portal-device-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.portal-settings-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.portal-settings-profile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.portal-settings-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--brand-primary-bg);
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.portal-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.portal-settings-row:last-child {
  border-bottom: none;
}

@media (max-width: 900px) {
  .portal-body {
    flex-direction: column;
  }

  .portal-sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 14px;
  }

  .portal-device-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 12px 14px;
    gap: 12px;
  }

  .portal-device-tile-shell {
    flex: 0 0 228px;
  }

  .portal-device-tile {
    min-height: 96px;
  }

  .portal-device-tile-content {
    min-height: 96px;
  }

  .portal-section-tabs {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .portal-section-tabs-nav {
    overflow-x: auto;
    flex: 1 1 100%;
  }

  .portal-section-tabs-actions {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  .portal-section-tab {
    flex: 0 0 auto;
  }

  .portal-main-content {
    padding: 16px;
  }

  .portal-inverter-heading-name {
    font-size: 22px;
  }
}

html[dir="rtl"] .portal-sidebar {
  border-right: none;
  border-left: 1px solid var(--border);
}

html[dir="rtl"] .portal-section-tabs-actions {
  flex-direction: row-reverse;
}

html[dir="rtl"] .portal-header-dropdown {
  left: 0;
  right: auto;
}

html[dir="rtl"] .portal-device-tile-meta-line,
html[dir="rtl"] .device-last-data-row,
html[dir="rtl"] .portal-realtime-metric-card {
  text-align: right;
}
