/* =========================
   Google Fonts
========================= */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&family=Roboto+Mono:wght@400;600&display=swap');

/* =========================
   Variables / Base
========================= */
:root {
  --bg-body:      #f0f2f5;
  --text-color:   #333;
  --primary-blue: #4a6b8c;
  --blue-dark:    #3c5a76;
  --blue-mid:     #5b83a8;
  --accent-orange:#e67e22;
  --light-blue-bg:#e6f2fa;
  --green:        #2ecc71;
  --green-dark:   #27ae60;
  --red:          #e74c3c;
  --red-dark:     #c0392b;
  --border:       #ced4da;
  --border-light: #e1e4e8;
  --shadow:       0 1px 3px rgba(0,0,0,.10);
  --shadow-md:    0 4px 12px rgba(0,0,0,.12);
  --radius:       5px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Roboto', sans-serif;
  background: var(--bg-body);
  margin: 0; padding: 0;
  color: var(--text-color);
  font-size: 14px; line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f0f2f5; }
::-webkit-scrollbar-thumb { background: var(--blue-mid); border-radius: 3px; }

/* =========================
   Layout
========================= */
#app-shell { display: flex; flex-direction: column; min-height: 100vh; }

#main-header {
  background: var(--blue-dark);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 58px;
  position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 6px rgba(0,0,0,.25); flex-shrink: 0;
}

.header-brand    { display: flex; align-items: center; gap: 12px; }
.header-logo img { height: 34px; width: auto; border-radius: 4px; display: block; }
.header-title    { font-size: 15px; font-weight: 700; color: #fff; }
.header-subtitle { font-size: 11px; color: rgba(255,255,255,.5); font-family: 'Roboto Mono', monospace; }
.header-right    { display: flex; align-items: center; gap: 16px; }
.header-user     { text-align: right; }
.header-user-name { font-size: 13px; font-weight: 500; color: #fff; }
.header-user-role { font-size: 11px; color: #f5c842; font-family: 'Roboto Mono', monospace; font-weight: 600; }

#nav-sidebar {
  position: fixed; left: 0; top: 58px; bottom: 0; width: 220px;
  background: var(--blue-dark); padding: 10px 0; z-index: 100; overflow-y: auto;
}

.nav-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  color: rgba(255,255,255,.3); padding: 10px 18px 4px; text-transform: uppercase;
}

.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 10px 18px;
  color: rgba(255,255,255,.65); cursor: pointer; font-size: 13px; font-weight: 500;
  border-left: 3px solid transparent; transition: all .15s;
}
.nav-item:hover  { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(230,126,34,.15); color: #f5c842; border-left-color: var(--accent-orange); }
.nav-item-icon   { width: 18px; text-align: center; font-size: 14px; }

#main-content { margin-left: 220px; padding: 24px; flex: 1; }

/* =========================
   Login
========================= */
#login-view {
  min-height: 100vh; background: var(--blue-dark);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}

.login-card {
  background: white; border-radius: 8px; padding: 40px 36px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow-md);
}

