:root {
  color-scheme: light;
  --bg: #f9fafb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #4b5563;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --accent: #16805e;
  --danger: #b42318;
  --shadow: 0 10px 22px rgba(17, 24, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  color: var(--ink);
}

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

button,
.button {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-weight: 600;
  min-height: 38px;
  justify-content: center;
  padding: 8px 12px;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: #f9fafb;
  border-color: #cbd5e1;
}

button.primary,
.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

button.primary:hover,
.primary:hover {
  background: var(--brand-dark);
}

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

button.danger:hover {
  background: #fef2f2;
  border-color: #fca5a5;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.ghost {
  background: transparent;
}

button.small {
  min-height: 32px;
  padding: 6px 10px;
}

.icon-button {
  height: 34px;
  min-height: 34px;
  padding: 0;
  width: 34px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  display: block;
  margin-top: 6px;
  min-height: 38px;
  padding: 9px 10px;
  width: 100%;
}

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

label {
  color: #344054;
  display: block;
  font-size: 0.88rem;
  font-weight: 650;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #1f2937;
  font-size: clamp(1.45rem, 2.2vw, 1.9rem);
  font-weight: 750;
}

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

.login-shell {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 430px;
  padding: 32px;
  text-align: center;
  width: 100%;
}

.brand-mark {
  align-items: center;
  background: var(--brand);
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 1.45rem;
  font-weight: 800;
  height: 54px;
  justify-content: center;
  margin-bottom: 18px;
  width: 54px;
}

.login-panel p {
  color: var(--muted);
  margin-top: 8px;
}

.stack {
  display: grid;
  gap: 16px;
  margin-top: 28px;
  text-align: left;
}

.full {
  width: 100%;
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
}

.app-shell {
  margin: 0 auto;
  max-width: 1180px;
  padding: 16px;
}

.topbar,
.toolbar,
.card,
.profiles-panel,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
}

.topbar p {
  color: #6b7280;
  font-size: 0.9rem;
  margin-top: 4px;
}

.topbar-title {
  align-items: center;
  display: flex;
  gap: 12px;
}

.header-mark {
  align-items: center;
  background: var(--brand);
  border-radius: 8px;
  color: #ffffff;
  display: inline-flex;
  font-size: 1.15rem;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.toolbar {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  margin-top: 16px;
  padding: 14px;
}

.file-button input {
  display: none;
}

.notice {
  color: #164c3d;
  margin-top: 14px;
  padding: 12px 14px;
}

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

.layout {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: 300px 1fr;
  margin-top: 16px;
}

.profiles-panel {
  padding: 16px;
  position: sticky;
  top: 12px;
}

.panel-heading,
.section-heading,
.dialog-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.panel-heading span {
  background: #eff6ff;
  border-radius: 999px;
  color: var(--brand);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 3px 9px;
}

.profiles-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: calc(100vh - 265px);
  overflow: auto;
}

.profile-filters {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr;
  margin-top: 10px;
}

.filter-chip {
  align-items: center;
  background: #ffffff;
  border-color: #d1d5db;
  color: #374151;
  display: flex;
  font-size: 0.82rem;
  justify-content: space-between;
  min-height: 32px;
  padding: 5px 9px;
}

.filter-chip.active {
  background: #eff6ff;
  border-color: var(--brand);
  color: var(--brand-dark);
}

.filter-chip strong {
  background: #f3f4f6;
  border-radius: 999px;
  color: #374151;
  font-size: 0.75rem;
  min-width: 28px;
  padding: 3px 7px;
  text-align: center;
}

.filter-chip.active strong {
  background: #dbeafe;
  color: var(--brand-dark);
}

.profile-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  gap: 3px;
  overflow: hidden;
  padding: 9px 10px;
  position: relative;
  text-align: left;
}

.profile-row::before {
  bottom: 0;
  content: "";
  left: 0;
  position: absolute;
  top: 0;
  width: 4px;
}

.profile-row.has-shades {
  border-color: #bbf7d0;
}

.profile-row.has-shades::before {
  background: #22c55e;
}

.profile-row.no-shades::before {
  background: #d1d5db;
}

.profile-row.active {
  border-color: var(--brand);
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.profile-row span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.profile-row strong,
.profile-row > span,
.profile-badges {
  margin-left: 4px;
}

.profile-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.profile-badge {
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 750;
  line-height: 1;
  padding: 4px 6px;
}

.profile-badge.shade {
  background: #dcfce7;
  color: #166534;
}

.profile-badge.light {
  background: #dbeafe;
  color: #1e40af;
}

.profile-badge.climate {
  background: #fef3c7;
  color: #92400e;
}

.profile-badge.audio {
  background: #f3e8ff;
  color: #6b21a8;
}

.profile-badge.video {
  background: #e0f2fe;
  color: #075985;
}

.profile-badge.empty {
  background: #f3f4f6;
  color: #6b7280;
}

.editor {
  display: grid;
  gap: 14px;
}

.card {
  padding: 20px 22px;
}

.card h2 {
  margin-bottom: 14px;
}

.preview-card {
  padding-bottom: 14px;
}

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

#jsonPreview {
  background: #111827;
  border-radius: 6px;
  color: #e5e7eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 14px 0 0;
  max-height: 260px;
  overflow: auto;
  padding: 14px;
  white-space: pre;
}

.grid {
  display: grid;
  gap: 12px;
}

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

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

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

.device-table {
  display: grid;
  gap: 8px;
}

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

.device-row button {
  min-width: 38px;
  padding-left: 8px;
  padding-right: 8px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(16, 24, 40, 0.22);
  padding: 0;
  width: min(640px, calc(100vw - 28px));
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.45);
}

.dialog-card {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.dialog-heading p {
  color: var(--muted);
  margin-top: 4px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.checkbox-row {
  align-items: center;
  display: flex;
  gap: 9px;
}

.checkbox-row input {
  margin: 0;
  min-height: auto;
  width: auto;
}

.bulk-result {
  background: #eff8f4;
  border: 1px solid #b9e3d2;
  border-radius: 7px;
  color: #14533f;
  padding: 11px;
}

@media (max-width: 1060px) {
  .toolbar,
  .grid.five,
  .grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .profiles-panel {
    position: static;
  }

  .profiles-list {
    max-height: 280px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

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

  .toolbar,
  .grid.two,
  .grid.five,
  .grid.four {
    grid-template-columns: 1fr;
  }
}
