:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-2: #121821;
  --bg-3: #1a222d;
  --ink: #e8eef5;
  --muted: #8b9aab;
  --line: #2a3442;
  --accent: #3dd68c;
  --accent-ink: #04150c;
  --danger: #ff6b7a;
  --warning: #f0c14a;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI", "Candara", "Gill Sans", sans-serif;
  --pad: clamp(0.75rem, 1.5vw, 1.25rem);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(61, 214, 140, 0.08), transparent 55%),
    radial-gradient(800px 380px at 100% 0%, rgba(80, 140, 220, 0.07), transparent 50%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem var(--pad);
  background: rgba(18, 24, 33, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar nav a {
  color: var(--muted);
}

.topbar nav a.active {
  font-weight: 700;
  color: var(--ink);
}

.logout-form { margin: 0; }
.logout-form button,
button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.55rem 1rem;
  font-weight: 600;
}

.logout-form button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 500;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 107, 122, 0.35);
  font-weight: 500;
}

.btn-confirm {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-facturar {
  background: #3b82f6;
  color: #fff;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  white-space: nowrap;
}

.btn-facturar:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
}

.btn-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
  pointer-events: none;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-pendiente {
  background: rgba(240, 193, 74, 0.18);
  color: var(--warning);
}

.badge-confirmado {
  background: rgba(61, 214, 140, 0.16);
  color: var(--accent);
}

.badge-situacion {
  text-transform: none;
}

.wrap,
.wrap.wide {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: var(--pad);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page-head h1 {
  margin: 0.15rem 0;
  font-size: clamp(1.45rem, 2.4vw, 1.9rem);
  letter-spacing: -0.03em;
}

.muted, .hint, .cliente-meta { color: var(--muted); }
.hint { font-size: 0.9rem; margin-top: 0.75rem; }
.back { display: inline-block; margin-bottom: 0.35rem; color: var(--muted); }

.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem var(--pad) 1.15rem;
  margin-top: 0.85rem;
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1.02rem;
  color: var(--ink);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}

.form-pago {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 { grid-column: span 2; }
.form-pago .span-2 { grid-column: 1 / -1; }

.check-line {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
}
.check-line input {
  width: 1rem;
  height: 1rem;
  padding: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: var(--muted);
}

input, select {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: var(--bg-3);
}

input:focus, select:focus {
  outline: 2px solid rgba(61, 214, 140, 0.35);
  border-color: var(--accent);
}

.actions { display: flex; gap: 0.5rem; align-items: end; }

.table-scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-3);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}

th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:hover {
  background: rgba(61, 214, 140, 0.04);
}

td.num, th.num { text-align: right; }

.matrix input {
  width: 7.5rem;
  padding: 0.35rem 0.45rem;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions-menu {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}

.actions-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  min-width: 11.5rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.actions-dropdown[hidden] {
  display: none !important;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.menu-item svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.menu-item:hover {
  background: rgba(61, 214, 140, 0.1);
}

.menu-item-danger {
  color: var(--danger);
}

.menu-item-danger:hover {
  background: rgba(255, 107, 122, 0.12);
}

.menu-item-static {
  cursor: default;
  color: var(--muted);
}

.menu-item-static:hover {
  background: transparent;
}

.msg {
  margin: 0.75rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: rgba(61, 214, 140, 0.12);
  color: var(--accent);
}

.msg.error {
  background: rgba(255, 107, 122, 0.12);
  color: var(--danger);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(400px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.login-card h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.login-card .error {
  margin: 0;
  color: var(--danger);
  background: rgba(255, 107, 122, 0.12);
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
}

.page-head-row {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.btn-linkish {
  padding: 0.35rem 0.7rem;
  display: inline-block;
  border-radius: 8px;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
}

body.modal-open {
  overflow: hidden;
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-dialog {
  position: relative;
  width: min(640px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.2rem 1.25rem;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-close {
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.2rem 0.55rem;
}

.modal-actions {
  justify-content: flex-end;
}

@media (max-width: 900px) {
  .form-pago, .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2, .form-pago .span-2 { grid-column: auto; }
}
