/* ===========================================================
   OLA EXPRESS · Generador de facturas
   =========================================================== */

:root {
  --navy: #1B365D;
  --navy-deep: #152a48;
  --ocre: #CE7925;
  --ocre-soft: #e8a662;
  --offwhite: #F7F7F7;
  --paper: #ffffff;
  --ink: #2b2b2b;
  --ink-soft: #5a5a5a;
  --muted: #9a9a9a;
  --line: #e3e3e3;
  --danger: #b5432a;

  --font-display: 'Anton', 'Oswald', 'Impact', sans-serif;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

  /* Fixed invoice design size (US Letter-ish ratio) */
  --invoice-w: 707px;
  --invoice-h: 1000px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  background: #ececec;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(420px, 520px) 1fr;
  min-height: 100vh;
}

.form-pane {
  background: #f4f4f4;
  border-right: 1px solid #dcdcdc;
  overflow-y: auto;
  max-height: 100vh;
}

.preview-pane {
  background: #ececec;
  overflow-y: auto;
  max-height: 100vh;
  padding: 28px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ---------- Form ---------- */

.form-inner {
  padding: 24px 24px 160px;
  max-width: 520px;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.form-title {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.04em;
  color: var(--navy);
  margin: 0;
}

.form-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-top: 2px;
}

.block {
  background: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 10px;
  padding: 16px 16px 14px;
  margin-bottom: 14px;
}

.block-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--navy);
  margin: 0 0 12px;
  text-transform: uppercase;
}

.block-title .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ocre);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

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

.field.full { grid-column: 1 / -1; }

.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 600;
}

.field input,
.field textarea,
.field select {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  padding: 9px 10px;
  border: 1px solid #d5d5d5;
  border-radius: 6px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(27, 54, 93, 0.12);
}

.field textarea {
  resize: vertical;
  min-height: 56px;
  font-family: var(--font-body);
}

/* ---------- Items table (form side) ---------- */

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

.item-card {
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  padding: 10px 10px 8px;
  background: #fafafa;
  position: relative;
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.item-num {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.btn-remove {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-remove:hover { color: var(--danger); background: #f2e4e0; }

.item-grid {
  display: grid;
  grid-template-columns: 2fr 0.6fr 0.8fr 0.8fr;
  gap: 6px;
}

.item-grid .field label { font-size: 10px; }
.item-grid .field input {
  font-size: 13px;
  padding: 7px 8px;
}

.item-dims {
  margin-top: 6px;
  padding: 8px 10px;
  background: #fff;
  border: 1px dashed #d0d0d0;
  border-radius: 6px;
}

.dims-head {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ocre);
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dims-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 6px;
  align-items: end;
}

.dims-grid .field input { font-size: 13px; padding: 6px 7px; }

.dims-calc {
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
.dims-calc strong { color: var(--navy); }

.btn-add {
  width: 100%;
  padding: 10px;
  border: 1px dashed #bdbdbd;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
  transition: all .15s;
}
.btn-add:hover {
  border-color: var(--navy);
  color: var(--navy);
  background: #f6f8fb;
}

/* ---------- Warnings ---------- */

.warnings {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.warn {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: #7a4a1f;
  background: #fdf4e7;
  border: 1px solid #f0d9b2;
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.35;
}
.warn-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ocre);
  margin-top: 5px;
}

/* ---------- Action bar ---------- */

.actions {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 24px;
  background: linear-gradient(to top, #f4f4f4 60%, rgba(244,244,244,0));
  display: flex;
  gap: 10px;
  margin: 0 -24px;
}

.btn {
  flex: 1;
  padding: 12px 14px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
}

.btn-primary {
  background: var(--navy);
  color: #fff;
}
.btn-primary:hover { background: var(--navy-deep); }

.btn-secondary {
  background: #fff;
  color: var(--navy);
  border-color: #d0d0d0;
}
.btn-secondary:hover { border-color: var(--navy); }

.btn-ocre {
  background: var(--ocre);
  color: #fff;
}
.btn-ocre:hover { background: #b56820; }

/* ---------- Phone row · second phone toggle ---------- */

.field label .field-action {
  margin-left: 6px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  border-radius: 3px;
  transition: color .12s, background .12s;
}
.field label .field-action:hover {
  color: var(--danger);
  background: #fdecea;
}

.add-phone-btn {
  width: 100%;
  padding: 9px 10px;
  border: 1px dashed #c8c8c8;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  transition: all .15s;
}
.add-phone-btn:hover {
  border-color: var(--navy);
  color: var(--navy);
  background: #f6f8fb;
}

/* ---------- Mode toggle (Air/Mar) ---------- */
.mode-toggle {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.mode-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  background: #fff;
  border: 1px solid #d5d5d5;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: all .12s;
}
.mode-btn:hover { border-color: var(--navy); color: var(--navy); }
.mode-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.mode-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 9.5px;
  letter-spacing: 0.08em;
  font-weight: 700;
  font-family: var(--font-body);
}
.mode-pill.mode-air,
.mode-pill.mode-mar {
  background: rgba(206, 121, 37, 0.12);
  color: var(--ocre);
}

/* ---------- Library (saved invoices) ---------- */

.library-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: #fff;
  border: 1px solid #d5d5d5;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--navy);
  font-weight: 600;
  transition: all .15s;
}
.library-toggle:hover {
  border-color: var(--navy);
  background: #f6f8fb;
}

.library {
  background: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 10px;
  padding: 12px 12px 10px;
  margin-bottom: 14px;
}

.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.library-head strong {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  font-size: 13px;
  color: var(--navy);
  text-transform: uppercase;
}

.library-actions { display: flex; gap: 4px; }

.mini-btn {
  padding: 5px 8px;
  font-size: 11px;
  background: #f4f4f4;
  border: 1px solid #dcdcdc;
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--ink-soft);
  transition: all .12s;
}
.mini-btn:hover { border-color: var(--navy); color: var(--navy); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: #fdecea; }

.library-search {
  width: 100%;
  padding: 7px 9px;
  font-size: 12.5px;
  font-family: var(--font-body);
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  margin-bottom: 8px;
  outline: none;
}
.library-search:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(27,54,93,.1); }

.library-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 14px 4px;
  text-align: center;
  font-style: italic;
}

.library-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.library-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border: 1px solid #ececec;
  border-radius: 6px;
  background: #fafafa;
  transition: all .12s;
}
.library-item:hover { border-color: #cfd7e4; background: #f4f7fb; }
.library-item.active {
  border-color: var(--ocre);
  background: #fef4e6;
}

.library-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 7px 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
}

