:root {
  --bg: #f0f7f8;
  --surface: #ffffff;
  --primary: #0d6e7a;
  --primary-light: #e6f4f6;
  --primary-dark: #095a64;
  --accent: #2aa9b8;
  --text: #1a2b2e;
  --text-muted: #5c7178;
  --border: #d4e4e7;
  --success: #0d7a4e;
  --shadow: 0 2px 12px rgba(13, 110, 122, 0.07);
  --shadow-input: 0 1px 6px rgba(13, 110, 122, 0.05);
  --radius: 10px;
  --radius-lg: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, #e8f4f6 0%, var(--bg) 40%, #f8fbfc 100%);
  color: var(--text);
  line-height: 1.4;
  font-size: 14px;
}

.app {
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: 0.55rem;
  padding-left: max(0.55rem, env(safe-area-inset-left));
  padding-right: max(0.55rem, env(safe-area-inset-right));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: var(--radius-lg);
  color: white;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon svg {
  width: 18px;
  height: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.base-salary-input {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  gap: 0.2rem;
}

.base-label {
  font-size: 0.68rem;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.base-hint {
  font-size: 0.62rem;
  opacity: 0.9;
  font-style: italic;
  text-align: right;
  line-height: 1.2;
}

.base-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  cursor: pointer;
  margin-top: 0.1rem;
}

.base-check input {
  width: 14px;
  height: 14px;
  accent-color: white;
  flex-shrink: 0;
}

.base-input.is-disabled,
.base-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.base-input {
  width: 8.5rem;
  max-width: 42vw;
  padding: 0.3rem 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary-dark);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: right;
}

.base-input:focus {
  outline: none;
  border-color: white;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

.base-input::-webkit-outer-spin-button,
.base-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.base-input[type="number"] {
  -moz-appearance: textfield;
}

.main-grid {
  display: grid;
  grid-template-rows: auto auto;
  gap: 0.55rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.inputs-card {
  display: flex;
  flex-direction: column;
  padding: 0.7rem 0.75rem;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  background: var(--primary-light);
  padding: 0.3rem;
  border-radius: 10px;
  margin-bottom: 0.55rem;
  flex-shrink: 0;
}

.tab {
  border: none;
  background: transparent;
  padding: 0.5rem 0.35rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.tab.active {
  background: white;
  color: var(--primary-dark);
  box-shadow: 0 2px 6px rgba(13, 110, 122, 0.1);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-hint {
  margin: 0 0 0.55rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.inputs-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-group {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.input-group:focus-within {
  border-color: var(--accent);
  background: white;
  box-shadow: var(--shadow-input);
}

.input-info {
  min-width: 0;
}

.input-info .title {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
}

.input-info .meta {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.input-group input {
  width: 58px;
  padding: 0.4rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  color: var(--primary-dark);
  background: white;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42, 169, 184, 0.12);
}

.input-group input::-webkit-outer-spin-button,
.input-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-group input[type="number"] {
  -moz-appearance: textfield;
}

.result-card {
  padding: 0.55rem 0.65rem;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.result-card h2 {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin-bottom: 0.4rem;
  min-height: 1.1rem;
}

.breakdown-row {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  padding: 0.18rem 0.45rem;
  background: var(--bg);
  border-radius: 6px;
}

.breakdown-row .name {
  color: var(--text-muted);
  font-weight: 500;
}

.breakdown-row .amount {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.breakdown-row.empty {
  background: none;
  padding: 0;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.72rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.55rem;
  border-radius: 8px;
}

.summary-row span {
  font-weight: 500;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.summary-row strong {
  font-size: 0.9rem;
  white-space: nowrap;
}

.gross-row {
  background: var(--bg);
  margin-bottom: 0.4rem;
}

.gross-row strong {
  color: var(--text);
  font-weight: 700;
}

.deductions-block {
  margin-bottom: 0.4rem;
}

.deductions-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.55rem;
  border-radius: 8px;
  background: #fef3f2;
  border: 1px solid #fecdca;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.deductions-summary::-webkit-details-marker {
  display: none;
}

.deductions-summary-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.76rem;
  color: #912018;
}

.deductions-summary-label::before {
  content: "▸";
  display: inline-block;
  font-size: 0.85rem;
  line-height: 1;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.deductions-block[open] .deductions-summary-label::before {
  transform: rotate(90deg);
}

.deductions-summary strong {
  color: #b42318;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
}

.deductions-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.35rem;
  padding: 0.35rem 0.45rem 0.1rem;
  border-left: 2px solid #fecdca;
  margin-left: 0.35rem;
}

.deduction-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.68rem;
  line-height: 1.25;
}

.deduction-row .name {
  color: var(--text-muted);
}

.deduction-row .amount {
  font-weight: 600;
  color: #b42318;
  white-space: nowrap;
}

.extra-deduction {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--border);
}

.extra-deduction-label,
.extra-deduction-amount {
  font-family: inherit;
  font-size: 0.72rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

.extra-deduction-label {
  min-width: 0;
}

.extra-deduction-label::placeholder {
  color: var(--text-muted);
}

.extra-deduction-amount {
  width: 5.5rem;
  font-weight: 600;
  text-align: right;
  color: var(--primary-dark);
}

.extra-deduction-label:focus,
.extra-deduction-amount:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(42, 169, 184, 0.12);
}

.extra-deduction-amount::-webkit-outer-spin-button,
.extra-deduction-amount::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.extra-deduction-amount[type="number"] {
  -moz-appearance: textfield;
}

.options-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.option-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
}

.option-check input {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.option-nested {
  display: none;
  margin-left: 1.1rem;
  padding-left: 0.45rem;
  border-left: 2px solid var(--border);
}

.option-nested.is-visible {
  display: flex;
}

.net-row {
  background: var(--primary-light);
  margin-bottom: 0.3rem;
}

.net-row span {
  color: var(--primary-dark);
  font-weight: 600;
}

.net-row strong {
  font-size: 1.05rem;
  color: var(--success);
  font-weight: 700;
}

.quincena-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 0 0.15rem;
}

.quincena-row span:last-child {
  font-weight: 600;
  color: var(--primary-dark);
  white-space: nowrap;
}

.btn-reset {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.22rem 0.5rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-reset:hover {
  background: var(--bg);
  color: var(--text);
}

@media (min-width: 560px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 0;
    padding: 0.7rem;
    gap: 0.65rem;
  }

  .main-grid {
    flex: 1;
    min-height: 0;
    grid-template-columns: 1.35fr 0.9fr;
    grid-template-rows: 1fr;
    gap: 0.65rem;
  }

  .inputs-card {
    min-height: 0;
    overflow: hidden;
  }

  .tab-panel.active {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .result-card {
    min-height: 0;
    overflow-y: auto;
  }

  .input-group input {
    width: 64px;
  }

  .brand h1 {
    font-size: 1.1rem;
  }

  .base-value {
    font-size: 1.1rem;
  }

  .base-input {
    width: 9.5rem;
    font-size: 1rem;
  }
}

@media (max-height: 640px) {
  .panel-hint {
    display: none;
  }

  .inputs-card {
    padding: 0.55rem 0.6rem;
  }

  .input-group {
    padding: 0.45rem 0.6rem;
    gap: 0.5rem;
  }

  .input-info .title {
    font-size: 0.82rem;
  }

  .inputs-grid {
    gap: 0.35rem;
  }

  .tab {
    padding: 0.4rem 0.3rem;
    font-size: 0.8rem;
  }
}

@media (max-height: 560px) {
  body {
    font-size: 13px;
  }

  .app {
    padding: 0.35rem;
    gap: 0.35rem;
  }

  .top-bar {
    padding: 0.4rem 0.55rem;
  }

  .input-group input {
    width: 50px;
    padding: 0.3rem 0.2rem;
    font-size: 0.88rem;
  }

  .net-row strong {
    font-size: 0.95rem;
  }
}
