/* ============================================
   Facturador ARCA v2 — Design System
   Dark mode, modern, responsive
   ============================================ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #161822;
  --bg-card: #1c1e2e;
  --bg-card-hover: #232540;
  --bg-input: #0f1117;
  --border: #2a2d42;
  --border-focus: #6366f1;
  --text-primary: #e8eaed;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-bg: rgba(99,102,241,.12);
  --success: #22c55e;
  --success-bg: rgba(34,197,94,.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245,158,11,.12);
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,.12);
  --sidebar-w: 220px;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: .2s ease;
  --shadow: 0 2px 12px rgba(0,0,0,.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; font-family: var(--font); background: var(--bg-primary); color: var(--text-primary); }

body { display: flex; overflow: hidden; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* SIDEBAR */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 0;
  transition: transform var(--transition);
  z-index: 100;
}
.sidebar-brand { padding: 0 20px 24px; display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 24px; }
.brand-text { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.brand-text small { font-size: 10px; font-weight: 500; color: var(--accent); vertical-align: super; margin-left: 2px; }
.nav-links { list-style: none; flex: 1; }
.nav-links a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; color: var(--text-secondary);
  text-decoration: none; font-size: 14px; font-weight: 500;
  transition: all var(--transition); border-left: 3px solid transparent;
}
.nav-links a:hover { color: var(--text-primary); background: var(--bg-card); }
.nav-links a.active { color: var(--accent); background: var(--accent-bg); border-left-color: var(--accent); }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.env-badge {
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 4px;
  background: var(--success-bg); color: var(--success);
}
.env-badge.prod { background: var(--danger-bg); color: var(--danger); }
.api-link { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.api-link:hover { color: var(--accent); }

/* MAIN */
#main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* TOPBAR */
.topbar {
  height: 56px; min-height: 56px; display: flex; align-items: center;
  padding: 0 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary); gap: 16px;
}
.topbar h1 { font-size: 18px; font-weight: 600; flex: 1; }
.menu-btn { display: none; background: none; border: none; color: var(--text-primary); font-size: 20px; cursor: pointer; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.api-key-section { display: flex; align-items: center; gap: 4px; }
#api-key-input {
  width: 180px; padding: 6px 10px; font-size: 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  transition: border-color var(--transition);
}
#api-key-input:focus { border-color: var(--border-focus); outline: none; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; padding: 4px; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted);
  transition: background var(--transition);
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 8px rgba(34,197,94,.5); }
.status-dot.error { background: var(--danger); }

/* PAGE CONTAINER */
.page-container { flex: 1; overflow-y: auto; padding: 24px; }
.page { display: none; animation: fadeIn .25s ease; }
.page.active { display: block; }

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

/* STATS GRID */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; align-items: center; gap: 16px;
  transition: all var(--transition);
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { font-size: 28px; }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* PANELS */
.panel {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
.panel h3 { font-size: 14px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 16px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-header h3 { margin-bottom: 0; }
.dashboard-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* QUICK ACTIONS */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-btn {
  padding: 14px; border: 1px solid var(--border); background: var(--bg-primary);
  color: var(--text-primary); border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all var(--transition); text-align: left;
}
.action-btn:hover { border-color: var(--accent); background: var(--accent-bg); }

/* CARDS GRID */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.account-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; transition: all var(--transition); position: relative;
}
.account-card:hover { border-color: var(--accent); }
.account-card .card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.account-card .card-title { font-size: 16px; font-weight: 600; }
.account-card .card-env {
  font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 4px;
}
.card-env.homo { background: var(--success-bg); color: var(--success); }
.card-env.prod { background: var(--danger-bg); color: var(--danger); }
.account-card .card-cuit { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; font-family: monospace; }
.account-card .card-badges { display: flex; gap: 8px; margin-bottom: 14px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 4px; font-weight: 500; }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.pending { background: var(--warning-bg); color: var(--warning); }
.card-actions { display: flex; gap: 8px; }
.card-actions button { font-size: 12px; }

/* PAGE HEADER */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 22px; font-weight: 700; }

/* BUTTONS */
.btn {
  padding: 8px 16px; border: none; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer; font-family: var(--font);
  transition: all var(--transition); display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-primary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover:not(:disabled) { filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.full-w { width: 100%; justify-content: center; }

/* FORMS */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, select, textarea {
  width: 100%; padding: 9px 12px; font-size: 13px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font);
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus { border-color: var(--border-focus); outline: none; }
select { cursor: pointer; }

.separator { height: 1px; background: var(--border); margin: 18px 0; }

/* COLLAPSIBLE */
.collapse-toggle {
  background: none; border: none; color: var(--text-muted); font-size: 12px;
  cursor: pointer; padding: 0; font-family: var(--font);
}
.collapse-toggle:hover { color: var(--text-primary); }

/* FILE DROP */
.file-drop {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; cursor: pointer; position: relative;
  transition: all var(--transition);
}
.file-drop:hover, .file-drop.dragover { border-color: var(--accent); background: var(--accent-bg); }
.file-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-drop p { font-size: 13px; color: var(--text-muted); }

/* MODAL */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px); z-index: 200; justify-content: center; align-items: center;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 480px; max-height: 90vh; overflow-y: auto; padding: 24px;
  animation: modalIn .2s ease;
}
.modal-sm { width: 380px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
.modal-close:hover { color: var(--text-primary); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@keyframes modalIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* EMISSION LAYOUT */
.emission-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.queue-list { max-height: 300px; overflow-y: auto; }
.queue-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 6px; font-size: 13px; background: var(--bg-primary);
}
.queue-item .qi-id { font-weight: 600; }
.queue-item .qi-total { font-family: monospace; color: var(--accent); }
.queue-item .qi-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.queue-item .qi-remove:hover { color: var(--danger); }
.emission-actions { display: flex; gap: 8px; margin-top: 14px; }
.emission-actions .btn { flex: 1; justify-content: center; }
.empty-state { color: var(--text-muted); font-size: 13px; text-align: center; padding: 24px 0; }

/* RESULTS */
.result-item {
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 6px;
  font-size: 13px; display: flex; justify-content: space-between; align-items: center;
}
.result-item.approved { background: var(--success-bg); border-left: 3px solid var(--success); }
.result-item.rejected { background: var(--danger-bg); border-left: 3px solid var(--danger); }
.result-item .ri-cae { font-family: monospace; font-size: 11px; color: var(--text-secondary); }

/* TABLE */
.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 10px 12px; font-weight: 600; font-size: 11px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--bg-card-hover); }
.data-table .num { text-align: right; font-family: monospace; }
.meta-info { margin-top: 12px; font-size: 12px; color: var(--text-muted); }

/* LOADING */
.loading-state {
  text-align: center; padding: 40px; color: var(--text-muted); font-size: 14px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 50% { opacity: .5; } }

/* ETL */
.etl-layout { display: grid; grid-template-columns: 380px 1fr; gap: 16px; }

/* TOAST */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px;
  max-width: 360px; animation: slideIn .3s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast.success { background: #166534; color: #bbf7d0; }
.toast.error { background: #991b1b; color: #fecaca; }
.toast.info { background: #1e3a5f; color: #bfdbfe; }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }

/* ACCOUNTS PREVIEW (dashboard) */
.accounts-preview .ap-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.accounts-preview .ap-item:last-child { border-bottom: none; }

/* RESPONSIVE */
@media (max-width: 1024px) {
  .emission-layout, .etl-layout, .dashboard-panels { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  #api-key-input { width: 120px; }
}
