:root {
  --color-indigo: #3F51B5;
  --color-teal: #26A69A;
  --color-magenta: #D82B6B;
  --color-orange: #F9A825;
  --color-dark: #0D0D0D;
  --color-surface: #f8f9fb;
  --color-card: #ffffff;
  --color-text: #1a1a2e;
  --color-muted: #5c6370;
  --color-border: #e2e6ed;
  --color-indigo-light: #eef0f8;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(13, 13, 13, 0.06);
}

* { box-sizing: border-box; }

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

.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--color-indigo) 0%, var(--color-dark) 100%);
  box-shadow: 0 4px 20px rgba(13, 13, 13, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  min-height: 56px;
  gap: 1rem;
}

.nav a.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 1rem 0.5rem 0;
  margin-right: 0.25rem;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.nav a.brand:hover,
.nav a.brand:focus-visible {
  opacity: 0.9;
  outline: none;
}

.brand-logo {
  display: block;
  flex-shrink: 0;
  width: auto;
  max-height: 36px;
}

.brand-text {
  display: flex;
  align-items: center;
  line-height: 1.15;
}

.brand-name {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  color: #fff;
}

.nav-toggle {
  display: none;
  margin-left: auto;
  padding: 0.4rem;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  line-height: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.35);
}

.nav-toggle:focus-visible {
  outline: 2px solid var(--color-teal);
  outline-offset: 2px;
}

.nav-toggle-icon {
  display: block;
}

.nav-toggle-close {
  display: none;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-open {
  display: none;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-close {
  display: block;
}

.nav-menu {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 0.5rem;
  min-width: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  justify-content: center;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover,
.nav-link:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  outline: none;
}

.nav-link.is-active {
  background: rgba(38, 166, 154, 0.28);
  color: var(--color-teal);
  box-shadow: inset 0 -2px 0 var(--color-teal);
}

.nav-link.is-active .nav-icon {
  stroke: var(--color-teal);
}

.nav-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}

.nav-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-action:hover,
.nav-action:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
  outline: none;
}

.nav-action--logout {
  opacity: 0.75;
  margin-left: 0.5rem;
}

.nav-action--logout:hover,
.nav-action--logout:focus-visible {
  opacity: 1;
  background: rgba(220, 50, 50, 0.2);
  border-color: rgba(220, 50, 50, 0.4);
}

@media (max-width: 768px) {
  .nav-inner {
    flex-wrap: wrap;
    padding: 0.65rem 1rem;
    min-height: auto;
  }

  .nav a.brand {
    border-right: none;
    padding-right: 0;
    margin-right: 0;
  }

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

  .nav-menu {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.75rem;
    padding: 0.5rem 0 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
  }

  .nav-menu.is-open {
    display: flex;
    animation: navSlideIn 0.2s ease;
  }

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

  .nav-links {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.15rem;
  }

  .nav-link {
    padding: 0.65rem 0.75rem;
  }

  .nav-actions {
    margin-left: 0;
    padding-top: 0.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .nav-action {
    justify-content: center;
    width: 100%;
  }
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 {
  margin-top: 0;
  color: var(--color-dark);
  font-weight: 700;
}

h2 {
  color: var(--color-text);
  font-weight: 600;
  font-size: 1.1rem;
}

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

.card {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-indigo);
}

.card--foxess {
  border-top-color: var(--color-teal);
}

.card--fusionsolar {
  border-top-color: var(--color-orange);
}

.big {
  font-size: 2rem;
  font-weight: 700;
  margin: 0.25rem 0;
  color: var(--color-indigo);
}

.stats-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--color-muted);
}

.stats-list li { padding: 0.15rem 0; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  border: 1px solid var(--color-border);
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

th {
  background: var(--color-indigo-light);
  font-weight: 600;
  color: var(--color-indigo);
}

.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-listed,
.badge-devices_pending {
  background: #fff4e0;
  color: #b36b00;
}

.badge-complete,
.badge-completed {
  background: #e0f5f0;
  color: #1a7a6d;
}

.badge-error,
.badge-failed {
  background: #fce8ef;
  color: #a81f52;
}

.badge-interrupted {
  background: #fff3e0;
  color: #e65100;
}

.badge-running {
  background: #e8eaf6;
  color: var(--color-indigo);
}

.btn {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-text);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  background: var(--color-indigo-light);
  border-color: var(--color-indigo);
}

.btn:focus-visible {
  outline: 2px solid var(--color-teal);
  outline-offset: 2px;
}

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