.login-logo-wrap { text-align: center; margin-bottom: 24px; }
.login-logo img  { height: 52px; width: auto; margin: 0 auto 12px; display: block; }
.login-title     { font-size: 20px; font-weight: 700; color: var(--primary-blue); margin-bottom: 4px; }
.login-subtitle  { font-size: 12px; color: #888; font-family: 'Roboto Mono', monospace; }

.login-field       { margin-bottom: 15px; }
.login-field label { display: block; font-weight: 700; font-size: 0.85em; color: #555; margin-bottom: 5px; }

.login-field input {
  width: 100%; padding: 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; font-family: 'Roboto', sans-serif;
  box-sizing: border-box; transition: border-color .2s; outline: none;
}
.login-field input:focus { border-color: var(--primary-blue); }

.login-error {
  background: #f8d7da; color: #721c24; padding: 10px;
  border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; text-align: center;
}

.btn-login-submit {
  width: 100%; padding: 12px; background: var(--blue-dark); color: white;
  border: none; border-radius: var(--radius); font-size: 1.05em; font-weight: 700;
  font-family: 'Roboto', sans-serif; cursor: pointer; margin-top: 8px; transition: background .2s;
}
.btn-login-submit:hover    { background: var(--primary-blue); }
.btn-login-submit:disabled { opacity: .55; cursor: not-allowed; }

/* =========================
   Cards
========================= */
.card {
  background: white; border-radius: 6px; box-shadow: var(--shadow);
  padding: 0; margin-bottom: 20px; border: 1px solid var(--border-light); overflow: hidden;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 20px; background: #f7f9fc; border-bottom: 1px solid var(--border-light);
}
.card-title { font-size: 15px; font-weight: 700; color: var(--primary-blue); margin: 0; }
.card-body  { padding: 20px; }

.section-card { background: white; border: 1px solid var(--border-light); border-radius: 6px; margin-bottom: 12px; box-shadow: var(--shadow); overflow: hidden; }
.section-header { padding: 9px 16px; background: var(--blue-dark); display: flex; align-items: center; gap: 10px; }
.section-letter { width: 24px; height: 24px; background: var(--accent-orange); border-radius: 4px; display: flex; align-items: center; justify-content: center; font-family: 'Roboto Mono', monospace; font-size: 12px; font-weight: 700; color: white; flex-shrink: 0; }
.section-title  { font-size: 13px; font-weight: 600; color: #fff; }
.section-body   { padding: 16px; }

/* =========================
   Forms
========================= */
.form-row   { display: flex; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.form-group { flex: 1; min-width: 180px; }
.form-group.full { flex: 0 0 100%; }

label.form-label { display: block; font-weight: 700; font-size: 0.82em; color: #555; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px; }
label.form-label .req { color: var(--red); margin-left: 2px; }

.form-control {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px; font-family: 'Roboto', sans-serif;
  box-sizing: border-box; transition: border-color .2s; outline: none;
  color: var(--text-color); background: #fff;
}
.form-control:focus { border-color: var(--primary-blue); }
.form-control.readonly, .form-control:disabled { background: #f0f2f5; color: #777; cursor: default; border-color: #ddd; }
.form-control.error { border-color: var(--red); }
textarea.form-control { resize: vertical; min-height: 70px; }

.char-count      { font-size: 11px; color: #aaa; text-align: right; margin-top: 2px; font-family: 'Roboto Mono', monospace; }
.char-count.warn { color: var(--accent-orange); }
.char-count.over { color: var(--red); }

.chips-wrap { display: flex; flex-wrap: wrap; gap: 7px; padding: 9px; border: 1px solid var(--border); border-radius: var(--radius); min-height: 44px; background: #fff; }
.chip { padding: 4px 12px; border: 1px solid var(--border); border-radius: 20px; font-size: 12px; font-weight: 500; color: #666; cursor: pointer; transition: all .15s; user-select: none; }
.chip:hover    { border-color: var(--primary-blue); color: var(--primary-blue); }
.chip.selected { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }

/* =========================
   Botones
========================= */
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 8px 15px; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 700; font-family: 'Roboto', sans-serif; cursor: pointer; transition: all .15s; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.97); }

.btn-primary { background: var(--blue-dark); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-blue); }
.btn-amber   { background: var(--accent-orange); color: white; }
.btn-amber:hover:not(:disabled)   { background: #cf6d17; }
.btn-success { background: var(--green-dark); color: white; }
.btn-success:hover:not(:disabled) { background: #219a52; }
.btn-danger  { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled)  { background: var(--red-dark); }
.btn-outline { background: white; border: 1px solid #ccc; color: #555; }
.btn-outline:hover:not(:disabled) { border-color: var(--primary-blue); color: var(--primary-blue); }
.btn-ghost   { background: transparent; color: #777; }
.btn-ghost:hover:not(:disabled)   { background: #f0f2f5; color: var(--text-color); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-logout { background: none; border: 1px solid rgba(255,255,255,.2); color: rgba(255,255,255,.75); padding: 5px 12px; border-radius: var(--radius); font-size: 12px; font-weight: 700; cursor: pointer; font-family: 'Roboto', sans-serif; transition: all .15s; }
.btn-logout:hover { background: rgba(231,76,60,.2); border-color: rgba(231,76,60,.5); color: #fca5a5; }

.btn-remove-row { background: none; border: none; color: #ccc; cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 4px; margin-top: 20px; transition: color .15s; align-self: start; }
.btn-remove-row:hover { color: var(--red); }

.btn-add-row { display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; border: 1px dashed var(--border); border-radius: var(--radius); background: transparent; color: #888; font-size: 12px; font-weight: 700; cursor: pointer; transition: all .15s; font-family: 'Roboto', sans-serif; margin-top: 6px; }
.btn-add-row:hover { border-color: var(--accent-orange); color: var(--accent-orange); }

/* =========================
   Badges
========================= */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; font-family: 'Roboto Mono', monospace; text-transform: uppercase; letter-spacing: .4px; }
.badge-pendiente { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
.badge-aprobado  { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.badge-draft     { background: #f0f2f5; color: #888; border: 1px solid var(--border); }

/* =========================
   Tabla
========================= */
.table-wrap { overflow-x: auto; }
table.main-table { width: 100%; border-collapse: collapse; font-size: 0.9em; }
table.main-table th { background: #f0f2f5; padding: 10px 14px; text-align: left; border-bottom: 2px solid #ddd; font-size: 0.82em; font-weight: 700; color: #555; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
table.main-table td { padding: 9px 14px; border-bottom: 1px solid #eee; vertical-align: middle; }
table.main-table tr:hover td { background: #f7fbff; }

.folio-code      { font-family: 'Roboto Mono', monospace; font-size: 13px; font-weight: 600; color: var(--primary-blue); }
.revision-toggle { font-size: 11px; color: var(--blue-mid); cursor: pointer; text-decoration: underline; display: block; margin-top: 2px; }
.revision-rows td { background: #f7f9fc !important; font-size: 12px; color: #777; padding: 7px 14px; }
.action-btns     { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.filters-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 16px; background: var(--light-blue-bg); border-bottom: 1px solid #b6d4fe; }
.filter-group       { display: flex; flex-direction: column; gap: 3px; }
.filter-group label { font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: #666; margin: 0; }
.filter-control { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; font-family: 'Roboto', sans-serif; background: #fff; outline: none; min-width: 130px; }
.filter-control:focus { border-color: var(--primary-blue); }

.search-wrap  { flex: 1; min-width: 220px; position: relative; }
.search-input { width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; font-family: 'Roboto', sans-serif; background: #fff; outline: none; }
.search-input:focus { border-color: var(--primary-blue); }
.search-icon  { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: #aaa; font-size: 13px; }

.view-tabs { display: flex; padding: 0 16px; border-bottom: 2px solid #ddd; background: #f7f9fc; }
.view-tab  { padding: 10px 18px; font-size: 13px; font-weight: 500; color: #777; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.view-tab:hover  { color: var(--text-color); }
.view-tab.active { color: var(--primary-blue); border-bottom-color: var(--accent-orange); font-weight: 700; }

.pagination  { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 0; border-top: 1px solid #eee; font-size: 13px; color: #777; background: #f7f9fc; }
.page-btns   { display: flex; gap: 4px; justify-content: center; }
.page-btn    { padding: 4px 10px; border: 1px solid #ccc; border-radius: 4px; background: white; font-size: 12px; cursor: pointer; color: var(--text-color); font-family: 'Roboto', sans-serif; transition: all .15s; }
.page-btn:hover  { border-color: var(--primary-blue); color: var(--primary-blue); }
.page-btn.active { background: var(--blue-dark); color: white; border-color: var(--blue-dark); }
.page-btn:disabled { opacity: .4; cursor: default; }

.detail-sticky { position: sticky; top: 58px; z-index: 100; background: white; border-bottom: 2px solid #ddd; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.detail-folio   { font-family: 'Roboto Mono', monospace; font-size: 20px; font-weight: 700; color: var(--primary-blue); }
.detail-meta    { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.decision-row { display: grid; grid-template-columns: 1.2fr 90px 90px 2fr 28px; gap: 8px; align-items: start; padding: 10px 12px; background: #f7f9fc; border: 1px solid var(--border-light); border-radius: var(--radius); margin-bottom: 8px; }
.decision-row select, .decision-row input[type="number"] { min-width: 0; width: 100%; }
.decision-row-label { font-size: 10px; font-weight: 700; color: var(--accent-orange); font-family: 'Roboto Mono', monospace; letter-spacing: .4px; margin-bottom: 4px; text-transform: uppercase; }

/* =========================
   Modales
========================= */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 24px; }
.modal-box     { background: #f4f4f4; width: 95%; max-width: 540px; border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-md); }
.modal-header  { padding: 14px 18px; background: white; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #ddd; }
.modal-title   { margin: 0; font-size: 15px; font-weight: 700; color: var(--primary-blue); }
.modal-close   { background: none; border: none; font-size: 1.4em; cursor: pointer; color: #999; transition: color .15s; }
.modal-close:hover { color: var(--red); }
.modal-body    { padding: 20px; overflow-y: auto; font-size: 14px; line-height: 1.6; }
.modal-footer  { padding: 12px 18px; background: white; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid #ddd; }

/* =========================
   Audit / Admin
========================= */
.audit-item { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid #eee; font-size: 13px; align-items: flex-start; }
.audit-action-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; font-family: 'Roboto Mono', monospace; white-space: nowrap; flex-shrink: 0; min-width: 74px; text-align: center; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { background: #f0f2f5; padding: 9px 12px; text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: #555; border-bottom: 2px solid #ddd; }
.admin-table td { padding: 9px 12px; border-bottom: 1px solid #eee; vertical-align: middle; }

/* =========================
   Alertas / Utils
========================= */
.alert         { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-error   { background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; }
.alert-success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; }
.alert-info    { background: var(--light-blue-bg); border: 1px solid #b6d4fe; color: var(--primary-blue); }

.empty-state      { text-align: center; padding: 48px 24px; color: #999; }
.empty-state-icon { font-size: 38px; margin-bottom: 12px; opacity: .35; }
.empty-state-text { font-size: 14px; }

.divider      { border: none; border-top: 1px solid #eee; margin: 16px 0; }
.text-mono    { font-family: 'Roboto Mono', monospace; }
.text-muted   { color: #777; }
.text-sm      { font-size: 12px; }
.mt-4         { margin-top: 16px; }
.mb-4         { margin-bottom: 16px; }
.flex         { display: flex; }
.gap-2        { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full       { width: 100%; }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================
   Impresion A4
========================= */
#print-area { display: none; }

@media print {
  @page { size: A4 portrait; margin: 12mm 5mm 5mm 5mm; }
  body { background: white !important; color: black !important; padding: 8mm 0 0 0 !important; font-size: 9px !important; line-height: 1.1 !important; }
  #app-shell, #login-view, #main-header, #nav-sidebar, .no-print, .btn, .btn-action, .btn-search-nav, .detail-sticky, .view-tabs, .filters-bar, .pagination { display: none !important; }
  #print-area { display: block !important; }
  .print-card { box-shadow: none !important; border: 1px solid #000 !important; margin-bottom: 3px !important; padding: 4px 6px !important; page-break-inside: avoid; border-radius: 0 !important; }
  .print-section-title { font-size: 9px !important; font-weight: 700 !important; border-bottom: 1px solid #ccc !important; padding-bottom: 2px !important; margin-bottom: 4px !important; text-transform: uppercase; }
  .print-grid { display: grid !important; grid-template-columns: repeat(3, 1fr) !important; gap: 4px 10px !important; }
  .print-field { margin-bottom: 3px !important; }
  .print-label { font-size: 7.5px !important; font-weight: 700 !important; color: #666 !important; text-transform: uppercase; display: block; }
  .print-value { font-size: 8.5px !important; border-bottom: 1px solid #999 !important; min-height: 11px !important; display: block; padding-bottom: 1px; }
  .print-header { display: flex !important; justify-content: space-between !important; align-items: flex-start !important; margin-bottom: 4px !important; }
  .print-logo-box { width: 80px; flex-shrink: 0; }
  .print-logo-img { width: 100%; height: auto; display: block; }  .print-center { text-align: center; flex: 1; }
  .print-doc-title { font-size: 12px !important; font-weight: 700 !important; }
  .print-folio-box { text-align: right; }
  .print-folio { font-family: 'Roboto Mono', monospace !important; font-size: 11px !important; font-weight: 700 !important; }
  .print-status-stamp { font-size: 10px !important; font-weight: 700 !important; padding: 2px 6px !important; border: 2px solid !important; border-radius: 3px !important; display: inline-block; }
  .print-draft-note { font-size: 7.5px !important; color: #888 !important; font-style: italic; margin-top: 2px; }
  .print-firmas { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 8px !important; margin-top: 6px !important; }
  .print-firma-block { border-top: 1px solid #999; padding-top: 2px; }
  .print-firma-label { font-size: 7.5px !important; color: #666; text-transform: uppercase; font-weight: 700; }
  .print-firma-name  { font-size: 8.5px !important; font-weight: 600; margin-top: 1px; }
  .print-firma-line  { border-bottom: 1px solid #999; height: 16px; }
  .print-footer { display: flex !important; justify-content: space-between !important; border-top: 1px solid #bbb !important; padding-top: 2px !important; margin-top: 3px !important; font-size: 7.5px !important; color: #888 !important; font-family: 'Roboto Mono', monospace !important; }
  .print-decisions-table { width: 100%; border-collapse: collapse; font-size: 8px; }
  .print-decisions-table th, .print-decisions-table td { border: 1px solid #ccc; padding: 2px 5px; text-align: left; }
  .print-decisions-table th { background: #f0f0f0; font-weight: 700; font-size: 7.5px; }
  input, select, textarea { border: none !important; border-bottom: 1px solid #999 !important; background: transparent !important; padding: 0 !important; font-size: 9px !important; min-height: 12px !important; }
  textarea { height: 22px !important; overflow: hidden; }
}
.pdf-cell { border: 1px solid #000; padding: 1mm 2mm; font-size: 8pt; }