:root {
  color-scheme: light;
  --bg: #f7f7f7;
  --panel: #ffffff;
  --panel-soft: #dee8f7;
  --panel-strong: #062860;
  --line: rgba(6, 40, 96, 0.16);
  --line-strong: rgba(4, 53, 119, 0.42);
  --text: #062860;
  --muted: #5a6680;
  --muted-strong: #043577;
  --gold: #043577;
  --gold-strong: #062860;
  --primary-text: #ffffff;
  --danger: #c73f4b;
  --success: #14865d;
  --input-bg: #ffffff;
  --button-bg: #ffffff;
  --button-text: #062860;
  --frame-bg: #f7f7f7;
  --radius: 8px;
  --shadow: 0 18px 46px rgba(6, 40, 96, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

button {
  cursor: pointer;
}

.app-shell,
.loading-view,
.login-view {
  min-height: 100vh;
}

.loading-view,
.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
}

.brand-word {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  user-select: none;
}

.planetra-mark {
  min-width: 0;
  display: inline-flex;
  gap: 9px;
  align-items: center;
  color: var(--gold);
  user-select: none;
}

.planetra-logo {
  width: 30px;
  height: 30px;
  display: block;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.brand-logo {
  width: auto;
  max-width: 180px;
  height: 32px;
  display: block;
  object-fit: contain;
  object-position: left center;
  user-select: none;
  -webkit-user-drag: none;
}

.login-panel {
  width: min(100%, 380px);
  display: grid;
  gap: 22px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
}

.login-title {
  display: grid;
  gap: 8px;
}

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

h1 {
  font-size: clamp(28px, 6vw, 38px);
  line-height: 0.98;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  font-size: 20px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: 0;
}

h3 {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

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

.form,
.form-grid,
.stack {
  display: grid;
  gap: 12px;
}

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

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.field-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

label,
.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: var(--input-bg);
  color: var(--text);
}

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

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  border-color: var(--gold-strong);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent);
  outline: none;
}

.button,
.link-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--button-bg);
  color: var(--button-text);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.button:hover,
.link-button:hover {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--button-bg) 84%, var(--gold));
}

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

.button-primary:hover {
  background: var(--gold-strong);
}

.button-danger {
  color: var(--danger);
}

.button-small {
  min-height: 36px;
  padding-inline: 11px;
  font-size: 13px;
}

.theme-toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--button-bg);
  color: var(--button-text);
  font-weight: 800;
}

.theme-toggle-track {
  width: 38px;
  height: 22px;
  position: relative;
  flex: 0 0 auto;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-soft) 76%, var(--bg));
  box-shadow: inset 0 0 0 1px var(--line);
}

.theme-toggle-thumb {
  width: 16px;
  height: 16px;
  position: absolute;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: var(--gold);
  transition: transform 160ms ease, background 160ms ease;
}

.theme-toggle.is-light .theme-toggle-thumb {
  transform: translateX(16px);
  background: var(--gold-strong);
}

.theme-toggle-text {
  min-width: 34px;
  font-size: 11px;
  line-height: 1;
  text-transform: uppercase;
}

.notice {
  min-height: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.3;
}

.notice-error {
  color: var(--danger);
}

.notice-success {
  color: var(--success);
}

.topbar {
  min-height: 68px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px clamp(14px, 2.6vw, 30px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}

.topbar-title {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.topbar-title h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(20px, 3vw, 30px);
  user-select: none;
}

.topbar-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.admin-topbar {
  grid-template-columns: minmax(220px, 0.55fr) minmax(640px, 1fr) minmax(170px, 0.45fr);
}

.admin-topbar-controls {
  min-width: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  justify-self: center;
}

.client-topbar {
  grid-template-columns: minmax(180px, 1fr) minmax(440px, 640px) minmax(120px, 1fr);
  align-items: center;
}

.client-topbar.no-filters {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.client-topbar.no-filters .client-filter-slot {
  display: none;
}

.client-topbar .client-filters {
  width: 100%;
  padding: 0;
  border-bottom: 0;
  background: transparent;
}

.client-topbar .client-filters select {
  min-height: 38px;
}

.client-topbar .topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.client-topbar .topbar-actions .topbar-meta {
  flex: 0 0 100%;
  text-align: right;
}

.client-shell,
.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
}

.client-shell[data-theme="dark"],
.admin-shell[data-theme="dark"] {
  color-scheme: dark;
}

.client-shell[data-theme="light"],
.admin-shell[data-theme="light"] {
  color-scheme: light;
}

.admin-shell[data-theme="dark"] {
  --bg: #07172b;
  --panel: #0d213d;
  --panel-soft: #132b4c;
  --panel-strong: #173763;
  --line: rgba(180, 202, 235, 0.2);
  --line-strong: rgba(91, 171, 239, 0.5);
  --text: #eef6ff;
  --muted: #9fb1ca;
  --muted-strong: #c7d8ef;
  --gold: #54b9f0;
  --gold-strong: #ffb23e;
  --primary-text: #07172b;
  --input-bg: #091b33;
  --button-bg: #102a4e;
  --button-text: #eef6ff;
  --frame-bg: #07172b;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.32);
}

.dashboard-workspace {
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel) 10%, transparent), transparent 180px),
    var(--bg);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px clamp(14px, 2.6vw, 30px);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, var(--panel-soft));
}

