:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #6d7785;
  --primary: #2962ff;
  --primary-2: #1e4fd6;
  --success: #1f9d55;
  --warning: #d9822b;
  --danger: #d64545;
  --info: #0f8ec7;
  --border: #dde5f0;
  --shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

aside {
  background: linear-gradient(180deg, #132238, #0f1a2b);
  color: #fff;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 18px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #55a3ff, #2962ff);
  display: grid;
  place-items: center;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(41,98,255,.35);
}

.brand h1 {
  font-size: 18px;
  margin: 0;
}

.brand p {
  margin: 3px 0 0;
  font-size: 12px;
  color: rgba(255,255,255,.7);
}

nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-btn {
  all: unset;
  cursor: pointer;
  padding: 12px 14px;
  border-radius: 14px;
  color: rgba(255,255,255,.85);
  font-size: 14px;
  transition: .2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}

main {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button, input, select, textarea {
  font: inherit;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 11px 16px;
  cursor: pointer;
  transition: .2s ease;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-2); }
.btn-soft { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.metric .label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric .value {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.metric .mini {
  font-size: 12px;
  color: var(--muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title h3 {
  margin: 0;
  font-size: 18px;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chart-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 50px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-track {
  height: 12px;
  background: #edf2fa;
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #5c8dff, #2962ff);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbfcff;
}

.list-item strong { display: block; }
.list-item small { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-confirmada { background: rgba(31,157,85,.14); color: var(--success); }
.status-pendiente { background: rgba(217,130,43,.14); color: var(--warning); }
.status-cancelada { background: rgba(214,69,69,.14); color: var(--danger); }
.status-finalizada { background: rgba(15,142,199,.14); color: var(--info); }
.status-en-uso { background: rgba(41,98,255,.14); color: var(--primary); }

.table-wrap {
  overflow: auto;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th, td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

th {
  background: #f7f9fe;
  color: #3c4656;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:hover td { background: #fafcff; }

.panel { display: none; }
.panel.active { display: block; }

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar-filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.search {
  width: 320px;
  max-width: 100%;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 14px;
}

.search.search-date {
  width: 170px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field.full { grid-column: 1 / -1; }

.field label {
  font-size: 13px;
  font-weight: 600;
  color: #314155;
}

.field input,
.field select,
.field textarea {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.client-picker {
  position: relative;
}

.picker-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: none;
  max-height: 240px;
  overflow: auto;
  z-index: 80;
}

.picker-results.active {
  display: block;
}

.picker-option {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid #eef3fa;
  cursor: pointer;
}

.picker-option:last-child {
  border-bottom: none;
}

.picker-option:hover {
  background: #f5f8ff;
}

.picker-option strong {
  display: block;
  margin-bottom: 2px;
}

.picker-option small {
  color: var(--muted);
}

.picker-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.actions-row {
  display: flex !important;
  flex-direction: row !important;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(9, 17, 29, .55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal.active { display: flex; }

.modal-card {
  width: min(860px, 100%);
  background: white;
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.18);
  padding: 22px;
  max-height: 92vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  margin-bottom: 18px;
}

.modal-header h3 {
  margin: 0;
  font-size: 22px;
}

.muted { color: var(--muted); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.day-name,
.day-cell {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 95px;
  padding: 10px;
}

.day-name {
  min-height: auto;
  font-weight: 700;
  text-align: center;
  background: #f7f9fe;
}

.day-cell.empty {
  background: transparent;
  border-style: dashed;
}

.day-number {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #425068;
}

.day-booking {
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: rgba(41,98,255,.12);
  color: var(--primary);
  font-weight: 700;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.money-positive { color: var(--success); font-weight: 700; }
.money-warning { color: var(--warning); font-weight: 700; }

.empty-state {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: white;
  border: 1px dashed var(--border);
  border-radius: 18px;
}

.access-note {
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}

.access-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(41, 98, 255, 0.24), transparent 38%),
    radial-gradient(circle at 85% 82%, rgba(41, 98, 255, 0.16), transparent 34%),
    rgba(9, 17, 29, 0.78);
}

.access-overlay.hidden {
  display: none;
}

.access-modal {
  width: min(520px, 100%);
  background: linear-gradient(180deg, #ffffff 0%, #f7f9ff 100%);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.38);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.access-modal h3 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -.02em;
}

.access-modal .actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.access-modal button.primary,
.access-modal button.secondary {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.access-modal button.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, #4a7bff 100%);
  box-shadow: 0 10px 22px rgba(41, 98, 255, .34);
}

.access-modal button.primary:hover {
  background: linear-gradient(135deg, var(--primary-2) 0%, #3f6ff0 100%);
  transform: translateY(-1px);
}

.access-modal button.secondary {
  color: var(--text);
  background: #e8edf6;
  border: 1px solid #d4ddeb;
}

.access-modal button.secondary:hover {
  background: #dbe4f2;
  transform: translateY(-1px);
}

.access-status-info {
  color: var(--muted);
}

.access-status-success {
  color: var(--success);
}

.access-status-error {
  color: var(--danger);
}

#backendAccessOverlay .access-modal {
  width: min(560px, 100%);
  padding: 26px;
  border: 1px solid #d7e2f6;
}

#backendAccessOverlay .access-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 2px;
}

#backendAccessOverlay .access-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #17438d 0%, #2962ff 100%);
  box-shadow: 0 14px 26px rgba(15, 53, 122, .36);
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .25);
}

#backendAccessOverlay .access-icon-wrap img {
  width: 34px;
  height: 34px;
  display: block;
}

#backendAccessOverlay .access-note {
  color: #52627b;
}

#backendAccessOverlay #backendAuthForm {
  display: grid;
  gap: 12px;
}

#backendAccessOverlay #backendAuthForm label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: #4c5d78;
  margin-bottom: 6px;
}

#backendAccessOverlay #backendAuthForm input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #ccd8ec;
  background: #fbfcff;
  color: #132238;
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

#backendAccessOverlay #backendAuthForm input:focus {
  border-color: #3f74ff;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(63, 116, 255, .14);
}

#backendAccessOverlay #backendAccessStatus {
  min-height: 20px;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .grid-cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .split { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  aside {
    position: static;
    height: auto;
  }
  .form-grid { grid-template-columns: 1fr; }
  .grid-cards { grid-template-columns: 1fr; }
  main { padding: 18px; }
  #backendAccessOverlay .access-head { grid-template-columns: 1fr; }
  #backendAccessOverlay .access-icon-wrap {
    width: 52px;
    height: 52px;
  }
}
