:root {
  --bg: #f4f1eb;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #8b7355;
  --accent-dark: #6b5740;
  --border: #e7e0d4;
  --ok: #15803d;
  --err: #b91c1c;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(28, 25, 23, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Login */
.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(145deg, #ebe6dc 0%, #f8f6f2 50%, #e8dfd0 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  display: inline-flex;
  width: 56px;
  height: 56px;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 14px;
  font-size: 1.1rem;
  margin-bottom: 12px;
}
.brand-mark.sm { width: 40px; height: 40px; font-size: 0.85rem; border-radius: 10px; }
.brand h1 { margin: 0; font-size: 1.5rem; }
.brand-sub { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fafaf9;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: #f5f5f4; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: #f5f3ef; border-color: var(--border); }
.btn-secondary:hover { background: #ebe6dc; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-danger { color: var(--err); border-color: #fecaca; }

.msg { margin-top: 16px; padding: 10px; border-radius: 8px; font-size: 0.9rem; }
.msg-ok { background: #dcfce7; color: var(--ok); }
.msg-err { background: #fee2e2; color: var(--err); }

/* Home */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.topbar-brand strong { display: block; }
.topbar-brand small { color: var(--muted); font-size: 0.8rem; }

.topbar-title {
  flex: 1;
  min-width: 0;
  margin: 0 12px;
}

.topbar-title strong {
  display: block;
  font-size: 1.05rem;
}

.topbar-title small {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.main-grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 24px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.panel h2 { margin: 0; font-size: 1.15rem; }

.ticket-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.ticket-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: #fafaf9;
}
.ticket-card-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ticket-num { font-weight: 700; color: var(--accent); }
.ticket-total { font-weight: 700; font-size: 1.1rem; }
.ticket-client { margin: 0 0 4px; font-weight: 600; }
.ticket-meta { margin: 0 0 12px; font-size: 0.85rem; color: var(--muted); }
.ticket-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.menu-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 16px;
  background: linear-gradient(135deg, #faf8f5, #f0ebe3);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s;
}
.menu-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.negocio-switch {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.negocio-switch .input { max-width: 220px; }

/* Payment */
.payment-summary,
.summary-strip.payment-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  max-width: 900px;
  margin: 0 auto 24px;
  padding: 0 24px;
}
.summary-item {
  background: var(--surface);
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.summary-item span { display: block; font-size: 0.8rem; color: var(--muted); }
.summary-item strong { font-size: 1.1rem; }

.payment-grid {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 24px 48px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.pay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.pay-card h3 { margin: 0 0 12px; font-size: 1rem; color: var(--accent); }
.pay-card .hint { font-size: 0.85rem; color: var(--muted); margin: 0 0 10px; }
.pay-card-discount { grid-column: 1 / -1; max-width: 320px; }
.pay-actions { grid-column: 1 / -1; }

/* —— Formularios (mismo lenguaje que home / cobrar) —— */
.page-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.page-shell-narrow { max-width: 480px; }
.page-shell-wide { max-width: 1000px; }
.page-shell-full { max-width: 1200px; }

.page-shell .payment-grid {
  padding: 0;
  margin: 0;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -4px 0 12px;
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.form-card-compact { padding: 14px 18px; }

.form-card-title {
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-dark);
}

.form-meta {
  margin: 10px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-grid-2 { grid-template-columns: 1fr 1fr; }
.field-grid-3 { grid-template-columns: repeat(3, 1fr); }

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label,
.form-card .label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.add-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(0, 2fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.add-row-grow { min-width: 0; }
.add-row-action { padding-bottom: 1px; }
.add-row-action .btn { white-space: nowrap; }

.form-footer,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding-top: 16px;
}

.form-actions-end { justify-content: flex-end; }
.form-actions-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

.info-banner {
  background: #faf8f5;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.info-banner strong { color: var(--accent-dark); }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  max-width: 900px;
  margin: 0 auto 20px;
  padding: 0 16px;
}

.client-search-wrap { position: relative; }

.search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
}

.search-results li {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: #f5f3ef; }
.search-results li.is-empty { cursor: default; color: var(--muted); }

.client-selected {
  margin: 12px 0;
  padding: 10px 14px;
  background: #dcfce7;
  border-radius: 8px;
  font-weight: 600;
  color: var(--ok);
  font-size: 0.92rem;
}

.lines-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 8px;
  background: #fafaf9;
}

.lines-empty {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
}

.line-item {
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px 12px;
  align-items: center;
}

.line-item:last-child { margin-bottom: 0; }
.line-item.line-combo { grid-template-columns: 1fr; gap: 10px; }

.line-sub {
  margin: 0;
  padding: 10px 12px 10px 14px;
  background: #f5f3ef;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px 10px;
  align-items: center;
  font-size: 0.92rem;
}

.line-label { font-weight: 600; font-size: 0.95rem; word-break: break-word; }

.line-item .input-sm,
.line-sub .input-sm {
  width: 88px;
  max-width: 100%;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.color-cell {
  background: #fafaf9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.color-cell-num {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.alert-migracion {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
}

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

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 { margin: 0; font-size: 1.1rem; color: var(--accent-dark); }

.modal-body { padding: 20px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.modal-close { font-size: 1.5rem; line-height: 1; padding: 4px 10px; }

.page-payment .topbar h1 {
  flex: 1;
  margin: 0 12px;
  font-size: 1.05rem;
}

@media (max-width: 640px) {
  .main-grid { padding: 16px; }
  .payment-summary,
  .summary-strip { padding: 0 12px; }
  .payment-grid { padding: 0 12px 32px; }
  .page-shell { padding: 12px 12px 32px; }
  .field-grid-2,
  .field-grid-3,
  .color-grid { grid-template-columns: 1fr; }
  .add-row { grid-template-columns: 1fr; }
  .add-row-action .btn { width: 100%; }
  .line-item,
  .line-sub { grid-template-columns: 1fr; }
  .form-footer,
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-footer .btn,
  .form-actions .btn { width: 100%; }
}
