/* ============================================================
   Terappia Cloud - Sistema de diseno
   Todos los estilos del back office viven en este unico archivo.
   Portado del monorepo hermano dex/cloud.
   ============================================================ */

/* ---------- 1. Tokens ---------- */
:root {
  --bg:        #f4f6fb;
  --canvas:    #888a8e;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --primary:   #539B99;
  --primary-h: #3E7473;
  --danger:    #ef4444;
  --success:   #22c55e;
  --warn:      #f59e0b;
  --info:      #3b82f6;
  --purple:    #8b5cf6;
  --text:      #1e293b;
  --muted:     #64748b;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --row-hover: #f1f5f9;
}

[data-theme="dark"] {
  --bg:        #32373D;
  --canvas:    #2b2c2f;
  --surface:   #3d4248;
  --border:    #555b63;
  --primary:   #539B99;
  --primary-h: #3E7473;
  --danger:    #ef4444;
  --success:   #22c55e;
  --warn:      #f59e0b;
  --info:      #3b82f6;
  --text:      #f0f0f0;
  --muted:     #aaaaaa;
  --shadow:    0 1px 4px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.6);
  --row-hover: #4a5058;
}

/* ---------- 2. Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}

/* ---------- 3. Layout principal ---------- */
.layout  { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--surface);
           border-right: 1px solid var(--border);
           display: flex; flex-direction: column; flex-shrink: 0; }