.btn-primary:hover {
  background: #1f9589;
  border-color: #1f9589;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filters select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
  font-size: 0.9rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.alert-info {
  background: #e8eaf6;
  color: var(--color-indigo);
  border: 1px solid #c5cae9;
}

.alert-warning {
  background: #fff3e0;
  color: #e65100;
  border: 1px solid #ffcc80;
}

.alert-danger {
  background: #fde8e8;
  color: #c62828;
  border: 1px solid #ef9a9a;
}

.alert-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.platform-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.platform-foxess {
  background: #e8eaf6;
  color: var(--color-indigo);
}

.platform-fusionsolar {
  background: #e0f5f0;
  color: #1a7a6d;
}

.platform-all {
  background: #f0f0f0;
  color: var(--color-muted);
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
}

.error-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.muted {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.pagination {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.pagination a {
  color: var(--color-indigo);
  text-decoration: none;
  font-weight: 500;
}

.pagination a:hover {
  color: var(--color-teal);
}

.test-result {
  font-size: 0.85rem;
  background: var(--color-surface);
  padding: 0.5rem;
  border-radius: 6px;
  min-height: 1.5rem;
  border: 1px solid var(--color-border);
  margin-top: 0.5rem;
}

/* Clients list enhancements */
.clients-filters {
  align-items: center;
}

.search-input {
  flex: 1 1 220px;
  min-width: 180px;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.search-input.is-searching {
  border-color: var(--color-indigo);
}

.search-hint {
  flex: 1 1 100%;
  margin: -0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--color-muted);
}

.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 1rem;
}

.table-wrap.is-loading {
  opacity: 0.55;
  pointer-events: none;
}

.clients-table th.sortable a {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.clients-table th.sortable a:hover {
  color: var(--color-indigo);
}

.row-link {
  cursor: pointer;
  transition: background 0.12s ease;
}

.row-link:hover {
  background: var(--color-indigo-light);
}

.error-badge {
  display: inline-block;
  min-width: 1.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #fde8e8;
  color: #c62828;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.error-badge--ok {
  background: #e8f5e9;
  color: #2e7d32;
}

.equipment-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #fff3e0;
  color: #e65100;
  font-size: 0.8rem;
  font-weight: 600;
}

.equipment-badge--ok {
  background: #e8f5e9;
  color: #2e7d32;
}

.production-cell {
  min-width: 110px;
}

.sparkline {
  display: block;
  width: 80px;
  height: 24px;
  color: var(--color-teal);
  margin-bottom: 0.15rem;
}

.production-kw {
  font-size: 0.82rem;
  font-weight: 600;
}

.equipment-cell {
  max-width: 180px;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.back-link {
  margin-bottom: 1rem;
}

.back-link a {
  color: var(--color-indigo);
  text-decoration: none;
  font-weight: 500;
}

.client-header {
  margin-bottom: 1.5rem;
}

.client-sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.client-sync-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  min-height: 1.25rem;
}

.client-sync-status--info {
  color: var(--color-accent, #26a69a);
}

.client-sync-status--error {
  color: #e57373;
}

.client-sync-status--success {
  color: #81c784;
}

.btn-danger {
  background: #c62828;
  border-color: #b71c1c;
  color: #fff;
}

.btn-danger:hover {
  background: #b71c1c;
}

.badge-cancelled {
  background: #616161;
  color: #fff;
}

.client-header-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.client-header-main h1 {
  margin: 0;
}

.client-header-title {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.client-external-id {
  margin: 0;
  font-size: 0.65rem;
  color: var(--color-muted);
  letter-spacing: 0.01em;
  line-height: 1.3;
  word-break: break-all;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1.25rem;
  margin: 0;
}

.detail-grid dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-muted);
  margin-bottom: 0.15rem;
}

.detail-grid dd {
  margin: 0;
  font-size: 0.95rem;
}

.chart-card {
  padding: 1rem;
  margin-bottom: 1.5rem;
}

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

.chart-card-head .period-selector {
  margin-bottom: 0;
}

.chart-card-title {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}

.chart-card-head .chart-hint {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
}

.chart-hint {
  margin: 0.75rem 0 0;
}

.chart-empty {
  margin: 0.5rem 0;
  padding: 1.5rem 0;
  text-align: center;
}

.badge-pv {
  background: rgba(38, 166, 154, 0.15);
  color: #1a7a70;
  font-weight: 600;
}

.badge-optimizer {
  background: rgba(255, 167, 38, 0.15);
  color: #b36800;
  font-weight: 600;
}

.badge-online {
  background: #e8f5e9;
  color: #2e7d32;
}

.badge-offline {
  background: #f5f5f5;
  color: #616161;
}

.badge-fault {
  background: #fde8e8;
  color: #c62828;
}

.badge-unknown {
  background: #f0f0f0;
  color: var(--color-muted);
}

@media (max-width: 900px) {
  .col-address,
  .col-synced,
  .col-production,
  th.col-production,
  th.col-synced,
  th.col-address {
    display: none;
  }
}

.export-header {
  margin-bottom: 1rem;
  padding: 1rem;
}

.export-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.export-status {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.export-status--ok {
  background: #e8f5e9;
  color: #2e7d32;
}

.export-status--blocked {
  background: #fde8e8;
  color: #c62828;
}

.period-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.period-selector select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.export-summary-grid {
  margin-top: 0.5rem;
}

.export-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.export-badge--ok {
  background: #e8f5e9;
  color: #2e7d32;
}

.export-badge--blocked {
  background: #fde8e8;
  color: #c62828;
}

.badge-config_disabled,
.badge-zero_export_limit {
  background: #fff3e0;
  color: #e65100;
}

.badge-overvoltage,
.badge-grid_fault {
  background: #fde8e8;
  color: #c62828;
}

.event-timeline td {
  font-size: 0.88rem;
}

.job-log-panel {
  margin-top: 1.5rem;
  padding: 1rem;
}

.job-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.job-log-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.job-log-output {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  padding: 0.75rem;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
