:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  text-align: center;
}
.login-logo { font-size: 48px; }
.login-card h1 { font-size: 22px; margin: 10px 0 4px; }
.login-sub { color: var(--muted); margin-bottom: 24px; }
.login-card label { display: block; text-align: left; margin-bottom: 14px; font-weight: 600; color: var(--text); }
.login-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- Layout ---------- */
.app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: #0f172a; color: #e2e8f0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { padding: 20px 18px; font-size: 18px; font-weight: 700; border-bottom: 1px solid #1e293b; }
#nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: none; color: #cbd5e1; text-align: left;
  padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; margin-bottom: 2px;
}
.nav-item:hover { background: #1e293b; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 16px; border-top: 1px solid #1e293b; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer span { color: #94a3b8; font-size: 13px; }

.main { flex: 1; padding: 24px; min-width: 0; }
.view { max-width: 1100px; margin: 0 auto; }

/* ---------- Common ---------- */
h1.view-title { font-size: 22px; margin-bottom: 4px; }
p.view-sub { color: var(--muted); margin-bottom: 18px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h3 { margin-bottom: 12px; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px;
  border: 1px solid transparent; border-radius: 8px; font-size: 14px; cursor: pointer;
  font-weight: 600; background: #e2e8f0; color: var(--text);
}
.btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.toolbar .spacer { flex: 1; }

input, select, textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
label.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: 13px; }
label.field input, label.field select, label.field textarea { display: block; width: 100%; margin-top: 5px; font-weight: 400; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: #e2e8f0; color: #475569; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 12px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-card .sub { font-size: 12px; color: var(--success); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* Estado ordenes */
.estado-pendiente_recoleccion { background: #fef3c7; color: #b45309; }
.estado-recolectado { background: #ede9fe; color: #6d28d9; }
.estado-en_proceso { background: #dbeafe; color: #1d4ed8; }
.estado-listo { background: #d1fae5; color: #047857; }
.estado-en_entrega { background: #cffafe; color: #0e7490; }
.estado-entregado { background: #dcfce7; color: #15803d; }
.estado-cancelado { background: #fee2e2; color: #b91c1c; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 24px; }
.modal.wide { max-width: 760px; }
.modal h2 { margin-bottom: 16px; font-size: 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Toast */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: 10px; color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: slidein .25s ease; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* Prendas list */
.prenda-line { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.prenda-line input, .prenda-line select { padding: 8px; }
.prenda-line .q { width: 70px; }
.prenda-line .price { width: 90px; }

/* Impresión */
.ip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 16px; }
.ip-col { display: flex; flex-direction: column; gap: 14px; }
.ip-plantilla { display: block; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); cursor: pointer; }
.ip-plantilla.active { border-color: var(--primary); background: var(--primary-soft); }
.ticket-wrap { background: #f3f3f3; border-radius: 10px; padding: 14px; display: flex; justify-content: center; }
.ticket { width: 300px; max-width: 100%; background: #fff; color: #000; font-family: "Courier New", monospace; font-size: 11px; line-height: 1.45; padding: 14px 10px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.t-line { white-space: nowrap; overflow: hidden; }
.t-line.center { text-align: center; }
.t-line.row { display: flex; justify-content: space-between; gap: 6px; }
.t-line.row span:first-child { text-align: left; }
.t-line.row span:last-child { text-align: right; white-space: nowrap; }
.t-sep { white-space: nowrap; overflow: hidden; color: #000; }
.t-logo { text-align: center; margin-bottom: 6px; }
.t-logo img { max-width: 100%; height: auto; }
.t-title { font-weight: bold; }
.t-sub { color: #333; }
.t-line.total { font-weight: bold; border-top: 1px dashed #000; margin-top: 2px; padding-top: 2px; }

@media (max-width: 640px) {
  .sidebar { width: 70px; }
  .sidebar-brand, .nav-item span, .sidebar-footer span { display: none; }
  .main { padding: 14px; }
  .ip-grid { grid-template-columns: 1fr; }
}
