:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f0f4f8;
  --line: #d9e0ea;
  --text: #172033;
  --muted: #667085;
  --blue: #234e9d;
  --blue-dark: #173b78;
  --blue-soft: #e8f0ff;
  --gold: #d7b75a;
  --gold-soft: #fff4bf;
  --green: #2f9e44;
  --yellow: #fff2b8;
  --danger: #c92a2a;
  --shadow: 0 18px 42px rgba(23, 43, 87, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(35, 78, 157, 0.13) 0%, rgba(245, 247, 251, 0.96) 38%, rgba(255, 244, 191, 0.84) 100%),
    linear-gradient(180deg, #ffffff 0%, #f3f6fb 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(235, 241, 253, 0.96) 100%);
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--blue), var(--gold)) 1;
  box-shadow: 0 12px 28px rgba(23, 43, 87, 0.1);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--blue-dark);
  font-size: 20px;
  font-weight: 800;
}

.subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  object-fit: contain;
  padding: 4px;
  border: 1px solid rgba(217, 224, 234, 0.86);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 24px rgba(23, 43, 87, 0.12);
}

.brand-text {
  min-width: 0;
}

button {
  height: 34px;
  border: 0;
  padding: 0 12px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-soft);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

button:hover {
  filter: brightness(0.97);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: linear-gradient(135deg, #2f5db4, var(--blue-dark));
  color: #fff;
  box-shadow: 0 10px 22px rgba(35, 78, 157, 0.22);
}

button.secondary {
  background: linear-gradient(135deg, #edf4ff, #dce8f8);
  color: var(--blue-dark);
}

button.ghost {
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  border: 1px solid var(--line);
}

button.small {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

button.full {
  width: 100%;
}

.app-shell {
  display: grid;
  grid-template-areas: "form items totals";
  grid-template-columns: minmax(260px, 330px) minmax(420px, 1fr) minmax(250px, 300px);
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 70px);
}

.form-panel {
  grid-area: form;
}

.items-panel {
  grid-area: items;
}

.totals-panel {
  grid-area: totals;
}

.panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(217, 224, 234, 0.92);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
  overflow: auto;
  backdrop-filter: blur(10px);
}

.items-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.section-title {
  margin: 14px 0 8px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.section-title:first-child {
  margin-top: 0;
}

.section-title.tight {
  margin: 0;
}

.hint,
.note,
.status {
  color: var(--muted);
  font-size: 12px;
}

.note {
  margin-top: 14px;
  padding: 10px;
  background: #eef8f0;
  border-left: 3px solid var(--green);
}

.status {
  min-height: 34px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

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

label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font: inherit;
  outline: none;
}

input,
select {
  height: 34px;
  padding: 0 9px;
}

input[type="date"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
}

input[type="date"]::-webkit-date-and-time-value {
  min-height: 1.2em;
  text-align: left;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  margin-left: auto;
}

textarea {
  resize: vertical;
  min-height: 80px;
  padding: 9px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(35, 78, 157, 0.12);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin-bottom: 8px;
  color: var(--text);
}

.check-row input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.table-wrap {
  flex: 1;
  min-height: 260px;
  overflow: auto;
  border: 1px solid #8ea0bb;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  height: 30px;
  background: var(--panel-soft);
  color: #4c5870;
  font-size: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th,
td {
  padding: 4px 6px;
  vertical-align: middle;
}

th:nth-child(1) {
  width: 39%;
}

th:nth-child(2) {
  width: 92px;
}

th:nth-child(3),
th:nth-child(4),
th:nth-child(5) {
  width: 108px;
}

th:nth-child(6) {
  width: 82px;
}

tbody tr {
  background: var(--yellow);
}

tbody tr.selected {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

td input,
td select {
  height: 28px;
  margin: 0;
  background: rgba(255, 255, 255, 0.72);
}

td select {
  cursor: pointer;
  padding-right: 24px;
  appearance: auto;
  background-color: rgba(255, 255, 255, 0.86);
  border-color: #cfd8e6;
  color: var(--text);
}

.delete-line {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  background: #fff1f1;
  color: var(--danger);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-box {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.summary {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.summary div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
}

.summary div:last-child {
  border-bottom: 0;
}

.summary .total {
  min-height: 44px;
  background: linear-gradient(135deg, #eaf0fb, #f8edc7);
  color: var(--blue);
  font-size: 16px;
}

.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  background: rgba(9, 18, 35, 0.42);
  backdrop-filter: blur(10px);
}

.share-sheet {
  width: min(560px, 100%);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(217, 224, 234, 0.92);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(9, 18, 35, 0.26);
  padding: 16px;
}

.share-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.share-head strong {
  display: block;
  color: var(--blue-dark);
  font-size: 18px;
}

.share-head span,
.share-help {
  color: var(--muted);
  font-size: 13px;
}

.share-close {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.share-option {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(135deg, #f8fbff, #e8f0ff);
  color: var(--blue-dark);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.share-option.primary-share {
  border-color: transparent;
  background: linear-gradient(135deg, #2f5db4, var(--blue-dark));
  color: #fff;
}

.share-help {
  margin: 12px 2px 0;
  line-height: 1.35;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-areas:
      "form totals"
      "items items";
    grid-template-columns: minmax(280px, 1fr) minmax(260px, 320px);
    height: auto;
    min-height: calc(100vh - 70px);
  }

  .panel {
    overflow: visible;
  }

  .items-panel {
    min-height: 520px;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 15px;
    background:
      linear-gradient(160deg, rgba(35, 78, 157, 0.15) 0%, rgba(255, 255, 255, 0.96) 34%, rgba(255, 244, 191, 0.9) 100%),
      #f5f7fb;
    padding-bottom: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px 12px 16px;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.98), rgba(232, 240, 255, 0.96));
  }

  .brand {
    font-size: 22px;
    letter-spacing: 0;
  }

  .brand-logo {
    width: 46px;
    height: 46px;
  }

  .subtitle {
    font-size: 13px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .top-actions button {
    width: 100%;
    height: 42px;
  }

  .app-shell {
    grid-template-areas:
      "form"
      "items"
      "totals";
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
    min-height: 0;
  }

  .panel {
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 12px 30px rgba(23, 43, 87, 0.12);
  }

  .grid.two {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  input,
  select {
    min-height: 42px;
    font-size: 16px;
    border-radius: 10px;
  }

  input[type="date"] {
    height: 42px;
    line-height: 42px;
    padding: 0 14px;
  }

  input[type="date"]::-webkit-date-and-time-value {
    padding: 0;
    text-align: left;
  }

  textarea {
    font-size: 16px;
  }

  button {
    min-height: 42px;
  }

  button.small {
    height: 42px;
    min-width: 118px;
    font-size: 13px;
  }

  .panel-header {
    align-items: stretch;
  }

  .panel-header > div {
    min-width: 0;
  }

  .table-wrap {
    min-height: 0;
    overflow: visible;
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

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

  tbody tr {
    position: relative;
    display: grid;
    gap: 8px;
    padding: 12px;
    background: linear-gradient(160deg, #fff7bd 0%, #fffce4 100%);
    border: 1px solid #d5dfef;
    border-radius: 10px;
    box-shadow: 0 8px 18px rgba(23, 43, 87, 0.08);
  }

  tbody tr.selected {
    outline: 0;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(35, 78, 157, 0.12);
  }

  tbody tr::before {
    content: "Concepto";
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }

  td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  td[data-label="Concepto"] {
    grid-template-columns: 1fr;
  }

  td[data-label="Concepto"]::before,
  td[data-label="Acciones"]::before {
    display: none;
  }

  td input,
  td select {
    height: 42px;
    min-height: 42px;
    border-radius: 10px;
  }

  .delete-line {
    width: 100%;
    height: 40px;
    font-weight: 800;
  }

  .detail-box textarea {
    min-height: 112px;
  }

  .summary div {
    min-height: 42px;
  }

  .summary .total {
    min-height: 52px;
    font-size: 17px;
  }

  .note {
    line-height: 1.35;
  }

  .share-overlay {
    padding: 10px;
  }

  .share-sheet {
    border-radius: 22px 22px 16px 16px;
    padding: 16px;
  }

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

  .share-option {
    min-height: 58px;
  }
}

@media (max-width: 420px) {
  .top-actions {
    grid-template-columns: 1fr;
  }

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