:root {
  --swiss-red: #c1121f;
  --swiss-red-dark: #780000;
  --alpine-blue: #1b4965;
  --stone: #f7f5f2;
  --card: #ffffff;
  --border: #e4e1db;
  --text: #1b1b1b;
  --muted: #6c6c6c;
  --success: #2f9e44;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, rgba(241, 242, 248, 0.9), var(--stone));
  color: var(--text);
}

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

.app-header {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1.25rem 2.5rem;
  background: var(--card);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-weight: 600;
  font-size: 1.2rem;
}

.header-actions {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  transition: max-height 0.25s ease, opacity 0.25s ease;
  overflow: hidden;
}

.app-header.collapsed #header-actions {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.icon-btn {
  border: none;
  padding: 0.35rem 1rem;
  border-radius: 999px;
}

.header-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.backup-indicator {
  font-size: 0.9rem;
  color: var(--muted);
}

button {
  border: none;
  background: var(--swiss-red);
  color: #fff;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button.ghost {
  background: rgba(193, 18, 31, 0.12);
  color: var(--swiss-red);
}

button.ghost.subtle {
  background: rgba(27, 73, 101, 0.12);
  color: var(--alpine-blue);
}

button.pill {
  border-radius: 999px;
}

button.primary {
  background: var(--swiss-red);
  color: #fff;
}

button.danger {
  background: var(--swiss-red-dark);
}

button.danger.ghost {
  background: rgba(120, 0, 0, 0.12);
  color: var(--swiss-red-dark);
}

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.55rem 0.9rem;
  width: 100%;
  background: #fff;
}

textarea {
  resize: vertical;
}

main {
  max-width: 1600px;
  margin: 0 auto;
}

.app-grid {
  display: grid;
  grid-template-columns: 0.85fr 1.4fr 0.85fr;
  gap: 1.2rem;
  padding: 1.5rem 2rem 3rem;
}

section {
  background: var(--card);
  border-radius: 1.3rem;
  padding: 1.4rem;
  box-shadow: 0 20px 45px rgba(12, 8, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.panel-header.stack {
  flex-direction: column;
}

.panel-header.stack .panel-buttons,
.panel-header.stack .detail-actions {
  justify-content: flex-start;
}

.panel-description {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.panel-heading {
  flex: 1;
}

.panel-buttons button {
  width: auto;
}

.stack-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.stack-buttons button {
  width: 100%;
}

.detail-panel .panel-description {
  margin-left: 0;
}

.detail-panel .panel-header {
  align-items: flex-start;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.list-panel input[type='search'] {
  background: #f8f9fb;
}

.list-wrapper {
  position: relative;
  max-height: 420px;
  overflow-y: auto;
  border-radius: 1rem;
  padding-bottom: 1.2rem;
}

.list-wrapper .list-fade {
  position: sticky;
  bottom: 0;
  height: 2.5rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, var(--card) 100%);
  pointer-events: none;
}

.list-hint {
  color: var(--muted);
  font-size: 0.8rem;
}

.tab-switcher {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-radius: 0.9rem;
  background: #f3f4f6;
  padding: 0.2rem;
}

.tab-switcher .tab {
  border-radius: 0.8rem;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.tab-switcher .tab.active {
  background: var(--swiss-red);
  color: #fff;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.item-list li {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.item-list li.active {
  border-color: var(--swiss-red);
  background: rgba(193, 18, 31, 0.08);
}

.item-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

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

.badge {
  background: rgba(27, 73, 101, 0.12);
  color: var(--alpine-blue);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.attribute-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.attribute-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 150px;
}

.attribute-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.card-header h4 {
  margin: 0;
  font-size: 1rem;
}

.card-tools {
  display: flex;
  gap: 0.25rem;
}

.card-tools button {
  background: transparent;
  color: var(--muted);
  padding: 0.25rem;
  border-radius: 0.6rem;
}

.card-tools button:hover {
  background: rgba(27, 73, 101, 0.12);
  color: var(--alpine-blue);
}

.attr-preview {
  border: 1px dashed var(--border);
  border-radius: 0.8rem;
  padding: 0.6rem;
  min-height: 70px;
  font-size: 0.9rem;
  background: #fdfdfd;
}

.attribute-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.attribute-list li {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.attribute-list .attr-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.drag-handle {
  cursor: grab;
  font-size: 1.1rem;
}

.multi-checkbox {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.multi-checkbox__item {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.multi-checkbox__item.active {
  border-color: var(--swiss-red);
  background: rgba(193, 18, 31, 0.12);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--swiss-red);
  color: #fff;
  padding: 0.9rem 1.1rem;
  border-radius: 0.9rem;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 20;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.login-screen {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 6, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
}

.login-card {
  background: var(--card);
  padding: 2rem;
  border-radius: 1.2rem;
  width: min(90vw, 360px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
}

.login-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.hidden {
  display: none !important;
}

#import-json-input {
  display: none;
}

.file-label {
  cursor: pointer;
  display: inline-block;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(193, 18, 31, 0.12);
  color: var(--swiss-red);
}

.attribute-body {
  transition: max-height 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}

.attribute-body.collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.language-hint {
  background: rgba(27, 73, 101, 0.08);
  border-radius: 1rem;
  padding: 0.9rem;
  color: var(--alpine-blue);
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.dialog-note {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

dialog {
  border: none;
  border-radius: 1.2rem;
  padding: 0;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.25);
}

dialog form,
dialog > div {
  padding: 1.5rem;
  border-radius: 1.2rem;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

dialog menu {
  display: flex;
  gap: 0.5rem;
  padding: 0;
  margin: 0;
}

@media (max-width: 1200px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  section {
    min-height: auto;
  }

  .list-wrapper {
    max-height: 360px;
  }
}

@media (max-width: 640px) {
  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }

  .header-actions {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .header-buttons {
    flex-direction: column;
    width: 100%;
  }

  .backup-indicator {
    order: 2;
  }

  .header-actions,
  .panel-buttons {
    width: 100%;
    flex-direction: column;
  }

  button,
  input,
  select {
    width: 100%;
  }

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