* { box-sizing: border-box; }

@font-face {
  font-family: "Helvetica Neue";
  src: url("./fonts/HelveticaLTStd-Roman.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Helvetica Neue";
  src: url("./fonts/HelveticaLTStd-Roman.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --blue: #0b57d0;
  --blue-top-btn: #1e64c8;
  --yellow: #ffc107;
  --bg: #f0f0f0;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6e6e6e;
  --border: #c7d2e0;
  --win-border: #707070;
  --win-border-light: #ffffff;
  --win-border-dark: #adadad;
  --win-btn-face: #ececec;
  --win-input-border: #7a7a7a;
  --win-select: #dceaff;
  --win-select-border: #99c2f0;
  --font-ui: "Helvetica Neue", "Helvetica LT Std", Helvetica, Arial, sans-serif;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ── Win32 controls base ── */
button {
  font-family: var(--font-ui);
  font-size: 14px;
}

.win-input,
input[type="text"],
input[type="number"],
input[type="date"],
textarea,
select {
  font-family: var(--font-ui);
  font-size: 14px;
  background: #fff;
  border: 1px solid var(--win-input-border);
  border-radius: 0;
  padding: 3px 6px;
  color: #000;
  min-height: 23px;
}

.win-input:focus,
input:focus,
textarea:focus {
  outline: 1px dotted #000;
  outline-offset: -4px;
}

input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--blue);
  margin: 0;
}

/* Botó Win32 estàndard (System) */
.win-btn {
  appearance: none;
  background: linear-gradient(180deg, #fdfdfd 0%, var(--win-btn-face) 50%, #dcdcdc 100%);
  border: 1px solid var(--win-border);
  border-radius: 0;
  color: #000;
  cursor: default;
  padding: 3px 12px;
  min-height: 28px;
  min-width: 75px;
  box-shadow:
    inset 1px 1px 0 var(--win-border-light),
    inset -1px -1px 0 var(--win-border-dark);
}

.win-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #f5f5f5 50%, #e8e8e8 100%);
}

.win-btn:active {
  background: #d4d4d4;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.25);
  padding: 4px 11px 2px 13px;
}

.win-btn-sm {
  min-width: 36px;
  padding: 3px 8px;
}

/* Botó primari (FlatStyle.Flat blau) */
.win-btn-primary {
  appearance: none;
  background: var(--blue);
  border: none;
  border-radius: 0;
  color: #fff;
  cursor: default;
  padding: 4px 14px;
  min-height: 32px;
  min-width: 90px;
  font-weight: 400;
}

.win-btn-primary:hover {
  background: #0c5fe0;
}

.win-btn-primary:active {
  background: #094aa8;
  padding: 5px 13px 3px 15px;
}

/* Botons barra superior (Flat sobre blau) */
.win-btn-top {
  appearance: none;
  background: var(--blue-top-btn);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 0;
  color: #fff;
  cursor: default;
  padding: 5px 8px;
  min-height: 28px;
  font-size: 14px;
  box-shadow: none;
}

.win-btn-top:hover {
  background: #2878d8;
}

.win-btn-top:active {
  background: #155aad;
  padding: 6px 7px 4px 9px;
}

.win-btn-top-bold {
  font-weight: 700;
}

.app {
  display: grid;
  grid-template-rows: 54px 1fr 68px;
  height: 100vh;
  min-height: 620px;
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 14px;
  background: var(--blue);
  color: #fff;
  border-bottom: 1px solid #084aa8;
}

.top-bar h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  padding: 8px 0;
}

/* Main split amb splitter Win32 */
.main-split {
  display: grid;
  grid-template-columns: 430px 4px 1fr;
  gap: 0;
  min-height: 0;
  background: var(--bg);
}

.splitter {
  background: var(--bg);
  border-left: 1px solid #b0b0b0;
  border-right: 1px solid #fff;
  cursor: col-resize;
}

