:root {
  --bg-1: #f2f6f9;
  --bg-2: #dce8ef;
  --panel: #ffffff;
  --text: #13212b;
  --muted: #5a6c79;
  --accent: #0f7a8a;
  --accent-2: #0d5f6b;
  --danger: #b52134;
  --line: #d5e0e7;
  --shadow: 0 12px 30px rgba(17, 48, 64, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 10%, #ffffff, transparent 35%),
    linear-gradient(150deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

body.auth-locked {
  overflow: hidden;
}

body.auth-locked .app {
  display: none;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(150deg, var(--bg-1), var(--bg-2));
  z-index: 999;
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 440px;
}

.app {
  max-width: 1980px;
  margin: 32px auto;
  padding: 0 18px;
  display: grid;
  gap: 20px;
  grid-template-columns: 0.95fr 1fr 1fr;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.55);
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.9rem);
}

h2 {
  margin: 0 0 12px;
  font-size: 1.2rem;
}

h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.subtitle {
  margin: 10px 0 18px;
  color: var(--muted);
}

.constants-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.constants-group {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  font-size: 0.9rem;
}

.constants-accordion {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fcfd;
  padding: 8px 10px 10px;
}

.constants-accordion summary {
  cursor: pointer;
  font-weight: 700;
  color: #27414f;
  user-select: none;
}

.accordion-content {
  margin-top: 10px;
}

.constants-actions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-save {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f5fafc;
  color: #1a3a49;
  font-weight: 700;
  cursor: pointer;
}

.btn-save:hover {
  background: #ecf4f8;
}

.save-msg {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.logout-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.logout-btn svg {
  width: 18px;
  height: 18px;
}

.password-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.toggle-password-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f5fafc;
  color: #1a3a49;
  padding: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.eye-icon {
  width: 18px;
  height: 18px;
}

.toggle-password-btn .eye-off {
  display: none;
}

.toggle-password-btn.is-visible .eye-open {
  display: none;
}

.toggle-password-btn.is-visible .eye-off {
  display: block;
}

.field-grid,
.tier-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field span {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

input,
select,
button {
  font-family: inherit;
  font-size: 1rem;
}

input,
select {
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #f9fcfd;
  color: var(--text);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 122, 138, 0.15);
}

.tier-section {
  margin: 20px 0 14px;
}

.roof-note {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eff7fa;
  color: #164855;
  font-weight: 600;
}

.btn-calc {
  width: 100%;
  height: 48px;
  margin-top: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.btn-calc:hover {
  filter: brightness(1.05);
}

.error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-weight: 600;
}

.result-empty {
  color: var(--muted);
  padding: 12px 0;
}

.hidden {
  display: none;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.kpis article {
  background: #f5fafc;
  border: 1px solid #dbe8ef;
  border-radius: 12px;
  padding: 12px;
}

.kpis p {
  margin: 7px 0 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  min-width: 680px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 10px 8px;
  font-size: 0.93rem;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  color: var(--muted);
  font-size: 0.85rem;
}

.section-accessories {
  margin-top: 18px;
}

.total-uzs-strong {
  margin: 8px 0 12px;
  font-size: 1.35rem;
  font-weight: 800;
  color: #123849;
}

.save-report-btn {
  margin-top: 10px;
}

.summary-right {
  text-align: right;
}

.strong-text {
  font-weight: 800;
  color: #173b4b;
}

.history-row {
  cursor: pointer;
}

.history-row:hover {
  background: #f1f8fb;
}

.meta {
  margin-top: 14px;
  font-size: 0.86rem;
  color: var(--muted);
}

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

  .form-panel {
    order: 1;
    grid-column: 1 / -1;
  }

  .result-panel {
    order: 2;
  }

  .constants-panel {
    order: 3;
    grid-column: auto;
  }

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

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    margin: 16px auto 24px;
  }

  .form-panel {
    order: 1;
    grid-column: auto;
  }

  .result-panel {
    order: 2;
  }

  .constants-panel {
    order: 3;
  }
}

@media (max-width: 700px) {

  .constants-grid,
  .field-grid,
  .tier-grid,
  .kpis {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 16px;
    border-radius: 14px;
  }
}

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

  .panel {
    padding: 12px;
    border-radius: 12px;
  }

  h1 {
    font-size: 1.1rem;
  }

  h2 {
    font-size: 1.05rem;
  }

  input,
  select,
  .btn-calc,
  .btn-save {
    height: 42px;
    font-size: 0.95rem;
  }

  th,
  td {
    font-size: 0.82rem;
    padding: 8px 6px;
  }

  .kpis p,
  .total-uzs-strong,
  .meta,
  #total-uzs-top {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

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

  .logout-btn {
    width: 40px;
  }

  .toggle-password-btn {
    width: 42px;
    height: 42px;
  }
}