.main    { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar  { background: var(--surface); border-bottom: 1px solid var(--border);
           padding: 0 24px; height: 60px;
           display: flex; align-items: center; justify-content: space-between;
           box-shadow: var(--shadow); }
.content { flex: 1; padding: 24px; overflow-y: auto; background: var(--canvas); }

/* ---------- 4. Sidebar ---------- */
.sidebar-logo  { padding: 20px 20px 16px; border-bottom: 1px solid var(--border);
                 display: flex; align-items: center; gap: 8px; }
.sidebar-nav   { padding: 0 0 12px; flex: 1; }
.sidebar-footer{ padding: 10px 20px; font-size: .75rem; color: var(--muted);
                 border-top: 1px solid var(--border); text-align: center;
                 letter-spacing: .03em; font-family: monospace; }

.nav-item { display: flex; align-items: center; gap: 10px;
            padding: 10px 20px; font-size: .9rem; color: var(--muted);
            cursor: pointer; border-left: 3px solid transparent;
            transition: background .15s, color .15s; text-decoration: none; }
.nav-item:hover  { background: rgba(83,155,153,.14); color: var(--primary); }
.nav-item.active { background: var(--primary); color: #fff;
                   border-left-color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.nav-group-wrap .nav-sub      { display: none; background: var(--bg); }
.nav-group-wrap.open .nav-sub { display: block; }
.nav-group-toggle             { justify-content: space-between; }
.nav-group-arrow              { font-size: .75rem; font-weight: 700;
                                margin-left: auto; transition: transform .2s;
                                color: var(--muted); }
.nav-group-wrap.open .nav-group-arrow { transform: rotate(45deg); }
.nav-sub-item                 { padding-left: 34px; background: var(--bg); }

/* ---------- 5. Topbar ---------- */
.topbar-title    { font-size: 1rem; font-weight: 600; flex: 1; }
.topbar-user     { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-username { background: none; border: none; cursor: pointer;
                   font-size: .85rem; color: var(--muted);
                   display: flex; align-items: center; gap: 4px;
                   padding: 6px 10px; border-radius: 8px; transition: background .15s; }
.topbar-username:hover { background: var(--border); }
.user-dropdown   { display: none; position: absolute; right: 0; top: calc(100% + 6px);
                   background: var(--surface); border: 1px solid var(--border);
                   border-radius: 10px; box-shadow: var(--shadow-lg);
                   min-width: 160px; overflow: hidden; z-index: 200; }
.user-dropdown.open { display: block; }

/* ---------- 6. Botones ---------- */
.btn { padding: 8px 16px; border-radius: var(--radius); border: none;
       font-size: .88rem; font-weight: 600; cursor: pointer;
       display: inline-flex; align-items: center; gap: 6px;
       transition: background .15s, transform .1s; }
.btn:active           { transform: scale(.97); }
.btn:disabled         { opacity: .65; cursor: not-allowed; }
.btn-primary          { background: var(--primary); color: #fff; }
.btn-primary:hover    { background: var(--primary-h); }
.btn-danger           { background: var(--danger); color: #fff; }
.btn-danger:hover     { background: #dc2626; }
.btn-secondary        { background: var(--surface); color: var(--text);
                        border: 1px solid var(--border); }
.btn-secondary:hover  { background: var(--bg); }
.btn-ghost            { background: transparent; color: var(--muted);
                        border: 1px solid var(--border); }
.btn-ghost:hover      { background: var(--bg); color: var(--text); }
.btn-sm               { padding: 5px 12px; font-size: .8rem; }
.btn-icon-sm          { background: none; border: none; cursor: pointer;
                        padding: 4px 8px; border-radius: 6px; font-size: .85rem; }
.btn-icon-sm:hover    { background: var(--bg); }

/* ---------- 7. Inputs ---------- */
input[type=text], input[type=number], input[type=url], input[type=tel],
input[type=email], input[type=date], input[type=time], input[type=datetime-local],
input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: .88rem; background: var(--surface);
  color: var(--text); outline: none; transition: border .15s; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(83,155,153,.18);
}
input:disabled, select:disabled, textarea:disabled,
input[readonly], textarea[readonly] {
  color: var(--muted); background: var(--bg); cursor: not-allowed; opacity: .75;
}
textarea { resize: vertical; min-height: 60px; }

.field-error   { margin-top: 4px; font-size: .78rem; color: var(--danger); }
.form-group label .req { color: var(--danger); font-weight: 700; margin-left: 2px; }
.input-invalid { border-color: var(--danger) !important;
                 box-shadow: 0 0 0 2px rgba(239,68,68,.18); }

/* ---------- Help tip (icono + tooltip global) ---------- */
.help-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 4px;
  color: var(--muted); cursor: help;
  font-size: .85rem; vertical-align: middle;
  border-radius: 50%;
}
.help-tip:hover, .help-tip:focus { color: var(--primary); outline: none; }

/* Tooltip global: se monta en <body>, escapa el overflow del modal */
#helpTooltip {
  position: fixed;
  min-width: 240px; max-width: 340px;
  padding: 8px 10px;
  background: #1f2937; color: #f9fafb;
  font-size: .78rem; font-weight: 400; line-height: 1.45;
  border-radius: 6px; box-shadow: 0 6px 16px rgba(0,0,0,.35);
  white-space: normal; text-align: left;
  z-index: 100000; pointer-events: none;
  opacity: 0; transition: opacity .12s;
}
#helpTooltip.visible { opacity: 1; }
#helpTooltip::after {
  content: ''; position: absolute;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
  border: 6px solid transparent;
}
#helpTooltip.above::after { top: 100%; border-top-color: #1f2937; }
#helpTooltip.below::after { bottom: 100%; border-bottom-color: #1f2937; }

/* ---------- 8. Formularios ---------- */
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3  { grid-template-columns: repeat(3, 1fr); }
.form-row-4  { grid-template-columns: repeat(4, 1fr); }
.form-group  { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea { width: 100%; }

/* ---------- 10. Tablas ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); box-shadow: var(--shadow);
              overflow-x: auto; overflow-y: hidden; }
table        { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead tr     { background: var(--bg); }
th           { padding: 10px 14px; text-align: left;
               font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
               color: var(--muted); font-weight: 600;
               border-bottom: 1px solid var(--border); white-space: nowrap; }
td           { padding: 10px 14px; border-bottom: 1px solid var(--border);
               vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }
.actions      { display: flex; gap: 4px; }
.table-empty  { text-align: center; padding: 48px 24px; color: var(--muted); }
.td-img       { width: 44px; height: 44px; object-fit: cover;
                border-radius: 8px; border: 1px solid var(--border); }
.td-nombre    { font-weight: 600; }
.td-id        { color: var(--muted); font-size: .8rem; }

/* ---------- 11. Badges ---------- */
.badge         { display: inline-block; padding: 2px 10px;
                 border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-info    { background: #eff6ff; color: #3b82f6; }
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger  { background: #fef2f2; color: #dc2626; }
.badge-warn    { background: #fef9c3; color: #a16207; }

/* ---------- 12. Stat cards ---------- */
.stats-bar  { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card  { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); padding: 14px 20px;
              display: flex; flex-direction: column; gap: 2px;
              flex: 1; min-width: 120px; }
.stat-label { font-size: .75rem; color: var(--muted);
              text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value.green  { color: var(--success); }
.stat-value.blue   { color: var(--primary); }
.stat-value.red    { color: var(--danger); }

.dash-link { cursor: pointer; transition: opacity .15s; }
.dash-link:hover { opacity: .75; }
.stat-card.dash-link:hover { background: var(--bg); }

/* ---------- 9. Toolbar (búsqueda + filtros + acciones) ---------- */
.toolbar       { display: flex; align-items: center; gap: 12px;
                 flex-wrap: wrap; margin-bottom: 20px; }
.toolbar-left  { display: flex; align-items: center; gap: 10px;
                 flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 10px; }

.search-wrap        { position: relative; display: inline-flex; align-items: center; }
.search-wrap .search-input { width: 260px; padding-right: 28px; }
.search-clear       { position: absolute; right: 6px; background: none; border: none;
                      cursor: pointer; color: var(--muted); font-size: 1.1rem;
                      padding: 2px 6px; border-radius: 50%; transition: color .15s; }
.search-clear:hover { color: var(--text); }

.filter-chip        { padding: 6px 12px; border-radius: 20px;
                      border: 1.5px solid var(--border);
                      font-size: .8rem; font-weight: 600; cursor: pointer;
                      white-space: nowrap; background: var(--surface);
                      color: var(--muted); transition: all .15s; }
.filter-chip:hover  { border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Botones solo-ícono con badge opcional */
.btn-icon            { position: relative; padding: 7px 11px; }
.btn-icon.active     { border-color: var(--primary); color: var(--primary); }
.btn-icon-badge      { position: absolute; top: -4px; right: -4px;
                       background: var(--primary); color: #fff;
                       font-size: .65rem; font-weight: 700;
                       min-width: 16px; height: 16px; padding: 0 4px;
                       border-radius: 99px; display: inline-flex;
                       align-items: center; justify-content: center;
                       line-height: 1; }

/* ---------- 14. Modales ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45);
                  display: flex; align-items: center; justify-content: center;
                  z-index: 100; opacity: 0; pointer-events: none;
                  transition: opacity .2s; }
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal          { background: var(--surface); border-radius: 14px;
                  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
                  box-shadow: var(--shadow-lg);
                  transform: scale(.96) translateY(12px);
                  transition: transform .2s; margin: 16px; }
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal-header   { padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
                  display: flex; align-items: center; justify-content: space-between;
                  gap: 12px; }
.modal-title    { font-size: 1rem; font-weight: 700;
                  display: inline-flex; align-items: center; gap: 8px; }
.modal-body     { padding: 20px 24px;
                  display: flex; flex-direction: column; gap: 16px; }
.modal-footer   { padding: 16px 24px; border-top: 1px solid var(--border);
                  display: flex; gap: 10px; justify-content: flex-end; }

/* Pestañas dentro de un modal (mismo look & feel que .db-exp-tabs). */
.modal-tabs        { display: flex; gap: 4px; border-bottom: 1px solid var(--border);
                     margin: -4px -4px 4px; padding: 0 4px; flex-shrink: 0; }
.modal-tab         { background: none; border: none; cursor: pointer;
                     font-family: inherit; font-size: .85rem; font-weight: 600;
                     color: var(--muted); padding: 10px 14px;
                     border-bottom: 2px solid transparent; margin-bottom: -1px;
                     display: inline-flex; align-items: center; gap: 8px;
                     transition: color .15s, border-color .15s; }
.modal-tab:hover   { color: var(--text); }
.modal-tab.active  { color: var(--primary); border-bottom-color: var(--primary); }
.modal-tabpanel    { display: flex; flex-direction: column; gap: 16px; }
.modal-tabpanel[hidden] { display: none; }

/* Tarjetas de campos del modal de Consulta (10% más oscuro que --surface) */
.consult-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.consult-card   { background: color-mix(in srgb, var(--surface) 90%, #000);
                  border: none; border-radius: var(--radius);
                  padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.consult-card.full { grid-column: 1 / -1; }
.consult-label  { font-size: .72rem; color: var(--muted);
                  text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.consult-value  { font-size: .9rem; color: var(--text); word-break: break-word; }
@media (max-width: 540px) { .consult-grid { grid-template-columns: 1fr; } }

/* Markdown renderizado dentro de una tarjeta de Consulta */
.md-body                             { line-height: 1.5; }
.md-body > *:first-child             { margin-top: 0; }
.md-body > *:last-child              { margin-bottom: 0; }
.md-body p                           { margin: 0 0 8px; }
.md-body h1, .md-body h2, .md-body h3,
.md-body h4, .md-body h5, .md-body h6 { margin: 12px 0 6px; font-weight: 700; line-height: 1.25; }
.md-body h1 { font-size: 1.15rem; }
.md-body h2 { font-size: 1.05rem; }
.md-body h3 { font-size: .98rem; }
.md-body h4, .md-body h5, .md-body h6 { font-size: .92rem; color: var(--muted); }
.md-body strong                      { font-weight: 700; }
.md-body em                          { font-style: italic; }
.md-body ul, .md-body ol             { margin: 0 0 8px; padding-left: 22px; }
.md-body li                          { margin-bottom: 2px; }
.md-body a                           { color: var(--primary); text-decoration: underline; }
.md-body a:hover                     { color: var(--primary-h); }
.md-body code                        { background: color-mix(in srgb, var(--surface) 85%, #000);
                                       border-radius: 4px; padding: 1px 5px;
                                       font-family: monospace; font-size: .85em; }
.md-body pre                         { background: color-mix(in srgb, var(--surface) 85%, #000);
                                       border-radius: 6px; padding: 10px 12px;
                                       overflow-x: auto; margin: 0 0 8px; }
.md-body pre code                    { background: none; padding: 0; font-size: .82rem; }
.md-body blockquote                  { border-left: 3px solid var(--border);
                                       margin: 0 0 8px; padding: 2px 12px;
                                       color: var(--muted); }
.md-body hr                          { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.md-body table                       { border-collapse: collapse; margin: 0 0 8px; font-size: .85rem; }
.md-body th, .md-body td             { border: 1px solid var(--border); padding: 4px 8px; }

/* ---------- 15. Confirm dialog ---------- */
.confirm-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5);
                    display: flex; align-items: center; justify-content: center;
                    z-index: 150; opacity: 0; pointer-events: none;
                    transition: opacity .15s; }
.confirm-backdrop.open { opacity: 1; pointer-events: all; }
.confirm-box     { background: var(--surface); border-radius: 14px;
                   padding: 28px 28px 20px; max-width: 380px;
                   width: calc(100% - 32px); box-shadow: var(--shadow-lg);
                   transform: scale(.95); transition: transform .15s; }
.confirm-backdrop.open .confirm-box { transform: scale(1); }
.confirm-title   { font-weight: 700; margin-bottom: 8px; }
.confirm-msg     { font-size: .88rem; color: var(--muted); margin-bottom: 20px;
                   line-height: 1.45; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Tools grid (sección Herramientas: launchers) ---------- */
.tools-grid { display: grid; gap: 16px;
              grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.tool-card  { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); box-shadow: var(--shadow);
              padding: 18px 20px; cursor: pointer;
              display: flex; flex-direction: column; gap: 6px;
              transition: transform .1s, box-shadow .15s, border-color .15s; }
.tool-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg);
                   transform: translateY(-1px); }
.tool-card:active { transform: scale(.99); }
.tool-card-icon  { font-size: 1.8rem; line-height: 1; margin-bottom: 4px; }
.tool-card-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.tool-card-desc  { font-size: .82rem; color: var(--muted); line-height: 1.45; }
.tool-card-desc code { background: var(--bg); padding: 1px 5px; border-radius: 4px;
                       font-size: .78rem; }

/* ---------- Explorador S3 ---------- */
.s3-modal { max-width: 980px; width: calc(100% - 32px); }
.s3-toolbar { display: flex; align-items: center; justify-content: space-between;
              gap: 12px; flex-wrap: wrap; }
.s3-toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.s3-breadcrumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
                  font-size: .88rem; color: var(--muted); min-height: 28px; }
.s3-breadcrumbs .s3-bc { background: none; border: none; cursor: pointer;
                         color: var(--primary); font-size: .88rem; font-weight: 600;
                         padding: 2px 6px; border-radius: 6px; }
.s3-breadcrumbs .s3-bc:hover { background: var(--bg); }
.s3-breadcrumbs .s3-bc.current { color: var(--text); cursor: default; }
.s3-breadcrumbs .s3-bc.current:hover { background: none; }
.s3-breadcrumbs .s3-sep { color: var(--muted); opacity: .6; }

.s3-table-card { background: var(--surface); border: 1px solid var(--border);
                 border-radius: var(--radius); overflow: auto;
                 max-height: 60vh; }
.s3-table-card table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.s3-table-card thead tr  { background: var(--bg); position: sticky; top: 0; z-index: 1; }
.s3-table-card th        { padding: 10px 14px; text-align: left;
                           font-size: .75rem; text-transform: uppercase;
                           letter-spacing: .05em; color: var(--muted);
                           font-weight: 600; border-bottom: 1px solid var(--border);
                           white-space: nowrap; }
.s3-table-card td        { padding: 10px 14px; border-bottom: 1px solid var(--border);
                           vertical-align: middle; }
.s3-table-card tbody tr:last-child td { border-bottom: none; }
.s3-table-card tbody tr.row-clickable:hover { background: var(--row-hover); }
.s3-table-card .s3-name   { display: flex; align-items: center; gap: 8px;
                            font-weight: 500; }
.s3-table-card .s3-icon   { font-size: 1.05rem; width: 22px; text-align: center; }
.s3-table-card .s3-size,
.s3-table-card .s3-date   { color: var(--muted); font-size: .82rem;
                            font-family: monospace; }
.s3-footer-info { font-size: .78rem; color: var(--muted);
                  display: flex; justify-content: space-between; gap: 8px;
                  flex-wrap: wrap; }

/* ---------- Config cards (sección Configuración) ---------- */
.config-grid       { display: grid; gap: 16px;
                     grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.config-card       { background: var(--surface); border: 1px solid var(--border);
                     border-radius: var(--radius); box-shadow: var(--shadow);
                     display: flex; flex-direction: column; overflow: hidden; }
.config-card-header { display: flex; gap: 14px; padding: 16px 18px; align-items: flex-start; }
.config-card-icon  { font-size: 1.8rem; line-height: 1; flex-shrink: 0; }
.config-card-info  { display: flex; flex-direction: column; gap: 4px; }
.config-card-title { font-weight: 700; font-size: .95rem; color: var(--text); }
.config-card-desc  { font-size: .82rem; color: var(--muted); line-height: 1.4; }
.config-card-body  { padding: 14px 18px; border-top: 1px solid var(--border); }

/* ---------- 17. Toggle switches ---------- */
.toggle-switch { display: inline-flex; align-items: center; gap: 12px;
                 cursor: pointer; user-select: none; }
.toggle-switch input { display: none; }
.toggle-track  { width: 44px; height: 24px; border-radius: 12px;
                 background: var(--border); position: relative;
                 transition: background .2s; flex-shrink: 0; }
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-thumb  { position: absolute; top: 3px; left: 3px;
                 width: 18px; height: 18px; border-radius: 50%;
                 background: #fff; transition: transform .2s;
                 box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }
.toggle-label  { font-size: .9rem; color: var(--text); }

/* ---------- 20. Menú contextual ---------- */
.ctx-menu { position: fixed; background: var(--surface);
            border: 1px solid var(--border); border-radius: 10px;
            box-shadow: var(--shadow-lg); min-width: 180px;
            padding: 6px; z-index: 250; display: none; }
.ctx-menu.open { display: block; }
.ctx-menu button { display: flex; align-items: center; gap: 10px;
                   width: 100%; padding: 8px 12px; border: none;
                   background: none; cursor: pointer;
                   font-size: .88rem; color: var(--text);
                   border-radius: 6px; text-align: left; }
.ctx-menu button i { width: 16px; text-align: center; color: var(--muted); }
.ctx-menu button:hover { background: var(--bg); }
.ctx-menu .ctx-menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.ctx-menu .ctx-menu-danger { color: var(--danger); }
.ctx-menu .ctx-menu-danger i { color: var(--danger); }
.ctx-menu .ctx-menu-danger:hover { background: rgba(239,68,68,.08); }

/* Filas clickeables del listado */
.row-clickable { cursor: pointer; }

/* ---------- Mapa de cuentas (Google Maps) ---------- */
.cuenta-map     { height: 260px; width: 100%;
                  border: 1px solid var(--border); border-radius: var(--radius);
                  overflow: hidden; background: var(--bg); }
.map-helper     { font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.map-placeholder{ display: flex; align-items: center; justify-content: center;
                  height: 100%; padding: 16px; text-align: center;
                  font-size: .85rem; color: var(--muted); line-height: 1.5; }
.map-placeholder code { background: var(--bg); padding: 1px 6px; border-radius: 4px;
                        font-family: monospace; }

/* ---------- 16. Toasts ---------- */
.toast { position: fixed; bottom: 24px; left: 50%;
         transform: translateX(-50%) translateY(16px);
         background: #1e293b; color: #fff;
         padding: 10px 20px; border-radius: 99px;
         font-size: .88rem; opacity: 0; pointer-events: none;
         transition: opacity .2s, transform .2s;
         z-index: 200; white-space: nowrap; }
.toast.show  { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ---------- 17. Banner de nueva versión ---------- */
.version-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: var(--primary); color: #fff;
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  font-size: .9rem; font-weight: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.version-banner button {
  background: #fff; color: var(--primary);
  border: none; border-radius: 6px;
  padding: 5px 14px; font-size: .85rem; font-weight: 600;
  cursor: pointer;
}
.version-banner button:hover { background: #e0e7ff; }

/* ---------- 18. Spinner ---------- */
.spin { display: inline-block; width: 28px; height: 28px;
        border: 3px solid var(--border); border-top-color: var(--primary);
        border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 19. Responsive / mobile ---------- */
.hamburger        { display: none; background: none; border: none; cursor: pointer;
                    font-size: 1.4rem; color: var(--text);
                    padding: 4px 8px; margin-right: 8px; line-height: 1; }
.sidebar-overlay  { display: none; position: fixed; inset: 0;
                    background: rgba(0,0,0,.45); z-index: 199; }
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  .hamburger { display: inline-flex; align-items: center; }
  .sidebar   { position: fixed; top: 0; left: 0; height: 100vh; z-index: 200;
               transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
}

/* ---------- Explorador DB ---------- */
.modal.db-exp-modal        { max-width: 1080px; width: calc(100% - 32px);
                             height: calc(100vh - 64px); max-height: calc(100vh - 64px);
                             display: flex; flex-direction: column; overflow: hidden; }
.db-exp-modal .modal-body  { gap: 12px; flex: 1; min-height: 0;
                             display: flex; flex-direction: column; overflow: hidden; }

.db-exp-toolbar       { display: flex; align-items: center; justify-content: space-between;
                        gap: 12px; flex-wrap: wrap; flex-shrink: 0; }
.db-exp-toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.db-exp-toolbar-right .search-wrap .search-input { width: 220px; }

.db-exp-breadcrumbs   { display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
                        font-size: .88rem; color: var(--muted); min-height: 28px; }
.db-exp-crumb         { background: none; border: none; cursor: pointer;
                        color: var(--primary); font-size: .88rem; font-weight: 600;
                        padding: 2px 6px; border-radius: 6px; font-family: inherit;
                        display: inline-flex; align-items: center; gap: 6px; }
.db-exp-crumb:hover   { background: var(--bg); }
.db-exp-crumb.current { color: var(--text); cursor: default; }
.db-exp-crumb.current:hover { background: none; }
.db-exp-crumb-sep     { color: var(--muted); opacity: .6; }

.db-exp-view          { display: flex; flex-direction: column; gap: 8px;
                        flex: 1; min-height: 0; }

.db-exp-tabs          { display: flex; gap: 4px; border-bottom: 1px solid var(--border);
                        margin: 0 -4px; padding: 0 4px; flex-shrink: 0; }
.db-exp-tab           { background: none; border: none; cursor: pointer;
                        font-family: inherit; font-size: .85rem; font-weight: 600;
                        color: var(--muted); padding: 10px 14px;
                        border-bottom: 2px solid transparent; margin-bottom: -1px;
                        display: inline-flex; align-items: center; gap: 8px;
                        transition: color .15s, border-color .15s; }
.db-exp-tab:hover     { color: var(--text); }
.db-exp-tab.active    { color: var(--primary); border-bottom-color: var(--primary); }
.db-exp-tab i         { font-size: .9rem; }
.db-exp-tab-count     { display: inline-flex; align-items: center; justify-content: center;
                        min-width: 18px; height: 18px; padding: 0 6px; border-radius: 99px;
                        background: var(--bg); border: 1px solid var(--border);
                        color: var(--muted); font-size: .7rem; font-weight: 700; }
.db-exp-tab.active .db-exp-tab-count {
                        background: rgba(83,155,153,.22); color: var(--primary);
                        border-color: rgba(83,155,153,.5); }

.db-exp-tabpanel      { flex: 1; min-height: 0; display: flex; flex-direction: column;
                        padding-top: 8px; gap: 8px; }
.db-exp-tabpanel[hidden] { display: none; }

.db-exp-recs-toolbar       { display: flex; align-items: center; justify-content: space-between;
                             gap: 12px; flex-wrap: wrap; flex-shrink: 0; }
.db-exp-recs-toolbar-left  { display: flex; align-items: center; gap: 10px; }
.db-exp-recs-toolbar-right { display: flex; align-items: center; gap: 8px; }
.db-exp-recs-toolbar-right .search-wrap .search-input { width: 240px; }
.db-exp-limite-label       { display: inline-flex; align-items: center; gap: 8px;
                             font-size: .8rem; font-weight: 600; color: var(--muted); }
.db-exp-limite-label select{ padding: 6px 10px; font-size: .85rem; }

.db-exp-table-card           { overflow: auto; }
.db-exp-fill                 { flex: 1; min-height: 0; max-height: none; }
.db-exp-table-card thead tr  { background: var(--bg); position: sticky; top: 0; z-index: 1; }
.db-exp-table-card tbody tr.row-clickable       { cursor: pointer; }
.db-exp-table-card tbody tr.row-clickable:hover { background: var(--row-hover); }
.db-exp-table-card td        { vertical-align: top; }

.db-exp-nombre     { font-weight: 600; word-break: break-all; }
.db-exp-col-nombre { font-weight: 600; color: var(--text); word-break: break-all; }
.db-exp-coment     { font-size: .75rem; color: var(--muted); margin-top: 2px;
                     font-style: italic; }
.db-exp-num        { color: var(--muted); font-size: .82rem; font-family: monospace;
                     white-space: nowrap; text-align: right; }
.db-exp-mono       { font-family: monospace; font-size: .82rem; color: var(--text);
                     white-space: nowrap; }
.db-exp-recs-card td { font-family: monospace; font-size: .8rem;
                       max-width: 280px; overflow: hidden; text-overflow: ellipsis;
                       white-space: nowrap; }
.db-exp-recs-card td:hover { white-space: normal; word-break: break-all; }
.db-exp-null       { color: var(--muted); font-style: italic; font-family: monospace;
                     font-size: .78rem; }
.db-exp-pk-icon    { color: var(--warn); font-size: .75rem; margin-left: 4px; }

.db-exp-footer-info { font-size: .78rem; color: var(--muted);
                      display: flex; justify-content: space-between;
                      gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.db-exp-empty       { padding: 30px; text-align: center; color: var(--muted); }

.db-exp-env-dev  { background: #dcfce7; color: #16a34a; }
.db-exp-env-prod { background: #fef2f2; color: #dc2626; }

/* Edición inline de celdas */
.db-exp-cell-edit                 { cursor: text; }
.db-exp-cell-edit:hover           { outline: 1px solid var(--border); outline-offset: -1px;
                                    background: rgba(0,0,0,.03); }
.db-exp-cell-lock                 { cursor: not-allowed; color: var(--muted); }
.db-exp-cell-lock:hover           { background: transparent; }
.db-exp-cell-editing              { padding: 4px 6px !important; background: var(--bg);
                                    outline: 2px solid var(--primary); outline-offset: -2px;
                                    white-space: normal !important; max-width: none !important;
                                    overflow: visible !important; }
.db-exp-cell-saving               { opacity: .6; pointer-events: none; }
.db-exp-cell-ok                   { animation: dbExpCellOk .8s ease-out; }
@keyframes dbExpCellOk {
  0%   { background: rgba(34,197,94,.35); }
  100% { background: transparent; }
}
.db-exp-edit-wrap                 { display: flex; align-items: center; gap: 4px; }
.db-exp-edit-input                { flex: 1; min-width: 80px; padding: 4px 6px !important;
                                    font-family: monospace; font-size: .82rem !important;
                                    border-radius: 6px !important; }
.db-exp-edit-actions              { display: inline-flex; gap: 2px; flex-shrink: 0; }
.db-exp-edit-actions .btn-icon-sm { padding: 2px 6px; font-size: .8rem; }

@media (max-width: 640px) {
  .db-exp-table-card th:nth-child(4),
  .db-exp-table-card td:nth-child(4),
  .db-exp-table-card th:nth-child(7),
  .db-exp-table-card td:nth-child(7) { display: none; }
}

/* ---------- Modal ancho + editor SQL/JSON read-only ---------- */
.modal.modal-wide  { max-width: 1080px; width: calc(100% - 32px); }
.modal-subtitle    { font-size: .82rem; color: var(--muted); font-weight: 500; }

.json-editor {
  width: 100%;
  min-height: 360px;
  max-height: 60vh;
  resize: vertical;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: .82rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  white-space: pre;
  overflow: auto;
}

/* Historial de mensajes de una conversación (pestaña "Mensajes"). */
.chat-log       { display: flex; flex-direction: column; gap: 10px;
                  max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.chat-msg       { border-radius: var(--radius); padding: 10px 12px;
                  background: color-mix(in srgb, var(--surface) 90%, #000);
                  max-width: 85%; }
.chat-msg-meta  { display: flex; justify-content: space-between; align-items: baseline;
                  gap: 10px; font-size: .72rem; color: var(--muted);
                  margin-bottom: 4px; }
.chat-msg-role  { text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.chat-msg-fecha { font-family: monospace; }
.chat-msg-body  { font-size: .9rem; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }

.chat-msg-user      { align-self: flex-end;
                      background: color-mix(in srgb, var(--primary) 12%, var(--surface)); }
.chat-msg-user .chat-msg-role { color: var(--primary); }

.chat-msg-assistant { align-self: flex-start; }
.chat-msg-assistant .chat-msg-role { color: var(--success); }

.chat-msg-tool      { align-self: flex-start;
                      background: color-mix(in srgb, var(--warn) 15%, var(--surface));
                      font-family: monospace; font-size: .82rem; max-width: 95%; }
.chat-msg-tool .chat-msg-role { color: var(--warn); }

.chat-msg-system    { align-self: center; max-width: 95%;
                      background: color-mix(in srgb, var(--info) 12%, var(--surface));
                      font-style: italic; }
.chat-msg-system .chat-msg-role { color: var(--info); }

/* ---------- Sincronizador de tablas: log estilo terminal ----------
   Verde por defecto, rojo para advertencias/errores. Salida en tiempo
   real via SSE. Altura fija con scroll interno para que el modal no
   crezca mas alla del viewport.
*/
.terminal-log             { background: #0d0d0d; color: #86efac;
                            border: 1px solid var(--border);
                            border-radius: var(--radius);
                            padding: 12px 14px; margin: 0;
                            font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
                            font-size: .82rem; line-height: 1.55;
                            height: 320px; overflow-y: auto;
                            white-space: pre-wrap; word-break: break-word;
                            box-shadow: var(--shadow); }
.terminal-log .term-info    { color: #86efac; display: block; }
.terminal-log .term-success { color: #4ade80; display: block; font-weight: 600; }
.terminal-log .term-warn    { color: #f5a8a8; display: block; }
.terminal-log .term-error   { color: #f87171; display: block; font-weight: 600; }