.panel-left {
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 8px 4px 8px 8px;
  min-height: 0;
  overflow: hidden;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  color: #6e6e6e;
  letter-spacing: 0.02em;
  padding: 0 0 4px 2px;
}

.tiles-scroll {
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0;
  padding: 2px;
  background: var(--bg);
}

.tile {
  width: 132px;
  height: 100px;
  margin: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 0;
  cursor: pointer;
  position: relative;
  color: #fff;
  text-align: left;
  padding: 0;
  overflow: hidden;
}

.tile:hover { filter: brightness(1.12); }
.tile:active { filter: brightness(0.85); }

.tile-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 54px;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 8px;
}

.tile-name {
  display: block;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-price {
  display: block;
  font-size: 10px;
  margin-top: 2px;
}

.panel-right {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
  padding: 8px 8px 8px 4px;
  min-height: 0;
}

.card {
  background: var(--card);
  border: 1px solid #d1d5db;
  border-radius: 0;
}

.quick-info {
  display: grid;
  grid-template-columns: 50px 80px 60px 100px 50px 115px 52px 1fr;
  gap: 0 6px;
  align-items: center;
  padding: 6px 8px;
}

.quick-info label {
  font-size: 14px;
  white-space: nowrap;
}

.quick-info input {
  width: 100%;
}

.grid-wrap {
  min-height: 0;
  overflow: auto;
  border: 1px solid #d1d5db;
}

.lines-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.lines-table th {
  background: var(--yellow);
  text-align: left;
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid #d1d5db;
  position: sticky;
  top: 0;
}

.lines-table td {
  border-bottom: 1px solid #e5e7eb;
  border-right: 1px solid #f0f0f0;
  padding: 0;
  height: 26px;
  font-size: 14px;
  vertical-align: middle;
}

.lines-table td:last-child {
  border-right: none;
}

.lines-table td.grid-readonly {
  padding: 2px 8px;
  background: #fafafa;
  color: #1f2937;
}

.lines-table td .grid-cell {
  display: block;
  width: 100%;
  height: 25px;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 2px 6px;
  font: inherit;
  color: inherit;
  min-height: 25px;
  box-shadow: none;
}

.lines-table tbody tr.selected td {
  background: var(--win-select);
}

.lines-table tbody tr.selected td.grid-readonly {
  background: #d4e8ff;
}

.lines-table td .grid-cell:focus {
  outline: none;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--win-input-border);
}

.lines-table tbody tr.selected td .grid-cell:focus {
  background: #fff;
}

.grid-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

/* Bottom bar */
.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-top: 1px solid #d1d5db;
  background: #fff;
}

.status {
  color: #505050;
  font-size: 14px;
}

.totals {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.total-block {
  display: flex;
  flex-direction: column;
  width: 130px;
}

.total-label {
  font-size: 10px;
  color: #828282;
}

.total-block strong {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.total-main strong {
  font-size: 19px;
  color: var(--blue);
}

.sep {
  color: #d1d5db;
  font-size: 14px;
  padding-bottom: 4px;
}

/* Modals — aspecte Form WinForms */
.modal {
  border: 1px solid var(--win-border);
  border-radius: 0;
  padding: 0;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.25);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.25);
}

.modal-body {
  padding: 14px 16px 12px;
  background: #f5f5f5;
}

.modal-lg { width: 660px; max-width: 96vw; }
.modal-xl { width: 980px; max-width: 96vw; }

.modal-body h2 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 400;
  color: #000;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Quantity dialog */
#qtyDialog { width: 320px; }
#qtyDialog .modal-body { background: #fff; padding: 18px 18px 12px; }

#qtyTitle {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 2px;
}

.qty-price {
  color: var(--blue);
  margin: 0 0 12px;
  font-size: 14px;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: #374151;
}

#qtyInput {
  width: 140px;
  font-size: 17px;
  padding: 4px 6px;
}

/* Products manager */
.products-layout h2 { margin-bottom: 8px; }

.products-split {
  display: grid;
  grid-template-columns: 220px 4px 1fr;
  gap: 0;
  min-height: 420px;
}

