:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --green: #15803d;
  --green-bg: #dcfce7;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 16px;
}

.hidden {
  display: none !important;
}

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

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  padding-bottom: 12px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-icon {
  font-size: 26px;
  line-height: 1;
}

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

.subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

main {
  padding-top: 24px;
  padding-bottom: 48px;
}

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

.section-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.section-header p {
  margin: 0;
  font-size: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-alt);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover {
  background: #e2e8f066;
}

.icon-btn {
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 15px;
}

.icon-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.icon-btn.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Spaces Grid */
.spaces-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.space-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.space-card:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}

.space-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.space-card h3 {
  margin: 0;
  font-size: 18px;
  word-break: break-word;
}

.space-card-actions {
  display: flex;
  gap: 2px;
}

.space-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--surface-alt);
  border-radius: 9px;
  padding: 10px;
}

.space-stat {
  display: flex;
  flex-direction: column;
}

.space-stat span {
  font-size: 11px;
  color: var(--muted);
}

.space-stat strong {
  font-size: 15px;
}

.space-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  font-size: 14px;
}

.space-card-total {
  font-weight: 700;
  color: var(--primary);
  font-size: 16px;
}

/* Orders View */
.breadcrumb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.space-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.space-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.space-banner h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.space-banner p {
  margin: 0;
  font-size: 13px;
}

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

.kpi-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 96px;
}

.kpi-total {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.kpi-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 18px;
  font-weight: 700;
}

.kpi-amber {
  color: var(--amber);
}

.kpi-green {
  color: var(--green);
}

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

.filter-pills {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.pill {
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.pill.active {
  background: var(--primary);
  color: #fff;
}

.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.search-input {
  max-width: 300px;
}

/* Table */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.orders-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

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

.orders-table th {
  background: var(--surface-alt);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 700;
}

.orders-table tbody tr:hover {
  background: #f8fafc;
}

.orders-table tbody tr.row-delivered {
  opacity: 0.78;
}

.num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.actions-col {
  width: 90px;
  text-align: right !important;
}

.customer-cell strong {
  display: block;
}

.customer-cell small {
  font-size: 11px;
  color: var(--muted);
}

.color-tag {
  display: inline-block;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
}

.due-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.due-badge {
  display: inline-block;
  width: fit-content;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
}

.due-ok {
  background: #e0f2fe;
  color: #0369a1;
}

.due-soon {
  background: var(--amber-bg);
  color: var(--amber);
}

.due-late {
  background: var(--danger-bg);
  color: var(--danger);
}

.due-done {
  background: var(--green-bg);
  color: var(--green);
}

/* Inline status select */
.status-select {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
}

.status-select.status-creando {
  background: var(--amber-bg);
  color: var(--amber);
  border-color: #fde68a;
}

.status-select.status-entregado {
  background: var(--green-bg);
  color: var(--green);
  border-color: #bbf7d0;
}

/* Footer Total */
.total-row td {
  background: #eff6ff;
  border-top: 2px solid #93c5fd;
  border-bottom: none;
  padding: 14px;
}

.total-price-cell {
  font-size: 17px !important;
  color: var(--primary);
}

.total-note {
  font-size: 13px !important;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
}

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

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

.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  padding: 20px;
  max-height: 92vh;
  overflow-y: auto;
}

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

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

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
}

.hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

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

.delivery-preview {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

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

.auth-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.auth-desc {
  margin: 0 0 18px;
  font-size: 14px;
}

.auth-submit {
  width: 100%;
  padding: 11px 16px;
  margin-top: 6px;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

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

.user-pill {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 13px;
}

.new-user-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.new-user-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--surface);
}

.user-row-info strong {
  display: block;
  font-size: 14px;
}

.user-row-info small {
  font-size: 12px;
  color: var(--muted);
}

.user-row-actions {
  display: flex;
  gap: 4px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 100;
}

@media (max-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .search-input {
    max-width: 100%;
  }
  .kpi-row {
    width: 100%;
  }
  .kpi-card {
    flex: 1 1 42%;
  }
}
