:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2ff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #dbe3f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-width: 260px;
  --header-height: 64px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #1f2937;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: Inter, Segoe UI, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  width: 100%;
}

.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.sidebar-logo, .auth-logo, .ticket-logo {
  width: 42px;
  height: 42px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.sidebar-link {
  padding: .75rem 1rem;
  border-radius: 10px;
  color: var(--text-muted);
  transition: .2s ease;
}

.sidebar-link:hover,
.sidebar-link.is-active {
  background: var(--surface-2);
  color: var(--text);
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-spacer { flex: 1; }

.header-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  font-weight: 700;
}

.header-logo {
  width: 36px;
  height: 36px;
}

.header-title {
  white-space: nowrap;
}

.header-user {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.header-username {
  font-weight: 600;
}

.app-content {
  padding: 1.25rem;
  width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: .65rem 1rem;
  cursor: pointer;
  background: var(--surface-2);
  transition: .2s ease;
}

.btn:hover { filter: brightness(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-sm { padding: .4rem .7rem; font-size: .875rem; }
.btn-block { width: 100%; }
.btn-module {
  font-weight: 600;
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.btn-module:hover {
  filter: brightness(1.08);
  color: #fff;
}

.btn-module-fee_payment,
.btn-module-action.btn-module-fee_payment,
[data-module="fee_payment"] .modal-header-module {
  background: #2563eb;
}

.btn-module-account_deposit,
.btn-module-action.btn-module-account_deposit,
[data-module="account_deposit"] .modal-header-module {
  background: #16a34a;
}

.btn-module-dni_transfer,
.btn-module-action.btn-module-dni_transfer,
[data-module="dni_transfer"] .modal-header-module {
  background: #7c3aed;
}

.btn-module-service_payment,
.btn-module-action.btn-module-service_payment,
[data-module="service_payment"] .modal-header-module {
  background: #ea580c;
}

.btn-module-recharge,
.btn-module-action.btn-module-recharge,
[data-module="recharge"] .modal-header-module {
  background: #0891b2;
}

.btn-module-withdrawal,
.btn-module-action.btn-module-withdrawal,
[data-module="withdrawal"] .modal-header-module {
  background: #e11d48;
}

.btn-module-action {
  color: #fff;
  border: none;
  font-weight: 600;
}

.btn-module-action:hover {
  filter: brightness(1.08);
  color: #fff;
}

.modal-header-module {
  color: #fff;
  border-bottom: none;
}

.modal-header-module h3 {
  color: #fff;
}

.modal-close-light {
  color: #fff;
  opacity: 0.9;
}

.modal-close-light:hover {
  opacity: 1;
}

[data-module] .modal-header-module {
  border-radius: var(--radius) var(--radius) 0 0;
}

.table-wrap {
  overflow: auto;
  width: 100%;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.data-table th,
.data-table td {
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: var(--surface-2);
}

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-confirmed { background: #dcfce7; color: #166534; }
.badge-warning { background: #ffedd5; color: #9a3412; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }

[data-theme="dark"] .badge-pending { background: #78350f; color: #fef3c7; }
[data-theme="dark"] .badge-confirmed { background: #14532d; color: #dcfce7; }
[data-theme="dark"] .badge-warning { background: #7c2d12; color: #ffedd5; }
[data-theme="dark"] .badge-cancelled { background: #7f1d1d; color: #fee2e2; }

.row-urgent { background: rgba(220, 38, 38, 0.06); }

.alert {
  padding: .85rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }

.filters-bar {
  margin-bottom: 1rem;
}

.filters-form {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: end;
}

.filters-form label,
.modal-body label,
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .9rem;
  font-weight: 600;
}

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem .75rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .85rem;
  margin-bottom: .85rem;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: .5rem !important;
  font-weight: 500 !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.stat-label {
  color: var(--text-muted);
  font-size: .85rem;
}

.stat-value {
  display: block;
  font-size: 1.4rem;
  margin-top: .35rem;
}

.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-dialog {
  position: relative;
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.modal-sm { width: min(480px, 100%); }

.modal-lg {
  width: min(920px, 100%);
}

.modal-compact {
  width: min(720px, 100%);
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.modal-body-compact {
  padding: 0.5rem 0.75rem 0.4rem;
  gap: 0.25rem;
}

.modal-body-compact .form-section {
  margin: 0;
  padding: 0;
  border: none;
}

.modal-body-compact label {
  gap: 0.1rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
}

.modal-body-compact input,
.modal-body-compact select,
.modal-body-compact textarea {
  padding: 5px;
  font-size: 0.8125rem;
  border-radius: 6px;
  min-height: 30px;
}

.modal-body-compact .search-select-input {
  padding: 5px;
  min-height: 30px;
}

.modal-body-compact .search-select-toggle {
  min-height: 30px;
}

.modal-body-compact .form-grid-compact {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.35rem 0.5rem;
  margin: 0;
}

.modal-body-compact .form-grid-dni-name {
  display: grid;
  grid-template-columns: 20% 1fr;
  gap: 0.35rem 0.5rem;
  margin: 0;
  align-items: start;
}

.modal-body-compact .form-grid-amounts-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem 0.5rem;
  margin: 0 0 0.35rem;
}

.modal-body-compact .form-grid-change-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.5rem;
  margin: 0;
}

.modal-body-compact .form-grid-obs-urgent {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.75rem;
  margin: 0;
  align-items: end;
}

.modal-body-compact .checkbox-urgent {
  white-space: nowrap;
  padding-bottom: 5px;
}

.modal-body-compact textarea {
  min-height: 30px;
  resize: vertical;
}

@media (max-width: 520px) {
  .modal-body-compact .form-grid-dni-name {
    grid-template-columns: 1fr;
  }

  .modal-body-compact .form-grid-amounts-row {
    grid-template-columns: 1fr;
  }

  .modal-body-compact .form-grid-obs-urgent {
    grid-template-columns: 1fr;
  }
}

.modal-body-compact .checkbox-compact {
  margin: 0;
  padding: 0.15rem 0;
  font-size: 0.78rem !important;
}

.modal-footer-compact {
  padding: 0.4rem 0 0.15rem;
  margin-top: 0.15rem;
  border-top: 1px solid var(--border);
  gap: 0.5rem;
}

.modal-compact .modal-header {
  padding: 0.45rem 0.75rem;
}

.modal-compact .modal-close {
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
}

.form-section {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
  border-bottom: none;
}

.form-section-title {
  margin: 0 0 .75rem;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}

.form-section[hidden] {
  display: none !important;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.change-label .change-field {
  font-weight: 700;
  color: var(--success);
}

.theme-toggle,
.nav-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 42px;
  height: 42px;
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.theme-toggle-auth {
  position: fixed;
  top: 1rem;
  right: 1rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-brand h1 {
  margin: .5rem 0 .25rem;
}

.auth-brand p {
  margin: 0;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ticket-body-page {
  background: #fff;
  color: #000;
}

.ticket-wrap {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.ticket {
  width: 80mm;
  max-width: 100%;
  font-family: monospace;
  font-size: 12px;
  border: 1px dashed #999;
  padding: 10px;
}

.ticket-header,
.ticket-footer {
  text-align: center;
}

.ticket-header h1 {
  font-size: 14px;
  margin: .25rem 0;
}

.ticket-body p {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin: .25rem 0;
}

.ticket-total {
  font-size: 14px;
  font-weight: 700;
}

.ticket-urgent {
  justify-content: center !important;
  font-weight: 700;
}

.ticket-actions {
  display: flex;
  gap: .5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: var(--sidebar-width);
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay.is-visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 25;
  }

  .nav-toggle { display: inline-flex; }
}

@media print {
  body * { visibility: hidden; }
  #ticketPrint, #ticketPrint * { visibility: visible; }
  #ticketPrint {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  .no-print { display: none !important; }
}

@media (min-width: 961px) {
  .nav-toggle { display: none; }
}

/* Select con buscador */
.search-select {
  position: relative;
  width: 100%;
}

.search-select-control {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.search-select-input {
  flex: 1;
  min-width: 0;
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.search-select-toggle {
  flex-shrink: 0;
  width: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-select.is-open .search-select-toggle {
  background: var(--bg);
}

.search-select-list {
  position: absolute;
  z-index: 120;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 180px;
  overflow-y: auto;
  margin: 0;
  padding: 0.2rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.search-select-option {
  padding: 0.35rem 0.55rem;
  font-size: 0.8125rem;
  cursor: pointer;
}

.search-select-option.is-placeholder {
  color: var(--text-muted);
}

.search-select-option:hover,
.search-select-option.is-active {
  background: var(--surface-2);
}

.search-select-option.is-selected {
  background: var(--primary);
  color: #fff;
}

.search-select-option[hidden] {
  display: none;
}

.dni-lookup-status {
  display: block;
  min-height: 0.95rem;
  font-size: 0.68rem;
  font-weight: 500;
  margin-top: 0.1rem;
  color: var(--text-muted);
}

.dni-lookup-status.is-loading {
  color: var(--primary);
}

.dni-lookup-status.is-success {
  color: var(--success);
}

.role-menus-box {
  margin-top: 0.35rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.role-menus-title {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 0.35rem;
}

.role-menus-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.25rem;
  max-height: 200px;
  overflow-y: auto;
}

.text-muted {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.68rem;
}
