@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=Roboto+Mono:wght@500;600;700&display=swap');

:root {
  color-scheme: light;
  --ink: #102a43;
  --muted: #536b84;
  --soft: #778da4;
  --line: #d5dee8;
  --surface: #ffffff;
  --canvas: #f4f8fb;
  --blue: #123b63;
  --blue-dark: #0b2947;
  --blue-soft: #e8eef5;
  --red: #c62828;
  --red-dark: #9f1d1d;
  --red-soft: #fff1f1;
  --green: #0f766e;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --danger: #b42318;
  --danger-soft: #fff4f2;
  --shadow: 0 14px 42px rgba(16, 42, 67, 0.09);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 0%, rgba(198, 40, 40, 0.08), transparent 22rem),
    radial-gradient(circle at 8% 18%, rgba(18, 59, 99, 0.10), transparent 28rem),
    var(--canvas);
  font-family: 'IBM Plex Sans', 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.topbar {
  position: relative;
  height: 92px;
  padding: 0 clamp(22px, 5vw, 76px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0;
  background: linear-gradient(105deg, #0b2947 0%, #123b63 72%, #174b79 100%);
  backdrop-filter: blur(16px);
}
.topbar::after { content: ''; position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: linear-gradient(90deg, var(--red) 0 28%, #ef5350 28% 38%, transparent 38%); }

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--blue);
  border: 1px solid rgba(255,255,255,.23);
  border-radius: 14px;
  background: rgba(255,255,255,.12);
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
}
.brand-mark svg { width: 27px; height: 27px; }
.eyebrow, .section-kicker, .card-index, .result-label {
  margin: 0;
  color: var(--blue);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.brand-lockup .eyebrow { color: #b8d4ec; letter-spacing: .18em; }
.wordmark { margin: 0; color: #fff; font-size: 29px; font-weight: 800; letter-spacing: -0.055em; line-height: 1; }
.wordmark span { color: #ff7474; }
.brand-tagline { margin: 6px 0 0; color: rgba(255,255,255,.65); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d4e4f1;
  font-size: 12px;
  font-weight: 600;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  box-shadow: 0 0 0 4px #f1f5f9;
}
.topbar-status.is-ready .status-dot { background: var(--green); box-shadow: 0 0 0 4px #d1fae5; }
.topbar-status.is-error .status-dot { background: var(--danger); box-shadow: 0 0 0 4px #fee2e2; }

.main-content { width: min(1120px, calc(100% - 44px)); margin: 0 auto; padding: 64px 0 30px; }
.intro-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 32px;
  margin-bottom: 34px;
}
.intro-row h1 { max-width: 630px; margin: 8px 0 10px; color: var(--ink); font-size: clamp(30px, 4vw, 47px); line-height: 1.07; letter-spacing: -0.055em; }
.intro-copy { max-width: 650px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.unit-control { width: 228px; flex: 0 0 228px; }
.unit-control label { display: block; margin-bottom: 7px; color: var(--ink); font-size: 12px; font-weight: 700; }
.select-wrap { position: relative; }
.unit-control select {
  width: 100%;
  height: 42px;
  padding: 0 36px 0 13px;
  appearance: none;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
}
.unit-control select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.12); }
.select-wrap svg { position: absolute; width: 18px; height: 18px; top: 12px; right: 10px; color: var(--soft); pointer-events: none; }
.unit-control > span { display: block; margin-top: 7px; color: var(--soft); font-size: 11px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.card { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.input-card, .result-card { padding: clamp(22px, 3vw, 32px); }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid #edf2f7; }
.card-heading h2 { margin: 6px 0 0; color: var(--ink); font-size: 19px; letter-spacing: -0.025em; }
.card-index { color: var(--soft); font-family: 'Roboto Mono', monospace; font-size: 10px; letter-spacing: 0.08em; }
.scale-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--blue); border-radius: 10px; background: var(--blue-soft); }
.scale-icon svg { width: 23px; height: 23px; }
.fields-stack { padding-top: 24px; }
.field-group { margin-bottom: 21px; }
.field-group:last-child { margin-bottom: 0; }
.field-group label { display: flex; align-items: baseline; gap: 7px; margin-bottom: 8px; color: var(--ink); font-size: 13px; font-weight: 700; }
.field-group label span { color: var(--soft); font-size: 11px; font-weight: 500; }
.input-shell { position: relative; }
.input-shell input {
  width: 100%;
  height: 53px;
  padding: 0 65px 0 15px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #fbfdff;
  font-family: 'Roboto Mono', monospace;
  font-size: 19px;
  font-weight: 600;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.input-shell input::placeholder { color: #b8c6d4; }
.input-shell input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.12); background: #fff; }
.input-shell input.has-error { border-color: #e58a8a; background: var(--red-soft); }
.input-shell input.has-value { border-color: #9ccfe8; background: #fafdff; }
.input-unit { position: absolute; top: 17px; right: 15px; color: var(--soft); font-family: 'Roboto Mono', monospace; font-size: 12px; font-weight: 600; }
.field-message { min-height: 15px; margin: 5px 2px 0; color: var(--danger); font-size: 11px; line-height: 1.35; }
.formula-note { display: flex; align-items: flex-start; gap: 9px; margin-top: 25px; padding: 12px 13px; color: var(--blue-dark); border: 1px solid #c9e9f8; border-radius: 9px; background: #f3fbff; }
.formula-note svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }
.formula-note p { margin: 0; font-size: 11px; line-height: 1.5; }
.formula-note strong { font-weight: 700; }

.result-card { display: flex; flex-direction: column; }
.result-heading { align-items: center; }
.result-status { padding: 5px 9px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; background: #f8fafc; font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.result-status.is-valid { color: var(--green); border-color: #a7f3d0; background: var(--green-soft); }
.result-status.is-error { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }
.result-display { min-height: 172px; display: flex; flex-direction: column; justify-content: center; padding: 31px 0 28px; }
.result-label { color: var(--soft); font-size: 10px; }
.result-number-row { display: flex; align-items: baseline; gap: 11px; margin-top: 8px; }
.result-number-row strong { color: var(--blue); font-family: 'Roboto Mono', monospace; font-size: clamp(42px, 6vw, 64px); line-height: 1; letter-spacing: -0.09em; }
.result-number-row span { color: var(--ink); font-size: 15px; font-weight: 600; }
.result-helper { max-width: 340px; margin: 13px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.result-display.is-empty .result-number-row strong { color: #bccbd9; }
.result-display.is-valid { border-left: 3px solid #38bdf8; padding-left: 18px; }
.result-display.is-error { border-left: 3px solid var(--red); padding-left: 18px; }
.breakdown { margin-top: auto; padding: 15px 0 14px; border-top: 1px solid #edf2f7; border-bottom: 1px solid #edf2f7; }
.breakdown-row { display: flex; justify-content: space-between; gap: 20px; padding: 6px 0; color: var(--muted); font-size: 12px; }
.breakdown-row strong { color: var(--ink); font-family: 'Roboto Mono', monospace; font-size: 12px; font-weight: 600; }
.breakdown-row small { color: var(--soft); font-size: 10px; font-weight: 500; }
.minus-row span::before { content: '−'; margin-right: 6px; color: var(--soft); }
.total-row { margin-top: 5px; padding-top: 11px; color: var(--ink); border-top: 1px dashed #d9e2ec; font-weight: 700; }
.total-row strong { color: var(--blue); font-size: 13px; }
.clear-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 43px; margin-top: 21px; color: var(--blue-dark); border: 1px solid #bae6fd; border-radius: 9px; background: #f0f9ff; font-size: 12px; font-weight: 700; transition: background 150ms ease, border-color 150ms ease, transform 150ms ease; }
.clear-button svg { width: 17px; height: 17px; }
.clear-button:hover { border-color: #7dd3fc; background: var(--blue-soft); }
.clear-button:active { transform: translateY(1px); }

.app-footer { display: flex; align-items: center; gap: 13px; padding: 26px 0 0; color: var(--soft); font-size: 10px; letter-spacing: 0.04em; text-align: center; }
.footer-rule { height: 1px; flex: 1; background: #dce7ef; }

@media (max-width: 760px) {
  .topbar { height: 82px; padding: 0 18px; }
  .topbar-status { font-size: 0; }
  .topbar-status .status-dot { width: 9px; height: 9px; }
  .main-content { width: min(100% - 32px, 580px); padding-top: 38px; }
  .intro-row { display: block; margin-bottom: 26px; }
  .intro-row h1 { font-size: 36px; }
  .unit-control { width: 100%; margin-top: 24px; }
  .workspace { grid-template-columns: 1fr; gap: 16px; }
  .result-card { min-height: 0; }
  .result-display { min-height: 150px; }
  .app-footer { padding-bottom: 15px; }
}

@media (max-width: 420px) {
  .main-content { width: min(100% - 24px, 580px); }
  .topbar { padding: 0 14px; }
  .input-card, .result-card { padding: 20px; }
  .intro-row h1 { font-size: 32px; }
  .wordmark { font-size: 24px; }
  .brand-mark { width: 36px; height: 36px; }
  .result-number-row strong { font-size: 47px; }
}


/* Navegação entre cálculo e memória */
.tab-nav { display: flex; align-items: center; gap: 5px; margin-bottom: 20px; padding: 5px; border: 1px solid #c7d5e2; border-radius: 14px; background: rgba(255, 255, 255, 0.86); box-shadow: 0 8px 24px rgba(16,42,67,.06); }
.tab-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; flex: 1 1 0; min-height: 42px; padding: 0 10px; color: var(--muted); border: 0; border-radius: 9px; background: transparent; font-size: 12px; font-weight: 700; transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 150ms ease; }
.tab-button svg { width: 17px; height: 17px; }
.tab-button:hover { color: var(--blue-dark); background: #f0f6fb; }
.tab-button.is-active { color: #fff; background: var(--blue); box-shadow: 0 5px 12px rgba(18,59,99,.2); }
.tab-count { min-width: 20px; padding: 2px 6px; color: var(--blue-dark); border-radius: 99px; background: #fff; font-family: 'Roboto Mono', monospace; font-size: 10px; text-align: center; }
.tab-panel { display: none; }
.tab-panel.is-visible { display: block; }

.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 21px; }
.result-actions .clear-button { margin-top: 0; }
.register-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 43px; color: #fff; border: 1px solid var(--red); border-radius: 9px; background: var(--red); font-size: 12px; font-weight: 700; transition: background 150ms ease, border-color 150ms ease, transform 150ms ease; }
.register-button svg { width: 17px; height: 17px; }
.register-button:hover:not(:disabled) { border-color: var(--red-dark); background: var(--red-dark); }
.register-button:active:not(:disabled) { transform: translateY(1px); }
.register-button:disabled { cursor: not-allowed; opacity: 0.42; }
.register-feedback { min-height: 17px; margin: 9px 0 -2px; color: var(--green); font-size: 11px; font-weight: 600; text-align: center; }
.register-feedback.is-success { animation: feedback-in 180ms ease-out; }
@keyframes feedback-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }

.memory-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 25px; margin-bottom: 20px; }
.memory-toolbar h2 { margin: 7px 0 6px; color: var(--ink); font-size: clamp(24px, 3vw, 32px); letter-spacing: -0.045em; }
.memory-toolbar p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.outline-danger-button { display: inline-flex; align-items: center; gap: 7px; min-height: 39px; padding: 0 12px; color: var(--danger); border: 1px solid #fecaca; border-radius: 9px; background: #fffafa; font-size: 11px; font-weight: 700; white-space: nowrap; }
.outline-danger-button:hover:not(:disabled) { background: var(--danger-soft); }
.outline-danger-button:disabled { cursor: not-allowed; opacity: 0.45; }
.outline-danger-button svg { width: 16px; height: 16px; }
.memory-summary-grid { display: grid; grid-template-columns: 1.25fr 1fr 1.25fr; gap: 14px; margin-bottom: 20px; }
.memory-summary-card { min-height: 126px; padding: 20px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: 0 8px 22px rgba(16, 42, 67, 0.045); }
.memory-summary-card span, .memory-summary-card small { display: block; color: var(--muted); font-size: 11px; }
.memory-summary-card strong { display: block; margin: 10px 0 3px; color: var(--ink); font-family: 'Roboto Mono', monospace; font-size: 28px; letter-spacing: -0.06em; }
.memory-summary-card.primary-summary { border-color: #bae6fd; background: linear-gradient(135deg, #f0f9ff, #fff); }
.memory-summary-card.primary-summary strong { color: var(--blue); font-size: 38px; }
.memory-list { display: grid; gap: 10px; }
.memory-record { display: grid; grid-template-columns: 40px minmax(0, 1fr) 36px; gap: 14px; align-items: center; padding: 16px 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 6px 18px rgba(16, 42, 67, 0.035); }
.memory-record-index { display: grid; place-items: center; width: 32px; height: 32px; color: var(--blue); border-radius: 9px; background: var(--blue-soft); font-family: 'Roboto Mono', monospace; font-size: 11px; font-weight: 700; }
.memory-record-topline { display: flex; align-items: baseline; justify-content: space-between; gap: 15px; }
.memory-record-topline strong { color: var(--blue-dark); font-family: 'Roboto Mono', monospace; font-size: 16px; }
.memory-record-topline span { color: var(--soft); font-size: 10px; white-space: nowrap; }
.memory-record-main p { margin: 6px 0 4px; color: var(--muted); font-size: 11px; }
.memory-record-main p b { color: var(--ink); }
.memory-record-main small { color: var(--soft); font-size: 10px; }
.delete-record-button { display: grid; place-items: center; width: 32px; height: 32px; color: var(--soft); border: 1px solid transparent; border-radius: 8px; background: transparent; }
.delete-record-button:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }
.delete-record-button svg { width: 17px; height: 17px; }
.memory-empty { display: flex; flex-direction: column; align-items: center; padding: 54px 22px; border: 1px dashed #bfd0df; border-radius: 14px; background: rgba(255, 255, 255, 0.6); text-align: center; }
.memory-empty-icon { display: grid; place-items: center; width: 47px; height: 47px; color: var(--blue); border-radius: 12px; background: var(--blue-soft); }
.memory-empty-icon svg { width: 24px; height: 24px; }
.memory-empty h3 { margin: 16px 0 6px; color: var(--ink); font-size: 16px; }
.memory-empty p { max-width: 390px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.empty-action { margin-top: 17px; padding: 8px 13px; color: var(--blue-dark); border: 1px solid #bae6fd; border-radius: 8px; background: #f0f9ff; font-size: 11px; font-weight: 700; }

@media (max-width: 760px) {
  .tab-nav { overflow: hidden; }
  .result-actions { grid-template-columns: 1fr; }
  .memory-toolbar { display: block; }
  .outline-danger-button { margin-top: 16px; }
  .memory-summary-grid { grid-template-columns: 1fr 1fr; }
  .memory-summary-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  .memory-summary-grid { grid-template-columns: 1fr; }
  .memory-summary-card:last-child { grid-column: auto; }
  .memory-record { grid-template-columns: 32px minmax(0, 1fr) 28px; gap: 10px; padding: 13px 11px; }
  .memory-record-topline { display: block; }
  .memory-record-topline span { display: block; margin-top: 4px; }
}


/* Identificação e saída do inventário */
.memory-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 9px; }
.piece-code-field { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 11px; font-weight: 700; }
.piece-code-field input { width: 190px; height: 38px; padding: 0 11px; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; outline: none; background: #fff; font-family: 'Roboto Mono', monospace; font-size: 12px; font-weight: 600; }
.piece-code-field input::placeholder { color: #a8b8c8; font-family: 'IBM Plex Sans', sans-serif; font-weight: 500; }
.piece-code-field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(18, 59, 99, 0.12); }
.memory-export-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.export-button { display: inline-flex; align-items: center; gap: 6px; min-height: 35px; padding: 0 10px; color: var(--blue-dark); border: 1px solid #b8c8d8; border-radius: 8px; background: #fff; font-size: 10px; font-weight: 700; white-space: nowrap; }
.export-button:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-soft); }
.export-button:disabled { cursor: not-allowed; opacity: 0.42; }
.export-button svg { width: 15px; height: 15px; }
.export-button.save-button { color: #fff; border-color: var(--red); background: var(--red); }
.export-button.save-button:hover:not(:disabled) { border-color: var(--red-dark); background: var(--red-dark); }
.export-feedback { min-height: 15px; margin: 0; color: var(--green); font-size: 10px; font-weight: 600; text-align: right; }
.export-feedback.is-error { color: var(--red); }

.common-calculator-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr); gap: 20px; align-items: stretch; }
.common-calculator-card { padding: clamp(22px, 3vw, 32px); }
.common-display { min-height: 78px; display: flex; align-items: flex-end; justify-content: flex-end; padding: 23px 5px 0; color: var(--blue-dark); font-family: 'Roboto Mono', monospace; font-size: clamp(35px, 7vw, 58px); font-weight: 700; letter-spacing: -.07em; overflow-wrap: anywhere; }
.common-expression { min-height: 23px; padding: 8px 5px 13px; color: var(--soft); font-family: 'Roboto Mono', monospace; font-size: 11px; text-align: right; }
.common-keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding-top: 15px; border-top: 1px solid #edf2f7; }
.common-keypad button { min-height: 48px; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; background: #f8fbfd; font-family: 'Roboto Mono', monospace; font-size: 16px; font-weight: 700; }
.common-keypad button:hover { border-color: var(--blue); background: var(--blue-soft); }
.common-keypad .operator-key { color: var(--blue-dark); background: var(--blue-soft); }
.common-keypad .equals-key { color: #fff; border-color: var(--red); background: var(--red); }
.common-keypad .equals-key:hover { border-color: var(--red-dark); background: var(--red-dark); }
.common-keypad .zero-key { grid-column: span 2; }
.common-register-button { margin-top: 15px; }
.common-help-card { display: flex; flex-direction: column; justify-content: center; padding: clamp(22px, 3vw, 32px); border: 1px solid #c9e9f8; border-radius: 16px; background: linear-gradient(145deg, #f3fbff, #fff); }
.common-help-card h2 { margin: 8px 0 10px; color: var(--ink); font-size: 22px; letter-spacing: -.035em; }
.common-help-card p { margin: 0 0 13px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.common-help-card .common-example { padding: 12px; color: var(--blue-dark); border-radius: 9px; background: var(--blue-soft); font-size: 12px; }
.common-help-card .clear-button { margin-top: 10px; }

@media (max-width: 860px) {
  .memory-toolbar { align-items: stretch; }
  .memory-tools { align-items: stretch; }
  .memory-export-actions { justify-content: flex-start; }
  .export-feedback { text-align: left; }
  .common-calculator-layout { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .piece-code-field { display: block; }
  .piece-code-field input { display: block; width: 100%; margin-top: 6px; }
  .memory-export-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .memory-export-actions .export-button, .memory-export-actions .outline-danger-button { justify-content: center; }
  .tab-nav { overflow: hidden; }
  .tab-button { gap: 4px; padding: 0 5px; font-size: 11px; }
  .tab-button svg { width: 15px; height: 15px; }
}