.client-view-tabs {
  position: sticky;
  top: var(--client-topbar-height, 90px);
  z-index: 15;
  gap: 10px;
  padding-block: 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
}

.tab {
  min-height: 38px;
  flex: 0 0 auto;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted-strong);
  font-weight: 700;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.tab.is-active {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  color: var(--text);
}

.client-filters {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(220px, 320px);
  gap: 10px;
  align-items: start;
  padding: 12px clamp(14px, 2.6vw, 30px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, var(--panel));
}

.client-category-filter {
  grid-template-columns: minmax(220px, 320px);
  justify-content: center;
}

.client-filters select {
  min-height: 40px;
}

.dashboard-frame-wrap {
  min-width: 0;
  min-height: 620px;
  height: 76vh;
  border: 1px solid color-mix(in srgb, var(--gold) 42%, var(--line));
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--frame-bg);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--gold) 10%, transparent),
    0 14px 34px color-mix(in srgb, var(--bg) 76%, #000000);
}

.dashboard-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--frame-bg);
}

.status-chart-wrap {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 18px 18px 12px;
}

.status-chart-canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.status-chart-canvas {
  width: 100% !important;
  height: 100% !important;
}

.status-chart-message {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.status-chart-message[hidden] {
  display: none;
}

.status-chart-message.is-error {
  color: var(--danger);
}

.status-chart-source {
  justify-self: start;
  color: var(--muted);
  font-size: 13px;
}

.dashboard-stack {
  display: grid;
  gap: 22px;
  padding: 16px clamp(14px, 2.6vw, 30px) 30px;
}

.dashboard-stack:not(:has(.dashboard-panel + .dashboard-panel)) {
  grid-template-columns: minmax(0, 1fr);
}

.operational-stack {
  display: grid;
  gap: 22px;
  padding: 16px clamp(14px, 2.6vw, 30px) 30px;
}

.dashboard-row-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

.dashboard-panel {
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--gold) 22%, var(--line));
  border-radius: calc(var(--radius) + 4px);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--gold) 7%, transparent), transparent 150px),
    color-mix(in srgb, var(--panel) 74%, transparent);
  box-shadow: 0 16px 42px color-mix(in srgb, var(--bg) 82%, #000000);
}

.dashboard-panel-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 2px 2px 0;
}

.dashboard-panel-head h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.admin-workspace {
  min-width: 0;
  width: min(100%, 1180px);
  margin: 0 auto;
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 18px clamp(14px, 2.6vw, 30px) 34px;
}

.admin-nav {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
}

.admin-nav .tab {
  flex: 0 0 auto;
}

.panel {
  display: grid;
  gap: 16px;
  align-self: start;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
}

.panel + .panel {
  margin-top: 16px;
}

.panel-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.client-card {
  display: grid;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.client-card:first-child {
  padding-top: 0;
  border-top: 0;
}

.row-form,
.dashboard-row {
  display: grid;
  gap: 10px;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

.row-form:first-child,
.dashboard-row:first-child {
  padding-top: 0;
  border-top: 0;
}

.client-row-grid {
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 0.7fr) minmax(140px, 0.8fr) minmax(140px, 0.8fr) 86px auto;
}

.client-card .row-form {
  padding-top: 0;
  border-top: 0;
}

.client-card-summary {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel-soft) 52%, var(--panel));
}

