.metal-main {
  width: min(1320px, calc(100% - 40px));
  margin-inline: auto;
  padding: 1.5rem 0 3rem;
}

.metal-hero { max-width: 720px; margin: 0 0 1.25rem; }
.metal-hero h1 { margin: .25rem 0; }
.metal-hero p { margin: .4rem 0; color: var(--muted); }
.back-link,
.back-link:visited {
  margin-bottom: .55rem;
}
.profile-picker,
.metal-card,
.history-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.compact-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.compact-head h2 { margin: 0; font-size: 1.15rem; }
.section-kicker { margin: 0 0 .2rem; }
.local-note,
.formula-text,
.field-note { color: var(--muted); font-size: .82rem; }
.profile-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .55rem; }
.profile-button {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: .45rem;
  min-width: 0;
  padding: .5rem;
  border: 1px solid var(--brand);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--brand-strong);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: background .18s, border-color .18s, color .18s;
}
.profile-button:hover {
  border-color: var(--brand-strong);
  background: var(--surface);
  color: var(--brand);
}
.profile-button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.profile-button.active { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); }
.profile-button svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 2; }
.profile-button span { font-size: .8rem; line-height: 1.15; }
.metal-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 1rem; margin-top: 1rem; }
.drawing-row { display: flex; align-items: center; gap: 1rem; margin-bottom: .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--surface-2); }
.profile-drawing { flex: 0 0 96px; height: 76px; color: var(--brand); }
.profile-drawing svg { width: 96px; height: 76px; fill: none; stroke: currentColor; stroke-width: 2; }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; }
.field-grid label { display: grid; gap: .3rem; font-size: .85rem; }
.field-grid input,
.field-grid select {
  min-width: 0;
  padding: .55rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
}
.field-grid input:focus,
.field-grid select:focus,
.catalog-controls input:focus,
.catalog-controls select:focus { border-color: var(--brand); outline: 2px solid var(--brand); outline-offset: 1px; }
.material-grid { grid-template-columns: 1fr 1fr; margin-top: .7rem; }
.density-grid { grid-template-columns: minmax(180px, 1fr) 2fr; }
.density-grid label { max-width: 260px; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin: .8rem 0; }
.mode-switch button,
.secondary-button {
  padding: .45rem .6rem;
  border: 1px solid var(--brand);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--brand-strong);
  font-size: .8rem;
  font-weight: 750;
  cursor: pointer;
}
.mode-switch button:hover,
.secondary-button:hover {
  background: var(--surface);
  color: var(--brand);
}
.mode-switch button.active { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); }
.price-details { margin: .8rem 0; }
.price-details summary { margin-bottom: .65rem; color: var(--brand); font-size: .86rem; font-weight: 700; cursor: pointer; }
.primary {
  border: 1px solid var(--brand);
  border-radius: 12px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 800;
  cursor: pointer;
}
.primary:hover { border-color: var(--brand-strong); background: var(--brand-strong); }
.text-button {
  padding: .45rem .7rem;
  border: 1px solid var(--brand);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--brand-strong);
  font-weight: 750;
  cursor: pointer;
}
.text-button:hover { background: var(--surface); color: var(--brand); }
.calculate-button { width: 100%; margin-top: .4rem; }
.form-error { min-height: 1.25rem; margin: .5rem 0; color: #b42318; font-size: .85rem; }
.result-card { display: flex; flex-direction: column; }
.result-empty { padding: 1.3rem 0; color: var(--muted); }
.result-body { display: grid; gap: .55rem; }
.result-primary { padding: .8rem; border-radius: 12px; background: var(--surface-2); color: var(--brand-strong); font-size: 1.45rem; font-weight: 750; }
.result-row { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.result-row span { color: var(--muted); }
.result-actions { margin-top: auto; padding-top: 1rem; }
.result-actions .secondary-button { width: 100%; }
.material-catalog { margin: .8rem 0; padding: .75rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.catalog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: .55rem; }
.catalog-heading h3 { margin: 0; font-size: 1rem; }
.catalog-count { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.catalog-controls { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(155px, 1fr); gap: .5rem; }
.catalog-controls label { min-width: 0; }
.catalog-controls input,
.catalog-controls select { width: 100%; min-width: 0; padding: .58rem .65rem; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); }
.material-list { max-height: 19rem; overflow: auto; margin-top: .55rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.material-category {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: .38rem .65rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--brand);
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.material-row { display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: stretch; gap: .2rem; border-bottom: 1px solid var(--line); }
.material-row:last-child { border-bottom: 0; }
.material-row.selected { background: var(--surface-2); }
.material-star {
  align-self: center;
  width: var(--btn-height-sm);
  height: var(--btn-height-sm);
  margin-left: .3rem;
  padding: 0;
  border: 1px solid var(--amber);
  border-radius: 12px;
  background: var(--surface);
  color: var(--amber);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.material-star:hover,
.material-star:focus-visible,
.material-star.active { border-color: var(--amber); background: var(--amber); color: #fff; outline: 0; }
.material-choice { display: grid; gap: .05rem; width: 100%; padding: .45rem .5rem; border: 0; border-radius: 12px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.material-choice:hover,
.material-choice:focus-visible { background: var(--surface-2); outline: 0; }
.material-choice strong { font-size: .86rem; }
.material-choice span { color: var(--brand-strong); font-size: .74rem; font-weight: 700; }
.material-choice small { overflow: hidden; color: var(--muted); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.selected-material { margin: .5rem 0 0; color: var(--muted); font-size: .76rem; }
.catalog-empty { margin: 0; padding: 1rem; color: var(--muted); text-align: center; }
.history-card { margin-top: 1rem; }
.history-list { display: grid; gap: .55rem; }
.history-item { display: grid; gap: .25rem; padding: .65rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); font-size: .86rem; }
.history-head { display: flex; justify-content: space-between; gap: .75rem; }
.history-head strong { font-size: .85rem; }
.history-item time { color: var(--muted); white-space: nowrap; }
.history-item p { margin: 0; color: var(--muted); font-size: .76rem; }
.history-values { display: flex; flex-wrap: wrap; gap: .35rem; }
.history-values span { padding: .22rem .42rem; border-radius: 8px; background: var(--surface); color: var(--brand-strong); font-size: .75rem; font-weight: 750; }
.hidden { display: none !important; }
[dir="rtl"] .material-star { margin-right: .3rem; margin-left: 0; }
[dir="rtl"] .material-choice { text-align: right; }

@media (max-width: 760px) {
  .metal-main { width: 100%; padding: 1rem .75rem 2rem; }
  .profile-picker,
  .metal-card,
  .history-card { padding: .8rem; border-radius: 14px; }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
  .metal-layout { grid-template-columns: 1fr; gap: .75rem; margin-top: .75rem; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
  .field-grid label:last-child:nth-child(odd) { grid-column: span 2; }
  .profile-drawing { flex-basis: 80px; }
  .profile-drawing svg { width: 80px; }
  .drawing-row { gap: .5rem; padding: .5rem; }
  .formula-text { margin: 0; }
  .result-primary { font-size: 1.25rem; }
  .catalog-controls,
  .density-grid { grid-template-columns: 1fr; }
  .density-grid label { max-width: none; }
  .material-list { max-height: 15rem; }
  .history-head { flex-direction: column; gap: .15rem; }
}

@media (max-width: 360px) {
  .profile-button { grid-template-columns: 30px minmax(0, 1fr); padding: .4rem; }
  .profile-button svg { width: 28px; }
  .field-grid,
  .material-grid { grid-template-columns: 1fr; }
  .field-grid label:last-child:nth-child(odd) { grid-column: auto; }
}
