:root {
  --bg: #efebe1;
  --card-bg: #faf6ee;
  --border: #e3ddcf;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #d6336c;
  --primary-dark: #b02655;
  --danger: #e0453f;
  --warn: #f2b705;
  --ok: #2ea043;
  --sidebar-bg: #201f2b;
  --sidebar-bg-active: #2c2a3d;
  --sidebar-text: #c7c5d6;
  --sidebar-text-dim: #8b899c;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

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

/* ---------------- Layout de sidebar ---------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
}

.main-wrap {
  margin-left: 230px;
  width: calc(100% - 230px);
}

.sidebar-logo {
  background: #ffffff;
  border-radius: 10px;
  padding: 14px 10px;
  margin: 0 auto 18px;
  width: 180px;
  text-align: center;
}
.sidebar-logo img { width: 100%; height: auto; display: block; margin: 0 auto; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.92em;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--sidebar-bg-active); color: #fff; }
.nav-item.active {
  background: var(--sidebar-bg-active);
  color: #fff;
  border-left: 3px solid var(--primary);
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 8px;
}
.sidebar-user .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85em; font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user .username { color: var(--sidebar-text); font-size: 0.88em; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .logout-link { color: var(--sidebar-text-dim); display: flex; }
.sidebar-user .logout-link:hover { color: #fff; }
.sidebar-user .logout-link svg { width: 17px; height: 17px; }

.content { padding: 24px 32px; width: 100%; }

.page-header { margin-bottom: 20px; }
.page-header h1 { margin: 0; }

h1 { margin-top: 0; }

/* ---------------- Login ---------------- */

.login-box {
  max-width: 320px;
  margin: 90px auto;
  background: var(--card-bg);
  padding: 32px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.login-logo { max-width: 200px; margin: 0 auto 4px; display: block; }
.login-box .subtitle { color: var(--muted); margin-top: 0; margin-bottom: 20px; }
.login-box form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.login-box label { font-size: 0.85em; color: var(--muted); }
.login-box input { padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.login-box button { margin-top: 12px; }

/* ---------------- Formularios ---------------- */

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
}
legend { font-weight: 600; padding: 0 6px; }
label { display: block; margin-top: 8px; font-size: 0.9em; color: var(--muted); }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], input[type="password"], select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 2px;
  font-size: 1em;
  font-family: inherit;
}
.item-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.item-row input { margin-top: 0; }

button, .btn-primary, .btn-secondary {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 0.95em;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef1f6; color: var(--text); text-decoration: none; display: inline-block; }
.btn-icon { background: none; color: var(--danger); font-size: 1em; padding: 4px 8px; }

