:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --border: #dbe3ee;
  --warn: #b45309;
  --tap-min: 44px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  margin: 0;
  background: linear-gradient(135deg, #f8fafc 0%, #ecfeff 100%);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--border);
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  backdrop-filter: blur(8px);
  z-index: 5;
  max-width: 100%;
  min-width: 0;
}

.topbar-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
  width: 100%;
  min-width: 0;
}

.currency-switch {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.currency-btn {
  margin: 0;
  min-height: 42px;
  min-width: 0;
  padding: 8px 12px;
  border: none;
  border-radius: 0;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  touch-action: manipulation;
}

.currency-btn + .currency-btn {
  border-left: 1px solid var(--border);
}

.currency-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.app-title {
  flex: 1 1 12rem;
  max-width: 100%;
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  cursor: default;
}

.engineer-hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

body.engineer-mode .meta {
  overflow-wrap: anywhere;
  word-break: break-word;
}

kbd {
  display: inline-block;
  padding: 0.12em 0.45em;
  font-size: 0.8em;
  font-family: ui-monospace, monospace;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f1f5f9;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
}

h1,
h2,
h3 {
  margin: 0 0 10px;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.layout {
  width: 100%;
  max-width: 1200px;
  min-width: 0;
  margin: 24px auto;
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  display: grid;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  min-width: 0;
  max-width: 100%;
}

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

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

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

.grid-3 {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

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

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: #334155;
}

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

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: var(--tap-min);
  background: #fff;
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
}

button {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: var(--tap-min);
  background: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  button:hover {
    border-color: #94a3b8;
  }
}

@media (hover: none) {
  button:active {
    background: #f1f5f9;
  }
}

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

.muted {
  color: var(--muted);
}

.hidden {
  display: none;
}

.details {
  margin: 0;
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 6px 8px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
}

.price-box {
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px;
}

.price-box strong {
  font-size: 22px;
  color: #0f172a;
}

.mode {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.mode > label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap-min);
  padding: 4px 0;
  cursor: pointer;
  touch-action: manipulation;
}

.mode input[type="radio"] {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 1.15rem;
  flex-shrink: 0;
}

.mode legend {
  color: var(--muted);
  padding: 0 6px;
}

.options {
  display: grid;
  gap: 8px;
}

.option-item {
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: var(--tap-min);
}

.option-item input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  min-height: 1.15rem;
  flex-shrink: 0;
}

.total {
  margin-top: 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.total strong {
  font-size: 28px;
  color: var(--accent);
}

.hint {
  color: var(--warn);
  font-size: 13px;
  margin-top: 6px;
}

.table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 900px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 8px;
  font-size: 13px;
}

thead th {
  background: #f8fafc;
  position: sticky;
  top: 0;
}

.span-3 {
  grid-column: span 3;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.engineer-intro {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
}

.engineer-subhead {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.engineer-table-title {
  margin: 16px 0 8px;
  font-size: 15px;
}

.h2-plain {
  margin-bottom: 0;
}

.button-secondary {
  border-color: #cbd5e1;
  background: #f8fafc;
}

@media (max-width: 980px) {
  .grid-4,
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .span-3 {
    grid-column: span 1;
  }

  .card-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .card-head .actions {
    width: 100%;
  }

  .card-head .actions button {
    flex: 1 1 auto;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 1.25rem;
    line-height: 1.3;
    word-break: break-word;
  }

  h2 {
    font-size: 1.1rem;
  }

  .meta {
    font-size: 12px;
    line-height: 1.45;
    word-break: break-word;
  }

  .layout {
    margin-top: 12px;
    gap: 12px;
  }

  .card {
    padding: 14px;
    border-radius: 12px;
  }

  .details {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  .details dt {
    margin-top: 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  .details dt:first-of-type {
    margin-top: 0;
  }

  .details dd {
    font-size: 15px;
    line-height: 1.45;
    word-break: break-word;
    overflow-wrap: anywhere;
    padding-bottom: 4px;
    border-bottom: 1px solid #f1f5f9;
  }

  .details dd:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .price-box {
    padding: 12px;
  }

  .price-box strong {
    font-size: clamp(1rem, 5vw, 1.35rem);
    word-break: break-word;
  }

  .total {
    flex-wrap: wrap;
  }

  .total strong {
    font-size: clamp(1.35rem, 6vw, 1.75rem);
  }

  .mode {
    flex-direction: column;
    align-items: stretch;
  }

  .mode > label {
    padding: 8px 10px;
    margin: 0 -4px;
    border-radius: 10px;
    border: 1px solid transparent;
  }

  .mode > label:active {
    background: #f8fafc;
    border-color: var(--border);
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 12px;
  }

  .row-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .row-actions button {
    min-height: var(--tap-min);
    width: 100%;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }
}
