
:root {
  --navy: #0d1b3f;
  --navy-2: #15306d;
  --sky-france: #00a4e4;
  --pantone-sky: #6dcff6;
  --ink: #101010;
  --white: #ffffff;
  --paper: #f4f7fb;
  --line: #d7e2ef;
  --soft: #eef6fd;
  --panel: #f2f3f5;
  --field: #eceeef;
  --field-focus: #fff5b8;
  --danger: #d62839;
  --success: #1f9d55;
  --shadow: 0 14px 35px rgba(13, 27, 63, 0.12);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #f7fbff 0%, #edf4fb 100%);
  color: var(--ink);
}
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.hidden-file { display: none !important; }

.app-shell {
  max-width: 1760px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: var(--white);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.topbar h1 { margin: 4px 0 6px; font-size: 2rem; }
.topbar p, .eyebrow { margin: 0; opacity: 0.92; }
.eyebrow {
  color: var(--pantone-sky);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  font-weight: 700;
}
.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}
.external-links-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn-external-link {
  min-width: 255px;
  justify-content: center;
}
.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 15px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.16s ease, opacity 0.16s ease, filter 0.16s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.02); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--sky-france); color: var(--white); }
.btn-secondary { background: var(--pantone-sky); color: var(--navy); }
.btn-accent { background: #19c2d8; color: var(--navy); }
.btn-dark { background: var(--ink); color: var(--white); }
.btn-light { background: var(--white); color: var(--navy); }
.btn-mini { background: var(--navy); color: var(--white); padding: 8px 12px; border-radius: 10px; }
.btn-danger { background: #d62839; color: var(--white); }
.btn-icon { background: rgba(255,255,255,0.16); color: var(--white); padding-inline: 14px; }
.btn-help {
  background: linear-gradient(135deg, #b60f20, #d62839);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  min-width: 48px;
  font-size: 1.2rem;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(214, 40, 57, 0.24);
}
.btn-fe {
  background: linear-gradient(135deg, #cf102d, #f24141);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  box-shadow: 0 10px 22px rgba(214, 40, 57, 0.22);
}
.btn-cdc {
  background: linear-gradient(135deg, #138a36, #27b052);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  box-shadow: 0 10px 22px rgba(31, 157, 85, 0.24);
}
.btn-fe-icon { color: #ffd400; font-size: 1.15rem; line-height: 1; }

.module-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 0;
}
.module-btn {
  border: 1px solid #bfd5ea;
  background: rgba(255,255,255,0.94);
  color: var(--navy);
  padding: 11px 16px;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}
.module-btn.is-active {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 8px 18px rgba(13, 27, 63, 0.16);
}

.alert-box {
  display: none;
  margin: 14px 0 0;
  padding: 14px 16px;
  border-radius: 14px;
  font-weight: 700;
}
.alert-box.show { display: block; }
.alert-success { background: #e9fff2; color: #196d3d; border: 1px solid #bce7cd; }
.alert-error { background: #fff0f1; color: #9c2130; border: 1px solid #f4c3ca; }
.alert-info { background: #eef9ff; color: #115e8a; border: 1px solid #bde6fb; }

.workspace {
  display: grid;
  grid-template-columns: 560px minmax(780px, 1fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}
.editor-panel { display: grid; gap: 16px; }
.module-screen { display: grid; gap: 16px; }
.panel-card {
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(13, 27, 63, 0.07);
}
.zone-head, .zone-client, .zone-detail, .zone-total, .zone-obs { background: rgba(255,255,255,0.96); }
.section-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--navy);
  margin-bottom: 14px;
}
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.doc-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  background: #e8f5ff;
  color: var(--navy);
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
}
.mini-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.mini-select { min-width: 180px; }
.segment {
  display: inline-flex;
  gap: 8px;
  background: #eaf2fa;
  padding: 6px;
  border-radius: 14px;
}
.segment-btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 800;
  cursor: pointer;
  color: var(--navy);
  background: transparent;
}
.segment-btn.is-active { background: var(--navy); color: #fff; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.full { grid-column: 1 / -1; }
.compact-grid label input,
.compact-grid label textarea { background: var(--field); }
label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #17305b;
}
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid #cfd8df;
  background: var(--field);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus,
.editable-input:focus, .editable-select:focus, .editable-textarea:focus {
  outline: 2px solid rgba(255, 214, 10, 0.18);
  border-color: #d6b400;
  background: var(--field-focus);
}
input[readonly], textarea[readonly] { background: #f4f6f8; }
textarea { resize: vertical; }

.date-field, .inline-popup-field {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.date-native { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.btn-date, .btn-inline-popup {
  border: 1px solid #c7d8e8;
  background: #fff;
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  font-weight: 700;
}
.limit-note {
  font-size: 0.84rem;
  color: #4a5d7f;
  background: #eef5fb;
  border: 1px solid #d7e7f6;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.table-scroll { overflow: auto; }
.editor-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}
.editor-table th, .editor-table td,
.data-table th, .data-table td {
  border-bottom: 1px solid #dde8f3;
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}
.editor-table th, .data-table th {
  background: var(--navy);
  color: var(--white);
  font-size: 0.84rem;
  position: sticky;
  top: 0;
  z-index: 1;
}
.editor-table td input, .editor-table td select {
  min-width: 72px;
  border-radius: 8px;
  padding: 8px 9px;
  background: var(--field);
}
.editor-table td .input-desc { min-width: 220px; }
.btn-remove {
  background: #fff2f3;
  color: var(--danger);
  border: 1px solid #f2c3ca;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 700;
}
.module-actions-inline {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.empty-state {
  color: #516581;
  background: #f5f9fd;
  border: 1px dashed #c6d8ea;
  border-radius: 14px;
  padding: 14px;
}
.history-list {
  display: grid;
  gap: 12px;
}
.history-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #d7e2ef;
  border-radius: 14px;
  padding: 12px;
  background: #f9fcff;
}
.history-title { font-weight: 900; color: var(--navy); }
.history-sub { font-size: 0.88rem; color: #4c6180; margin-top: 4px; }
.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.preview-panel { position: sticky; top: 18px; }
.preview-window {
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.preview-window.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
  visibility: hidden;
  height: 0;
  overflow: hidden;
}
.preview-window.is-dragging { user-select: none; }
.preview-toolbar {
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  border-radius: 16px 16px 0 0;
  padding: 12px 16px;
  cursor: move;
  box-shadow: 0 8px 20px rgba(13,27,63,0.12);
}
.preview-toolbar-title { font-weight: 900; font-size: 1rem; }
.preview-toolbar-note { font-size: 0.82rem; opacity: 0.82; margin-top: 4px; }
.kude-sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: var(--white);
  box-shadow: 0 18px 46px rgba(13, 27, 63, 0.18);
  padding: 12mm;
  color: #000;
}
.sheet-header {
  display: grid;
  grid-template-columns: 1.2fr 0.95fr;
  gap: 12px;
  border: 2px solid var(--navy);
}
.brand-block, .doc-block { padding: 12px; }
.brand-block {
  border-right: 1px solid #c7d8e8;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.brand-logo {
  background: linear-gradient(180deg, var(--sky-france), var(--pantone-sky));
  color: var(--white);
  width: 84px;
  height: 84px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  overflow: hidden;
}
.logo-image { width: 100%; height: 100%; object-fit: contain; }
.brand-logo-fallback { font-size: 0.95rem; }
.brand-name { font-size: 1.2rem; font-weight: 900; color: var(--navy); margin-bottom: 6px; }
.brand-meta { font-size: 0.86rem; margin-top: 4px; }
.doc-block { background: #f9fcff; }
.doc-type { font-size: 1rem; font-weight: 900; color: var(--navy); text-align: center; margin-bottom: 8px; }
.doc-code-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px dashed #c9d8e8;
  padding: 6px 0;
  font-size: 0.88rem;
}
.client-box, .detail-box, .totals-box, .footer-box {
  margin-top: 12px;
  border: 1px solid #c7d8e8;
}
.box-title {
  padding: 8px 10px;
  background: var(--navy);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 900;
}
.client-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  font-size: 0.84rem;
}
.client-grid > div {
  padding: 8px 10px;
  border-top: 1px solid #d6e3ef;
  border-right: 1px solid #d6e3ef;
}
.client-grid > div:nth-child(2n) { border-right: 0; }
.full-preview-line { grid-column: 1 / -1; }
.preview-table { width: 100%; border-collapse: collapse; }
.preview-table th, .preview-table td {
  border: 1px solid #d6e3ef;
  padding: 6px 6px;
  font-size: 0.78rem;
}
.preview-table th { background: #f2f8fd; }
.preview-row-pad td { height: 28px; }
.center { text-align: center; }
.right { text-align: right; }
.small { font-size: 0.72rem; }
.totals-box {
  display: grid;
  grid-template-columns: 1.2fr 0.85fr;
}
.letters-box, .resume-box { min-height: 138px; }
.letters-box { padding: 0; border-right: 1px solid #d6e3ef; }
.letters-box p { margin: 12px 10px; font-size: 0.88rem; }
.obs-line { border-top: 1px dashed #d6e3ef; padding-top: 10px; }
.resume-box { display: grid; }
.resume-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid #d6e3ef;
  font-size: 0.86rem;
}
.resume-row.total-row {
  background: var(--navy);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 900;
}
.footer-box {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: stretch;
}
.qr-area {
  display: grid;
  place-items: center;
  padding: 12px 8px;
  border-right: 1px solid #d6e3ef;
}
.qr-caption { font-size: 0.75rem; color: #49627f; margin-top: 8px; }
.cdc-area { padding: 10px 12px; }
.cdc-label { font-weight: 900; color: var(--navy); margin-bottom: 6px; }
.cdc-value {
  font-size: 0.85rem;
  word-break: break-all;
  padding: 8px 10px;
  border: 1px dashed #c0d3e6;
  background: #fbfdff;
}
.legal-strip {
  margin-top: 10px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #29496e;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(13,27,63,0.42);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  background: #fff;
  border-radius: 20px;
  width: min(540px, 100%);
  padding: 18px;
  box-shadow: 0 24px 44px rgba(13,27,63,0.24);
}
.small-card { width: min(460px, 100%); }
.sale-options { display: grid; gap: 10px; }
.sale-option {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #d3e3f0;
  background: #f8fcff;
  cursor: pointer;
}
.sale-option:hover { background: #eef8ff; }
.logo-preview-box {
  margin-top: 14px;
  border: 1px dashed #bfd2e5;
  border-radius: 16px;
  background: #f8fbff;
  padding: 14px;
  min-height: 94px;
  display: grid;
  place-items: center;
}
.cfg-logo-preview { max-width: 220px; max-height: 90px; object-fit: contain; }
.cfg-logo-empty { color: #607590; font-weight: 700; }
.config-preview {
  margin-top: 14px;
  background: #edf7ff;
  border: 1px solid #c8e8fb;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 800;
  color: #134c74;
}

@media (max-width: 1440px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { position: relative; top: 0; }
  .preview-window { position: relative !important; inset: auto !important; }
}
@media (max-width: 980px) {
  .app-shell { padding: 12px; }
  .topbar { padding: 16px; }
  .topbar h1 { font-size: 1.5rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .client-grid { grid-template-columns: 1fr; }
  .client-grid > div { border-right: 0; }
  .totals-box { grid-template-columns: 1fr; }
  .letters-box { border-right: 0; border-bottom: 1px solid #d6e3ef; }
  .sheet-header { grid-template-columns: 1fr; }
  .brand-block { border-right: 0; border-bottom: 1px solid #c7d8e8; }
}
@media (max-width: 768px) {
  .module-nav, .topbar-actions { gap: 8px; }
  .btn, .module-btn { padding: 10px 12px; }
  .kude-sheet {
    width: 100%;
    min-height: auto;
    padding: 16px;
    box-shadow: 0 12px 28px rgba(13,27,63,0.16);
  }
  .preview-toolbar { cursor: default; }
}
@media print {
  body { background: #fff; }
  .no-print, .module-nav, .editor-panel, .alert-box { display: none !important; }
  .workspace { display: block; margin: 0; }
  .preview-panel, .preview-window { position: static !important; }
  .preview-window { opacity: 1 !important; visibility: visible !important; transform: none !important; height: auto !important; }
  .kude-sheet { box-shadow: none; width: 100%; margin: 0; padding: 0; }
}