.library-line1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}
.library-num {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--navy);
}
.library-total {
  font-size: 12px;
  color: var(--ocre);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.library-line2 {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-soft);
  gap: 8px;
}
.library-who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.library-when {
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.library-tools {
  display: flex;
  align-items: center;
  padding: 6px 6px 6px 0;
  gap: 3px;
}
.library-tools .mini-btn {
  padding: 4px 7px;
  background: transparent;
  border-color: transparent;
}
.library-tools .mini-btn:hover { background: #fff; }

/* ---------- File input (logo) ---------- */

.logo-input {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-preview {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #fff;
  border: 1px dashed #c8c8c8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.logo-placeholder {
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.logo-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.file-btn {
  display: inline-block;
  padding: 7px 10px;
  background: #fff;
  border: 1px solid #d5d5d5;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink);
  text-align: center;
  transition: all .15s;
}
.file-btn:hover { border-color: var(--navy); color: var(--navy); }

.logo-clear {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  padding: 0;
}
.logo-clear:hover { color: var(--danger); }

/* ===========================================================
   INVOICE (preview)
   =========================================================== */

.invoice-wrap {
  width: 100%;
  max-width: var(--invoice-w);
}

.invoice {
  width: var(--invoice-w);
  min-height: var(--invoice-h);
  background: var(--paper);
  box-shadow: 0 18px 60px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 235px 1fr;
  grid-template-rows: 1fr auto;
  font-size: 12px;
  color: var(--ink);
}

/* Left navy panel */

.panel-left {
  background: var(--navy);
  color: #fff;
  padding: 32px 24px 40px;
  grid-row: 1 / 2;
}

.date-big {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.02em;
}
.date-big .y { display: block; }

.invoice-word {
  font-family: var(--font-display);
  font-size: 32px;
  color: var(--ocre);
  letter-spacing: 0.04em;
  margin-top: 22px;
  line-height: 1;
}

.invoice-num {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.04em;
  margin-top: 2px;
  color: #fff;
}

.panel-section {
  margin-top: 26px;
}

.panel-section h3 {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.06em;
  margin: 0 0 10px;
  color: #fff;
}

.panel-field {
  margin-bottom: 10px;
}

.panel-label {
  font-size: 10.5px;
  color: rgba(255,255,255,0.78);
  margin-bottom: 2px;
  line-height: 1.3;
}

.panel-value {
  font-size: 12px;
  color: var(--ocre-soft);
  font-weight: 500;
  line-height: 1.35;
  word-break: break-word;
  min-height: 14px;
}
.panel-value.empty::before {
  content: '—';
  color: rgba(255,255,255,0.3);
}

/* Right panel */

.panel-right {
  background: var(--offwhite);
  padding: 30px 34px 40px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.brand-row {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 46px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand img {
  max-height: 42px;
  max-width: 240px;
  object-fit: contain;
}

.brand-wordmark {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.06em;
  color: var(--navy);
}

.brand-wordmark .accent { color: var(--ocre); }

.company-info {
  text-align: right;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink);
  margin-bottom: 22px;
}
.company-info .name {
  font-weight: 700;
  color: var(--navy);
  font-size: 12.5px;
}

/* Items table */

.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
}

.items-table th {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--navy);
  text-align: left;
  padding: 4px 0 16px;
  font-weight: normal;
  border-bottom: 1.5px solid var(--navy);
}

.items-table th.num,
.items-table td.num { text-align: right; }

.items-table td {
  padding: 10px 0;
  font-size: 12px;
  color: var(--ink);
  border-bottom: 1px solid #eaeaea;
  vertical-align: top;
}

.items-table td.desc { padding-right: 8px; }
.items-table td.num { font-variant-numeric: tabular-nums; }

.items-table tr.empty-row td {
  color: var(--muted);
  font-style: italic;
}

/* Totals */

.totals {
  margin-left: auto;
  width: 58%;
  margin-top: 8px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  font-size: 12.5px;
  border-top: 1px solid #eaeaea;
}
.totals-row:first-child { border-top: none; }

.totals-row .label { color: var(--ink-soft); }
.totals-row .value {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.totals-row.total {
  padding-top: 10px;
  margin-top: 4px;
}
.totals-row.total .label {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.05em;
  color: var(--navy);
}
.totals-row.total .value {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--navy);
}

/* Signature */

.signature {
  margin-top: 28px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.sig-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e9d5b8;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ocre);
  flex-shrink: 0;
}

.sig-line {
  flex: 1;
  border-bottom: 1px solid #c8c8c8;
  padding-bottom: 4px;
}
.sig-label {
  font-size: 12px;
  color: var(--ocre);
  margin-top: 2px;
}

/* Delivery time box */

.delivery-box {
  margin-top: 24px;
  margin-left: auto;
  width: 56%;
  border-left: 4px solid var(--ocre);
  padding: 8px 12px;
  font-size: 11px;
  background: #fff;
  line-height: 1.5;
}
.delivery-box .title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--navy);
  margin-bottom: 4px;
}
.delivery-box strong { color: var(--navy); }

