:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #2563eb;
  --accent-2: #059669;
  --danger: #a63b3b;
  --shadow: 0 12px 40px rgba(2, 6, 23, 0.06);
  --shadow-strong: 0 18px 50px rgba(37, 99, 235, 0.16);
  --ring: rgba(37, 99, 235, 0.18);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  padding-bottom: 38px;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  height: calc(100vh - 38px);
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 16px;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #f9fafb 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px 8px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 150px;
  height: 44px;
  text-decoration: none;
}

.brand-mark img {
  display: block;
  width: 150px;
  height: 44px;
  object-fit: contain;
}

.brand-block > div:last-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.brand-name {
  color: var(--text);
  font-weight: 900;
  line-height: 1.15;
  text-decoration: none;
  white-space: normal;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 1.25;
  white-space: normal;
}

.brand-subtitle .brand-home-link {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  color: var(--text) !important;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none !important;
}

.brand-subtitle .brand-home-link:hover {
  border-color: var(--accent);
  color: var(--accent) !important;
}

.brand-subtitle,
.group-label,
small {
  color: var(--muted);
}

.panel-section {
  padding: 14px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

h2 {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.template-search {
  display: block;
  margin-bottom: 10px;
}

.template-search input {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.template-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.template-list[hidden] {
  display: none;
}

.home-shell .template-browser {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.home-shell .template-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.home-promo-grid {
  display: grid;
  gap: 8px;
}

.home-promo-card {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  color: #fff;
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.18), transparent 36%),
    linear-gradient(135deg, #0f1d42 0%, #163472 48%, #2850cb 100%);
  border: 1px solid rgba(37, 99, 235, 0.34);
  border-radius: 8px;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.16);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.home-promo-card:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.56);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
  filter: saturate(1.08);
}

.home-promo-card strong {
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
}

.home-promo-card span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.template-button[hidden] {
  display: none !important;
}

.template-button {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 11px 12px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.04);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.template-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: #bfdbfe;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.12);
}

a.template-button {
  color: var(--text);
  text-decoration: none;
}

.template-button span,
.template-button small {
  display: block;
}

.template-button.active {
  border-color: var(--accent);
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.08), transparent 42%),
    #fff;
  box-shadow: inset 3px 0 0 var(--accent), 0 12px 28px rgba(37, 99, 235, 0.14);
}

.template-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.make-auth-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.54);
}

.make-auth-modal.is-open {
  display: flex;
}

.make-auth-dialog {
  width: min(460px, 100%);
  padding: 22px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(2, 6, 23, 0.22);
}

.make-auth-dialog h2 {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.2;
}

.make-auth-dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.make-auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.make-auth-actions a,
.make-auth-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.make-auth-actions a:first-child {
  color: #fff;
  background: #111827;
}

.make-auth-actions a:nth-child(2) {
  color: #fff;
  background: var(--accent);
}

.make-auth-actions button {
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
}

.make-account-widget {
  display: flex;
  align-items: center;
  gap: 4px;
}

.make-account-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 9px;
  color: #fff;
  background: #111827;
  border: 1px solid #111827;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
}

.make-account-button.muted {
  color: var(--text);
  background: #fff;
  border-color: var(--border-strong);
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  padding: 4px 9px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: var(--accent);
  background: #dbeafe;
  font-size: 12px;
  font-weight: 800;
}

.params-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

input:disabled {
  background: #f3f4f6;
  color: #9ca3af;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

fieldset {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.56);
}

legend {
  padding: 0 5px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.segmented label {
  display: block;
  position: relative;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
  font-weight: 800;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.segmented input:checked + span {
  color: #fff;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  border-color: var(--accent);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.2);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--text);
  font-weight: 600;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: relative;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.topbar .template-line {
  color: var(--text);
  font-weight: 700;
}

.topbar .summary-line {
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.language-select {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.language-select select {
  min-height: 36px;
  width: 150px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(2, 6, 23, 0.08);
}

.button.primary {
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
}

.template-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 360px));
  align-content: start;
  align-items: start;
  gap: 14px;
  padding: 18px;
  overflow: auto;
}

.template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  max-width: 360px;
  min-height: 190px;
  padding: 22px;
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.04), transparent 34%),
    linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.template-card p,
.home-note p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.home-mobile-intro {
  display: none;
}

.home-mobile-intro p,
.template-mobile-intro p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.template-mobile-intro {
  display: none;
}

.template-mobile-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.template-mobile-actions .make-account-widget {
  order: 1;
  grid-column: 1 / -1;
  justify-content: stretch;
}

.template-mobile-actions .mobile-copy-link {
  order: 2;
}

.template-mobile-actions .mobile-export-dxf {
  order: 3;
}

.template-mobile-actions .mobile-export-stl {
  order: 4;
}

.template-mobile-actions .make-account-button {
  flex: 1;
  min-height: 36px;
  padding: 8px 12px;
  font-size: 12px;
}

.template-mobile-actions .language-select {
  order: 5;
  grid-column: 1 / -1;
}

.button.secondary {
  background: var(--surface-2);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 320px;
  padding: 10px 12px;
  color: #fff;
  background: #1d2a38;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

@media (min-width: 921px) and (max-width: 1500px) {
  .top-actions .make-account-widget {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }

  .top-actions .make-account-button {
    min-height: 30px;
    padding: 6px 9px;
    border-radius: 7px;
    font-size: 11px;
  }
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

  .home-shell .home-workspace .topbar {
    display: none;
  }

  .home-shell .home-mobile-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
  }

  .home-mobile-intro h2 {
    margin-bottom: 0;
  }

  .home-mobile-language {
    flex: 0 0 150px;
  }

  .template-shell .workspace .topbar {
    display: none;
  }

  .template-shell .template-mobile-intro {
    display: grid;
    gap: 12px;
  }
}