.products-split-divider {
  background: #f5f5f5;
  border-left: 1px solid #b0b0b0;
  border-right: 1px solid #fff;
}

.products-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--win-input-border);
  background: #fff;
  height: 360px;
  overflow: auto;
  border-radius: 0;
}

.products-list li {
  padding: 4px 8px;
  border-bottom: none;
  cursor: default;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.products-list li.selected {
  background: #0078d4;
  color: #fff;
}

.products-list li:hover:not(.selected) {
  background: #e8f0ff;
}

.list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding: 4px;
  background: #f5f5f5;
}

.products-edit-panel {
  padding: 10px;
  display: grid;
  gap: 4px;
  align-content: start;
  margin-left: 8px;
}

.form-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 6px;
  align-items: center;
}

.form-row label {
  font-size: 14px;
}

.form-row input[type="text"] {
  width: 100%;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-row input[type="color"] {
  width: 36px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--win-input-border);
  border-radius: 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0 4px 90px;
  font-size: 14px;
  cursor: default;
}

.hint {
  color: #888;
  font-size: 11px;
}

.tile-preview-wrap {
  margin-top: 4px;
  padding-left: 90px;
}

.tile-preview-wrap .tile {
  margin: 4px 0 0;
  width: 150px;
  height: 110px;
}

/* Config */
.config-scroll {
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.config-section {
  padding: 10px;
  margin-bottom: 10px;
}

.config-section h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: #646464;
  letter-spacing: 0.04em;
}

.config-section .form-row {
  grid-template-columns: 110px 1fr;
  margin-bottom: 2px;
}

.config-section .form-row-top {
  align-items: start;
}

.config-section .form-row-top label {
  padding-top: 4px;
}

.config-section input,
.config-section textarea {
  width: 100%;
}

.logo-preview {
  display: block;
  max-width: 120px;
  max-height: 60px;
  margin-top: 4px;
  border: 1px solid var(--win-input-border);
}

.hidden { display: none !important; }

/* Preview */
.preview-body {
  background: #f9fafb;
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border: 1px solid #d1d5db;
  padding: 10px 14px;
  margin-bottom: 10px;
}

.preview-total-header {
  color: var(--blue);
  font-size: 22px;
  font-weight: 700;
}

.preview-top {
  display: grid;
  grid-template-columns: 1fr 230px;
  gap: 12px;
  margin-bottom: 10px;
}

.preview-parties {
  background: #fff;
  border: 1px solid #d1d5db;
  padding: 10px;
  min-height: 120px;
  white-space: pre-line;
  font-size: 14px;
}

.preview-meta-box { display: grid; gap: 0; }

.preview-doc-title {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 8px;
  font-size: 14px;
}

.preview-meta {
  border: 1px solid var(--border);
  background: #fff;
  padding: 6px 8px;
  font-size: 14px;
  line-height: 1.55;
}

.preview-table {
  background: #fff;
  border: 1px solid #d1d5db;
}

.preview-footer {
  margin-top: 10px;
  background: #fff;
  border: 1px solid #d1d5db;
  padding: 10px 14px;
}

.preview-yellow-line {
  height: 2px;
  background: var(--yellow);
  margin-bottom: 10px;
}

.preview-pay-total {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 8px;
}

.preview-pay-total span { color: var(--blue); }

.preview-legal {
  font-size: 11px;
  color: #374151;
  margin: 0;
}

@media (max-width: 900px) {
  .main-split {
    grid-template-columns: 1fr;
    grid-template-rows: auto 4px 1fr;
  }

  .splitter { cursor: row-resize; border-left: none; border-top: 1px solid #b0b0b0; border-right: none; border-bottom: 1px solid #fff; }

  .quick-info {
    grid-template-columns: auto 1fr auto 1fr;
  }

  .products-split {
    grid-template-columns: 1fr;
  }

  .products-split-divider { display: none; }

  .preview-top {
    grid-template-columns: 1fr;
  }
}