/* Bottom ocre strip (spans both columns) */

.panel-bottom {
  grid-column: 1 / -1;
  background: var(--ocre);
  color: var(--navy);
  padding: 22px 28px 30px;
  position: relative;
  overflow: hidden;
  min-height: 160px;
}

.method-title {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--navy);
  margin-bottom: 14px;
}

.method-grid {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 6px 40px;
  max-width: 70%;
}

.method-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--navy);
  text-transform: uppercase;
}
.method-value {
  font-size: 12.5px;
  color: var(--navy);
  font-weight: 500;
  margin-bottom: 6px;
}

.due-block {
  margin-top: 10px;
}
.due-block .method-label { color: var(--navy); }

/* Decorative wave (bottom-right) */

.wave {
  position: absolute;
  right: -30px;
  bottom: -40px;
  width: 260px;
  height: 200px;
  pointer-events: none;
}

/* ---------- Print ---------- */

@page {
  size: letter;
  margin: 0;
}

@media print {
  html, body {
    background: #fff;
    margin: 0;
    padding: 0;
  }
  .app { display: block; }
  .form-pane { display: none; }
  .preview-pane {
    padding: 0;
    background: #fff;
    max-height: none;
    overflow: visible;
    display: block;
  }
  .invoice-wrap { max-width: none; }
  .invoice {
    width: 100%;
    min-height: 100vh;
    box-shadow: none;
    page-break-after: avoid;
  }
}
