:root {
  --primary: #1e3a5f;
  --primary-hover: #162c49;
  --primary-soft: #e8eff7;
  --accent: #2563eb;
  --bg: #eef2f6;
  --surface: #ffffff;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* ==================== AUTH SCREEN ==================== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(135deg, #162c49 0%, #1e3a5f 55%, #2b507e 100%);
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: #ffffff;
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.35);
}

.auth-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.auth-logo {
  width: 155px;
  height: 104px;
  object-fit: cover;
  border-radius: 9px;
  border: 1px solid var(--border);
}

.auth-title {
  text-align: center;
  margin: 0 0 6px;
  font-size: 21px;
  color: var(--primary);
}

.auth-sub {
  text-align: center;
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-subtle);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.btn-full {
  width: 100%;
  padding: 11px 16px;
}

.auth-switch {
  margin-top: 14px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  text-decoration: underline;
}

.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
}

.alert-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid #fcd34d;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.18);
  gap: 14px;
  flex-wrap: wrap;
}

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

.topbar-logo {
  width: 56px;
  height: 38px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: #fff;
}

.topbar-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.topbar-sub {
  font-size: 11.5px;
  color: #cbd5e1;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  border: none;
  background: transparent;
  color: #dbeafe;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-btn.active {
  background: #ffffff;
  color: var(--primary);
}

.nav-logout {
  border: 1px solid rgba(255, 255, 255, 0.25);
  margin-left: 4px;
}

.nav-badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

.nav-btn.active .nav-badge {
  background: var(--primary-soft);
  color: var(--primary);
}

/* ==================== LAYOUT ==================== */
.main-container {
  max-width: 1580px;
  margin: 0 auto;
  padding: 20px 20px 56px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(460px, 1.05fr) minmax(420px, 0.95fr);
  gap: 22px;
  align-items: start;
}

@media (max-width: 1100px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

.editor-toolbar,
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.editor-status-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 800;
  color: var(--primary);
}

h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--primary);
}

.subtitle {
  margin: 3px 0 0;
  color: var(--text-subtle);
  font-size: 13px;
}

/* ==================== CARDS & FORMS ==================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.form-grid {
  display: grid;
  gap: 11px 14px;
}

.form-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 680px) {
  .form-grid.cols-2,
  .form-grid.cols-3 {
    grid-template-columns: 1fr;
  }
}

.span-2 {
  grid-column: span 2;
}

@media (max-width: 680px) {
  .span-2 {
    grid-column: span 1;
  }
}

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

.field label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.35px;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="email"],
.field input[type="password"],
.field input[type="search"],
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.14);
}

.client-picker-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}

.flex-1 {
  flex: 1;
}

.checkbox-align {
  justify-content: flex-end;
  padding-bottom: 5px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-weight: 600 !important;
  color: var(--text) !important;
  cursor: pointer;
}

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.cfg-logo-img {
  width: 148px;
  height: 100px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #bfd0e6;
}

.btn-secondary:hover:not(:disabled) {
  background: #dbe6f4;
}

.btn-ghost {
  background: #fff;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: #f8fafc;
  color: var(--text);
}

.btn-danger-ghost {
  background: #fff;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn-sm {
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: 6px;
}

.btn-icon {
  padding: 5px 8px;
  font-size: 13px;
  line-height: 1;
}

.action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  bottom: 12px;
  z-index: 20;
}

.form-footer {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

/* ==================== ITEMS EDITOR TABLE ==================== */
.items-editor-wrap {
  overflow-x: auto;
}

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

.items-editor-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 7px 6px;
  border-bottom: 2px solid var(--border);
}

.items-editor-table th.th-qty {
  width: 80px;
  text-align: center;
}

.items-editor-table th.th-price {
  width: 118px;
  text-align: right;
}

.items-editor-table th.th-total {
  width: 108px;
  text-align: right;
}

.items-editor-table th.th-act {
  width: 36px;
}

.items-editor-table td {
  padding: 6px 5px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.items-editor-table textarea.item-desc {
  width: 100%;
  min-height: 36px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
}

.items-editor-table input.item-qty,
.items-editor-table input.item-price {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.items-editor-table input.item-qty {
  text-align: center;
}

.items-editor-table input.item-price {
  text-align: right;
}

.item-line-total {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding-top: 12px !important;
  white-space: nowrap;
}

.totals-editor {
  margin-left: auto;
  max-width: 390px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

.totals-editor-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  gap: 10px;
}

.totals-editor-row:last-child {
  border-bottom: none;
}

.iva-label-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.iva-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.iva-input-wrap input {
  width: 64px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: right;
  font-weight: 700;
  font-size: 12.5px;
  background: #fff;
}

.totals-editor-row.grand {
  background: var(--primary);
  color: #fff;
  font-size: 14.5px;
  padding: 10px 12px;
}

.totals-editor-row.bcv-ref {
  background: #eef6ff;
  color: var(--primary);
  font-size: 12.5px;
}

/* ==================== LIVE PREVIEW SHEET ==================== */
.editor-preview-col {
  position: sticky;
  top: 74px;
}

.preview-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.preview-hint {
  font-weight: 600;
  color: var(--success);
  background: var(--success-bg);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
}

.preview-sheet-container {
  background: #cbd5e1;
  padding: 14px;
  border-radius: var(--radius);
  max-height: calc(100vh - 125px);
  overflow-y: auto;
}

.paper-sheet {
  background: #ffffff;
  color: #1e293b;
  padding: 24px 26px;
  border-radius: 4px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.16);
  font-size: 12px;
  line-height: 1.4;
}

.pv-header {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 3px solid #1e3a5f;
  margin-bottom: 12px;
}

.pv-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1.4;
}

