/* ============================================
   FacturaSRI Ecuador - Admin Panel Styles
   ============================================ */

:root {
  --bg: #f0f4f8;
  --sidebar-bg: #0f1f2e;
  --sidebar-hover: #1a3145;
  --sidebar-active: #0e6655;
  --accent: #0d9488;
  --accent-dark: #0a7a6e;
  --ink: #1a2e45;
  --ink-light: #64748b;
  --card: #ffffff;
  --border: #e2e8f0;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #3b82f6;
  --sidebar-width: 250px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ============ LAYOUT ============ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-icon {
  font-size: 24px;
  background: var(--accent);
  border-radius: 8px;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand span:last-child {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: 0.3px;
}

.nav-list {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s;
  font-size: 13.5px;
  color: #94a3b8;
}

.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active); color: #ffffff; font-weight: 600; }

.nav-icon { width: 20px; text-align: center; font-size: 15px; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin-bottom: 8px;
}

.user-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 14px;
  flex-shrink: 0;
}

.user-email { font-size: 12px; color: #e2e8f0; font-weight: 500; word-break: break-all; }
.user-role {
  font-size: 11px; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.5px;
}

.btn-logout {
  width: 100%; padding: 8px; border-radius: 6px;
  background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.25);
  color: #fca5a5; cursor: pointer; font-size: 13px;
  transition: background 0.15s;
}
.btn-logout:hover { background: rgba(239,68,68,0.2); }

/* ============ MAIN CONTENT ============ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  background: var(--bg);
}

.main-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 18px 32px 0;
}

.flow-mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.flow-mode-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-light);
}

.flow-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.flow-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.flow-switch-text {
  font-size: 13px;
  color: var(--ink-light);
  font-weight: 600;
}

.flow-switch-text.active {
  color: var(--ink);
}

.flow-switch-slider {
  width: 46px;
  height: 24px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: background 0.2s ease;
}

.flow-switch-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  transition: transform 0.2s ease;
}

.flow-switch input:checked + .flow-switch-slider {
  background: var(--accent);
}

.flow-switch input:checked + .flow-switch-slider::after {
  transform: translateX(22px);
}

.view-container {
  padding: 28px 32px;
  max-width: 1200px;
}

/* ============ VIEW HEADER ============ */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.view-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}

.view-sub {
  font-size: 13px;
  color: var(--ink-light);
  margin-left: 10px;
}

/* ============ CARDS ============ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 600; }

.mt2 { margin-top: 16px; }
.mt1 { margin-top: 10px; }

/* ============ STATS GRID ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}

.stat-icon { font-size: 28px; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--ink-light); margin-top: 3px; }

.stat-blue .stat-icon  { background: #eff6ff; padding: 8px; border-radius: 8px; }
.stat-green .stat-icon { background: #f0fdf4; padding: 8px; border-radius: 8px; }
.stat-teal .stat-icon  { background: #f0fdfa; padding: 8px; border-radius: 8px; }
.stat-purple .stat-icon{ background: #faf5ff; padding: 8px; border-radius: 8px; }

/* ============ STATUS BAR ============ */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 0 4px;
}
.status-item { display: flex; align-items: center; gap: 8px; }
.status-count { font-weight: 700; font-size: 15px; }

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table thead th {
  text-align: left;
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--ink-light);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s;
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.table td {
  padding: 10px 12px;
  vertical-align: middle;
}
.table td small { color: var(--ink-light); font-size: 12px; display: block; }

.actions { display: flex; gap: 6px; align-items: center; }

/* ============ BADGES ============ */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge-teal   { background: #d1fae5; color: #065f46; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-green  { background: #dcfce7; color: #14532d; }

.tag {
  background: #f0f9ff; color: #0369a1;
  border: 1px solid #bae6fd; border-radius: 4px;
  padding: 1px 7px; font-size: 12px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent); color: white; border-color: var(--accent-dark);
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: white; color: var(--ink);
  border-color: var(--border); box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-full { width: 100%; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--ink-light); padding: 4px; border-radius: 4px; }