.alert-ok { background: #e6f6ea; border: 1px solid var(--ok); color: #1c6b30; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert-error { background: #fdeceb; border: 1px solid var(--danger); color: #a1332e; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

/* ---------------- Filtros y tabla ---------------- */

.filters { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; background: var(--card-bg); padding: 14px; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.filters label { margin-top: 0; }
.filters button, .filters .btn-secondary { align-self: flex-end; }

.table-scroll { overflow-x: auto; border-radius: 10px; box-shadow: var(--shadow-sm); }
.table-scroll .pedidos-table { box-shadow: none; }

.pedidos-table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 10px; overflow: hidden; }
.pedidos-table tbody tr { cursor: pointer; }
.pedidos-table tbody tr:hover { background: #f3ecdd; }
.pedidos-table tbody tr.atrasado:hover { background: #fdeae7; }
.pedidos-table th, .pedidos-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.9em; text-align: left; vertical-align: top; }
.pedidos-table th { background: var(--sidebar-bg); color: #fff; font-weight: 600; }
.pedidos-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.pedidos-table th.sortable:hover { background: var(--sidebar-bg-active); }
.pedidos-table th .sort-arrow { font-size: 0.75em; color: var(--sidebar-text-dim); margin-left: 4px; }
.pedidos-table th.sort-asc .sort-arrow, .pedidos-table th.sort-desc .sort-arrow { color: var(--primary); }
.pedidos-table tr.atrasado { background: #fff8f7; }
.pedidos-table a.pedido-link { color: var(--text); font-weight: 600; text-decoration: none; }
.pedidos-table a.pedido-link:hover { color: var(--primary); text-decoration: underline; }
.inline-form { display: inline-flex; gap: 6px; }
.pago-form input { width: 90px; margin-top: 0; }
.acciones { display: flex; gap: 10px; align-items: center; }

/* ---------------- Pills / badges ---------------- */

.pill { display: inline-block; border-radius: 10px; padding: 2px 9px; font-size: 0.78em; font-weight: 600; }
.pill-ok { background: #e6f6ea; color: var(--ok); }
.pill-warn { background: #fdf3d9; color: #8a6400; }
.pill-danger { background: #fdeceb; color: var(--danger); }

/* ---------------- Kanban ---------------- */

.kanban-board { display: flex; gap: 16px; align-items: flex-start; }
.kanban-col { flex: 1; min-width: 250px; background: #eceef2; border-radius: 12px; padding: 12px; }
.kanban-col-header { padding: 4px 8px 12px; }
.kanban-col-header h2 { font-size: 0.95em; margin: 0 0 2px; }
.kanban-col-summary { font-size: 0.78em; color: var(--muted); }
.kanban-list { min-height: 60px; display: flex; flex-direction: column; gap: 8px; }
.kanban-card { background: var(--card-bg); border-radius: 10px; padding: 12px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.card-num { font-size: 0.75em; color: var(--muted); }
.card-nombre { font-weight: 600; margin-top: 2px; }
.card-detalle { font-size: 0.85em; color: var(--muted); margin: 4px 0; }
.card-fecha { font-size: 0.8em; }
.card-pago { margin-top: 8px; }

.status-icon { width: 16px; height: 16px; flex-shrink: 0; }
.status-atrasado { color: var(--danger); }
.status-pagado { color: var(--ok); }
.status-neutro { color: #c9cbd3; }

/* ---------------- Detalle de pedido ---------------- */

.detalle-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.detalle-acciones { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-danger { background: var(--card-bg); color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: #fdeceb; }
.btn-ok { background: var(--card-bg); color: var(--ok); border: 1px solid var(--ok); }
.btn-ok:hover { background: #e6f6ea; }

.detalle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.detalle-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; box-shadow: var(--shadow-sm); }
.detalle-card h3 { margin: 0 0 10px; font-size: 0.9em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detalle-card dl { margin: 0; }
.detalle-card dt { font-size: 0.8em; color: var(--muted); margin-top: 8px; }
.detalle-card dt:first-child { margin-top: 0; }
.detalle-card dd { margin: 0; font-size: 1em; }

.detalle-items { width: 100%; border-collapse: collapse; }
.detalle-items th, .detalle-items td { padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.92em; }
.detalle-items th:last-child, .detalle-items td:last-child { text-align: right; }

/* ---------------- Mobile: topbar + drawer ---------------- */

.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  z-index: 40;
}
.mobile-topbar img { height: 34px; }
.hamburger {
  background: none; border: none; color: #fff; padding: 6px;
  display: flex; align-items: center; justify-content: center;
}
.hamburger svg { width: 24px; height: 24px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 30;
}

@media (max-width: 860px) {
  .mobile-topbar { display: flex; }
  .sidebar-overlay.open { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }

  .main-wrap {
    margin-left: 0;
    width: 100%;
    padding-top: 56px;
  }

  .filters { flex-direction: column; align-items: stretch; }
  .filters label { width: 100%; }

  .kanban-board { overflow-x: auto; padding-bottom: 8px; }
  .kanban-col { min-width: 250px; }

  .detalle-grid { grid-template-columns: 1fr; }
  .detalle-header { flex-direction: column; align-items: stretch; }

  .item-row { flex-wrap: wrap; }
  .item-row input { flex: 1 1 100%; }
}