.pv-logo-box {
  width: 124px;
  height: 84px;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
}

.pv-logo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pv-issuer-title {
  font-size: 12.5px;
  font-weight: 800;
  color: #1e3a5f;
  margin-bottom: 2px;
}

.pv-issuer-name {
  font-size: 11px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.pv-issuer-meta {
  font-size: 10.2px;
  color: #334155;
  line-height: 1.45;
}

.pv-header-right {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  min-width: 155px;
}

.pv-badge {
  background: #1e3a5f;
  color: #fff;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
}

.pv-meta-box {
  margin-top: 6px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  padding: 6px 9px;
  width: 100%;
  font-size: 10.2px;
}

.pv-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.pv-section-bar {
  background: #eef2f7;
  color: #1e3a5f;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 4px 9px;
  border-left: 4px solid #1e3a5f;
  border-radius: 0 4px 4px 0;
  margin-bottom: 7px;
}

.pv-client-card {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 9px 11px;
  margin-bottom: 13px;
}

.pv-client-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 6px 14px;
}

.pv-label {
  font-size: 8.8px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
}

.pv-val {
  font-size: 11px;
  font-weight: 600;
  color: #0f172a;
  word-break: break-word;
}

.pv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 11px;
}

.pv-table th {
  background: #1e3a5f;
  color: #fff;
  font-size: 9.6px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 6px 7px;
  border: 1px solid #1e3a5f;
}

.pv-table td {
  padding: 6px 7px;
  border: 1px solid #cbd5e1;
  vertical-align: top;
}

.pv-table tr.alt td {
  background: #f8fafc;
}

.pv-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 13px;
}

.pv-bcv-pill {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  padding: 7px 9px;
  font-size: 10px;
  color: #334155;
  line-height: 1.45;
}

.pv-totals {
  width: 268px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  overflow: hidden;
  margin-left: auto;
}

.pv-tot-line {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 10.8px;
  font-weight: 700;
  gap: 8px;
}

.pv-tot-line.grand {
  background: #1e3a5f;
  color: #fff;
  border-bottom: none;
  font-size: 11.8px;
  padding: 8px 10px;
}

.pv-notes {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #1e3a5f;
  border-radius: 5px;
  padding: 8px 12px;
  margin-bottom: 14px;
}

.pv-notes-title {
  font-size: 9.8px;
  font-weight: 800;
  color: #1e3a5f;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.pv-notes ul {
  margin: 0;
  padding-left: 15px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.5;
}

.pv-footer {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 9.8px;
  color: #64748b;
}

.pv-sign {
  width: 180px;
  text-align: center;
}

.pv-sign-line {
  border-top: 1px solid #64748b;
  padding-top: 3px;
  font-weight: 700;
  color: #334155;
}

/* ==================== TABLES & KPIs ==================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

@media (max-width: 820px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin-top: 4px;
}

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13.5px;
}

.filter-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13.5px;
  background: #fff;
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  color: var(--text-muted);
  padding: 10px;
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}

.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #f8fafc;
}

.text-right {
  text-align: right !important;
}

.text-center {
  text-align: center !important;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.estado-select {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
}

.estado-Pendiente {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: #fde68a;
}

.estado-Aprobado {
  background: var(--success-bg);
  color: var(--success);
  border-color: #bbf7d0;
}

.estado-Ejecutado {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.estado-Rechazado {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #fecaca;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.pill-info {
  background: #dbeafe;
  color: #1d4ed8;
}

.empty-state {
  text-align: center;
  padding: 34px 16px;
  color: var(--text-subtle);
}

/* ==================== TOASTS ==================== */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  border-left: 4px solid #38bdf8;
  animation: toastIn 0.2s ease-out;
}

.toast.success {
  border-left-color: #22c55e;
}

.toast.error {
  border-left-color: #ef4444;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==================== PRINT STYLES ==================== */
@media print {
  @page {
    size: letter;
    margin: 12mm;
  }
  body {
    background: #fff !important;
  }
  .no-print,
  .auth-screen {
    display: none !important;
  }
  .main-container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }
  .editor-layout {
    display: block !important;
  }
  .editor-preview-col {
    position: static !important;
  }
  .preview-sheet-container {
    background: transparent !important;
    padding: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .paper-sheet {
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