.btn-icon:hover { background: #f1f5f9; }

.align-end { align-self: flex-end; margin-bottom: 0; }

/* ============ FORMS ============ */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--ink); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.input {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); font-size: 13.5px;
  background: white; color: var(--ink); outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13,148,136,0.12); }
.input[type="file"] { padding: 7px; }
select.input { appearance: auto; }

.flex2 { flex: 2; }
.flex1 { flex: 1; }

.item-row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid #f0f4f8;
}
.item-row:first-child { padding-top: 0; }

/* ============ MODAL ============ */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,31,46,0.5);
  z-index: 200;
  backdrop-filter: blur(2px);
}

#modal-container {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 210;
  width: 100%;
  max-width: 520px;
  padding: 16px;
}

.modal {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-body {
  padding: 20px;
  max-height: 70vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

.hidden { display: none !important; }

/* ============ TOASTS ============ */
#toasts {
  position: fixed; top: 20px; right: 20px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 320px;
}

.toast {
  padding: 12px 16px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: 0 4px 15px rgba(0,0,0,0.12);
  animation: toast-in 0.25s ease;
}
.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f1f2e 0%, #1a3a4e 50%, #0f2e2a 100%);
  padding: 28px;
}

.login-shell {
  width: 100%;
  max-width: 1120px;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(360px, 1fr);
  gap: 24px;
}

.login-card {
  background: white; border-radius: 20px;
  padding: 40px; width: 100%; max-width: 400px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.3);
  display: flex; flex-direction: column; gap: 16px;
}

.login-logo {
  font-size: 36px; text-align: center;
  background: var(--accent); border-radius: 14px;
  width: 62px; height: 62px; display: flex; align-items: center;
  justify-content: center; margin: 0 auto;
}
.login-card h2 { font-size: 22px; font-weight: 800; text-align: center; color: var(--ink); }
.login-sub { text-align: center; color: var(--ink-light); font-size: 13px; margin-top: -8px; }
.login-footer { text-align: center; color: var(--ink-light); font-size: 11.5px; margin-top: 4px; }

.login-info-card {
  background: rgba(255,255,255,0.96);
  border-radius: 18px;
  border: 1px solid rgba(226,232,240,0.9);
  box-shadow: 0 18px 40px rgba(8, 19, 35, 0.22);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-info-card h3 {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.demo-users-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.demo-user-btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  cursor: pointer;
}

.demo-user-btn:hover {
  border-color: var(--accent);
  background: #ecfeff;
}

.demo-user-btn strong {
  font-size: 12.5px;
}

.demo-user-btn span {
  font-size: 11.5px;
  color: var(--ink-light);
}

.login-features-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: #1e293b;
  font-size: 12.5px;
}

.login-features-list li {
  line-height: 1.45;
}

.error-msg { background: #fef2f2; color: var(--danger); border-radius: 8px; padding: 10px 12px; font-size: 13px; }

/* ============ MISC ============ */
.empty { color: var(--ink-light); font-size: 13.5px; padding: 24px; text-align: center; }
.loading { color: var(--ink-light); padding: 40px; text-align: center; font-size: 14px; }

code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; font-family: monospace; }

.info-box { background: #f0f9ff; border-color: #bae6fd; }
.info-box h4 { margin-bottom: 6px; font-size: 13.5px; color: #0369a1; }
.info-box p  { font-size: 13px; color: #0369a1; line-height: 1.6; }

.events-list { display: flex; flex-direction: column; gap: 10px; }
.event-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; background: #f8fafc; border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.event-type { font-weight: 600; font-size: 12.5px; flex: 1; }
.event-time { font-size: 11.5px; color: var(--ink-light); }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; }
  .main-toolbar { padding: 16px 16px 0; justify-content: stretch; }
  .flow-mode-card { width: 100%; justify-content: space-between; border-radius: 12px; }
  .view-container { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }

  .login-shell {
    grid-template-columns: 1fr;
    max-width: 520px;
  }

  .login-card {
    max-width: 100%;
  }

  .demo-users-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}


@media (max-width: 760px) {
  .grid {
    grid-template-columns: 1fr;
  }
}