.summary-line {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.summary-label {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.8;
  text-transform: uppercase;
}

.summary-chips,
.dashboard-tab-chips {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.summary-chip {
  max-width: 260px;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 88%, var(--panel-soft));
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted-chip {
  color: var(--muted);
}

.dashboard-row-grid {
  grid-template-columns: minmax(160px, 0.9fr) minmax(240px, 1.5fr) 90px 86px auto;
}

.dashboard-tab-row-grid {
  grid-template-columns: minmax(180px, 1fr) 100px 92px auto;
}

.access-row {
  gap: 14px;
}

.access-row-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(180px, 0.9fr) 92px auto;
  gap: 10px;
  align-items: end;
}

.row-grid {
  display: grid;
  gap: 10px;
  align-items: end;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.checkbox-field {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-strong);
  font-size: 14px;
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.password-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.admin-client-name {
  color: var(--gold);
}

.admin-client-picker {
  max-width: 420px;
}

.admin-client-picker.compact {
  width: 220px;
  max-width: 220px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-client-picker.compact span {
  flex: 0 0 auto;
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.admin-client-picker.compact select {
  min-width: 0;
  min-height: 48px;
}

.admin-client-picker.compact.is-placeholder {
  visibility: hidden;
  pointer-events: none;
}

.design-form {
  align-items: end;
}

.design-preview {
  min-height: 150px;
  grid-column: 1 / -1;
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

.design-preview-top,
.design-preview-body {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.design-preview-body {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.design-colors {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.color-line {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
}

.color-input {
  min-height: 44px;
  padding: 4px;
}

.empty-state.compact {
  min-height: 120px;
}

.dashboard-tab-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: color-mix(in srgb, var(--panel) 96%, var(--bg));
}

.dashboard-tab-toggle {
  width: 100%;
  min-height: 64px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  text-align: left;
}

.dashboard-tab-main {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.dashboard-tab-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-tab-item.is-open .dashboard-tab-toggle {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--gold) 9%, transparent);
}

.dashboard-tab-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.dashboard-tab-body .row-form:first-child {
  border-top: 0;
  padding-top: 0;
}

.dashboard-tab-content-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.access-dashboard-list {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.access-dashboard-option {
  min-height: 54px;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel-soft) 70%, transparent);
  color: var(--text);
}

.access-dashboard-option input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--gold);
}

.access-dashboard-option span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.access-dashboard-option strong,
.access-dashboard-option small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.access-dashboard-option small {
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.72);
}

.modal-panel {
  width: min(100%, 620px);
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-panel-wide {
  width: min(100%, 820px);
}

.modal-head,
.modal-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.modal-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .client-view-tabs {
    position: static;
  }

  .form-grid,
  .client-row-grid,
  .summary-line,
  .dashboard-row-grid,
  .dashboard-tab-row-grid,
  .access-row-grid,
  .access-dashboard-list,
  .design-colors,
  .client-filters {
    grid-template-columns: 1fr;
  }

  .client-topbar {
    grid-template-columns: 1fr;
  }

  .admin-topbar {
    grid-template-columns: 1fr auto;
  }

  .admin-topbar-controls {
    grid-column: 1 / -1;
    justify-self: start;
    flex-wrap: wrap;
  }

  .row-actions {
    justify-content: stretch;
  }

  .row-actions .button {
    flex: 1;
  }

  .dashboard-tab-toggle {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (min-width: 1600px) {
  .dashboard-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .dashboard-row-divider {
    grid-column: 1 / -1;
  }

  .dashboard-frame-wrap {
    height: 68vh;
    min-height: 540px;
  }
}

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .topbar-title h1 {
    white-space: normal;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .admin-topbar {
    grid-template-columns: 1fr;
  }

  .admin-nav {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .admin-client-picker.compact {
    width: 100%;
    max-width: none;
  }

  .client-topbar .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .button,
  .topbar-actions .link-button {
    flex: 1;
  }

  .login-panel,
  .panel {
    padding: 16px;
  }

  .summary-chip {
    max-width: 100%;
  }

  .password-line {
    grid-template-columns: 1fr;
  }

  .dashboard-frame-wrap {
    min-height: 520px;
    height: 72vh;
  }

  .dashboard-panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-panel-head h2 {
    white-space: normal;
  }

}
