/* ─────────────────────────────────────────────
   tiendatrade · Design System · v1
   Tokens + componentes compartidos
   Minimalista · moderno · light-only
   Porteado del rediseño React de Claude Design.
   ───────────────────────────────────────────── */

:root {
  /* Neutros cálidos muy sutiles */
  --bg:            oklch(1 0 0);
  --surface:       oklch(1 0 0);
  --surface-2:     oklch(0.985 0.004 70);
  --surface-3:     oklch(0.965 0.005 70);
  --border:        oklch(0.925 0.006 70);
  --border-soft:   oklch(0.955 0.005 70);
  --border-strong: oklch(0.875 0.008 70);

  --fg:            oklch(0.22 0.01 60);
  --fg-soft:       oklch(0.42 0.008 60);
  --fg-muted:      oklch(0.58 0.006 60);
  --fg-faint:      oklch(0.72 0.005 60);

  /* Acento naranja refinado */
  --accent:        oklch(0.685 0.185 45);
  --accent-hover:  oklch(0.64 0.19 45);
  --accent-soft:   oklch(0.95 0.04 55);
  --accent-softer: oklch(0.975 0.02 55);
  --accent-fg:     oklch(0.48 0.18 40);

  /* Semánticos */
  --success:       oklch(0.62 0.15 150);
  --success-soft:  oklch(0.955 0.035 150);
  --success-fg:    oklch(0.42 0.12 150);

  --danger:        oklch(0.62 0.19 25);
  --danger-soft:   oklch(0.955 0.035 25);
  --danger-fg:     oklch(0.48 0.17 25);

  --warn:          oklch(0.72 0.16 75);
  --warn-soft:     oklch(0.96 0.04 75);
  --warn-fg:       oklch(0.52 0.14 75);

  --info:          oklch(0.62 0.13 240);
  --info-soft:     oklch(0.96 0.02 240);
  --info-fg:       oklch(0.45 0.13 240);

  /* Tipografía */
  --font:  'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:  'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Tamaños (densidad alta) */
  --fs-xs:  11px;
  --fs-sm:  12px;
  --fs-md:  13px;
  --fs-lg:  14px;
  --fs-xl:  16px;
  --fs-2xl: 20px;
  --fs-3xl: 26px;

  /* Spacing */
  --s-1:  2px;
  --s-2:  4px;
  --s-3:  6px;
  --s-4:  8px;
  --s-5:  10px;
  --s-6:  12px;
  --s-7:  14px;
  --s-8:  16px;
  --s-10: 20px;
  --s-12: 24px;
  --s-16: 32px;

  /* Radios */
  --r-sm:  4px;
  --r-md:  6px;
  --r-lg:  8px;
  --r-xl:  12px;
  --r-2xl: 16px;

  /* Sombras */
  --shadow-xs: 0 1px 0 oklch(0 0 0 / 0.04);
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.04), 0 1px 0 oklch(0 0 0 / 0.03);
  --shadow-md: 0 2px 6px oklch(0 0 0 / 0.05), 0 1px 2px oklch(0 0 0 / 0.04);
  --shadow-lg: 0 8px 24px oklch(0 0 0 / 0.08), 0 2px 4px oklch(0 0 0 / 0.04);

  /* Fallback hex (para navegadores sin oklch) */
  --accent-hex: #F08A47;
}

/* ──────────────────────────────────────────
   BASE
   ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs-md);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "ss03";
  letter-spacing: -0.005em;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.mono, code, kbd {
  font-family: var(--mono);
  font-feature-settings: "ss01", "cv01";
}

/* ──────────────────────────────────────────
   BUTTONS
   ────────────────────────────────────────── */
.tt-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-6);
  height: 30px;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.tt-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.tt-btn.sm  { height: 24px; padding: 0 var(--s-4); font-size: var(--fs-sm); }
.tt-btn.lg  { height: 34px; padding: 0 var(--s-8); font-size: var(--fs-lg); }
.tt-btn.primary {
  background: var(--accent); color: #fff; border-color: transparent;
  box-shadow: 0 1px 0 oklch(0 0 0 / 0.06), inset 0 1px 0 oklch(1 0 0 / 0.15);
}
.tt-btn.primary:hover { background: var(--accent-hover); }
.tt-btn.ghost  { border-color: transparent; background: transparent; color: var(--fg-soft); }
.tt-btn.ghost:hover { background: var(--surface-2); color: var(--fg); }
.tt-btn.soft   { background: var(--accent-soft); color: var(--accent-fg); border-color: transparent; }
.tt-btn.soft:hover { background: oklch(0.93 0.05 55); }
.tt-btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.tt-btn.danger:hover { background: oklch(0.56 0.2 25); }
.tt-btn.success{ background: var(--success); color: #fff; border-color: transparent; }
.tt-btn.icon   { padding: 0; width: 30px; justify-content: center; }
.tt-btn.icon.sm { width: 24px; }
.tt-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ──────────────────────────────────────────
   INPUTS
   ────────────────────────────────────────── */
.tt-input,
.tt-select,
.tt-textarea {
  height: 30px;
  padding: 0 var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--fs-md);
  color: var(--fg);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  min-width: 0;
  font-family: var(--font);
}
.tt-textarea { height: auto; padding: var(--s-3) var(--s-4); }
.tt-input:focus,
.tt-select:focus,
.tt-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.tt-input::placeholder { color: var(--fg-faint); }

.tt-input-group {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  height: 30px;
  padding: 0 var(--s-4);
  gap: var(--s-3);
  transition: border-color .12s, box-shadow .12s;
}
.tt-input-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.tt-input-group input {
  flex: 1; border: 0; outline: 0; background: transparent;
  height: 100%; min-width: 0; color: var(--fg);
}
.tt-input-group .prefix-icon { color: var(--fg-muted); flex-shrink: 0; }

.tt-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.tt-field-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  font-weight: 600;
  margin-bottom: var(--s-2);
  display: block;
}

/* Checkbox custom */
.tt-checkbox {
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  transition: background .12s, border-color .12s;
  position: relative;
  flex-shrink: 0;
}
.tt-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.tt-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ──────────────────────────────────────────
   CARDS
   ────────────────────────────────────────── */
.tt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.tt-card-pad { padding: var(--s-8); }
.tt-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-6) var(--s-8);
  border-bottom: 1px solid var(--border);
  gap: var(--s-6);
}
.tt-card-title    { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; }
.tt-card-subtitle { font-size: var(--fs-sm); color: var(--fg-muted); margin-top: 2px; }

/* ──────────────────────────────────────────
   CHIPS / BADGES
   ────────────────────────────────────────── */
.tt-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 2px var(--s-3);
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--surface-3);
  color: var(--fg-soft);
  line-height: 1.4;
  letter-spacing: -0.005em;
  white-space: nowrap;
}
.tt-chip.accent  { background: var(--accent-soft);  color: var(--accent-fg); }
.tt-chip.success { background: var(--success-soft); color: var(--success-fg); }
.tt-chip.danger  { background: var(--danger-soft);  color: var(--danger-fg); }
.tt-chip.warn    { background: var(--warn-soft);    color: var(--warn-fg); }
.tt-chip.info    { background: var(--info-soft);    color: var(--info-fg); }
.tt-chip.neutral { background: var(--surface-3);    color: var(--fg-soft); }
.tt-chip.dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.tt-chip.mono { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0; }

.tt-badge-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-fg);
}

/* ──────────────────────────────────────────
   TABLES
   ────────────────────────────────────────── */
.tt-table-wrap {
  overflow: auto;
  position: relative;
}
table.tt-data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-md);
}
table.tt-data thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--fg-faint);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
table.tt-data thead th.sortable { cursor: pointer; }
table.tt-data thead th.sortable:hover { color: var(--fg-soft); }
table.tt-data thead th .sort-ind { margin-left: 4px; opacity: 0.5; }
table.tt-data tbody td {
  padding: var(--s-5) var(--s-5);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  white-space: nowrap;
}
table.tt-data tbody tr:last-child td { border-bottom: 0; }
table.tt-data tbody tr:hover { background: var(--surface-2); }
table.tt-data tbody tr.selected { background: var(--accent-softer); }
table.tt-data td.num {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 12px;
}
table.tt-data td.pinned,
table.tt-data th.pinned {
  position: sticky; left: 0; background: var(--surface); z-index: 1;
  box-shadow: 1px 0 0 var(--border-soft);
}
table.tt-data tbody tr:hover td.pinned    { background: var(--surface-2); }
table.tt-data tbody tr.selected td.pinned { background: var(--accent-softer); }

/* ──────────────────────────────────────────
   STOCK BAR
   ────────────────────────────────────────── */
.tt-stock-bar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 90px;
}
.tt-stock-bar .track {
  flex: 1;
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.tt-stock-bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--fg-soft);
  border-radius: 999px;
}
.tt-stock-bar.crit .fill { background: var(--danger); }
.tt-stock-bar.warn .fill { background: var(--warn); }
.tt-stock-bar.ok   .fill { background: var(--success); }
.tt-stock-bar .val {
  font-family: var(--mono); font-size: 11px; color: var(--fg-soft);
  min-width: 26px; text-align: right;
}

/* ──────────────────────────────────────────
   DELTA (variación %)
   ────────────────────────────────────────── */
.tt-delta {
  display: inline-flex; align-items: center; gap: 2px;
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  padding: 1px 5px; border-radius: 4px;
}
.tt-delta.up   { color: var(--danger-fg);  background: var(--danger-soft); }
.tt-delta.down { color: var(--success-fg); background: var(--success-soft); }

/* ──────────────────────────────────────────
   SEGMENTED CONTROL
   ────────────────────────────────────────── */
.tt-segmented {
  display: inline-flex;
  background: var(--surface-3);
  border-radius: var(--r-md);
  padding: 2px;
  gap: 2px;
}
.tt-segmented button {
  padding: 4px 10px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--fg-soft);
  border-radius: 4px;
  transition: background .12s, color .12s;
}
.tt-segmented button:hover { color: var(--fg); }
.tt-segmented button.active {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-xs);
}

/* ──────────────────────────────────────────
   KPI
   ────────────────────────────────────────── */
.tt-kpi {
  padding: var(--s-7) var(--s-8);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.tt-kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--fg-faint);
}
.tt-kpi-value {
  font-family: var(--mono);
  font-size: var(--fs-2xl);
  font-weight: 500;
  color: var(--fg);
  letter-spacing: -0.02em;
}
.tt-kpi-sub {
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  font-family: var(--mono);
}

/* ──────────────────────────────────────────
   PAGE HEADER / TOOLBAR
   ────────────────────────────────────────── */
.tt-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: var(--s-7);
  gap: var(--s-8);
}
.tt-page-title-wrap { display: flex; flex-direction: column; gap: 4px; }
.tt-page-eyebrow {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-faint);
  font-weight: 600;
}
.tt-page-title {
  font-size: var(--fs-3xl);
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--fg);
  line-height: 1.1;
}
.tt-page-actions { display: flex; gap: var(--s-3); align-items: center; }

.tt-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-5) var(--s-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--s-6);
  flex-wrap: wrap;
}
.tt-toolbar .tt-filter-inline { min-width: 0; }
.tt-toolbar .tt-filter-inline .tt-select { min-width: 120px; }
.tt-toolbar .tt-search {
  flex: 1;
  min-width: 220px;
  max-width: 360px;
}
.tt-toolbar .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
}
.tt-filter-inline {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.tt-filter-inline .tt-field-label { margin-bottom: 0; }

/* ──────────────────────────────────────────
   TOAST (notificaciones)
   ────────────────────────────────────────── */
.tt-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: var(--s-5) var(--s-8);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: opacity .25s, transform .25s;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.tt-toast.show { opacity: 1; transform: translateY(0); }
.tt-toast.ok   { background: var(--success); }
.tt-toast.err  { background: var(--danger); }
.tt-toast.info { background: var(--accent); }

/* ──────────────────────────────────────────
   SPINNER
   ────────────────────────────────────────── */
@keyframes tt-spin { to { transform: rotate(360deg); } }
.tt-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: tt-spin .7s linear infinite;
  display: inline-block;
}
.tt-spinner.lg { width: 36px; height: 36px; border-width: 3px; }
.tt-spin { animation: tt-spin .7s linear infinite; display: inline-block; }

/* ──────────────────────────────────────────
   UTILITIES
   ────────────────────────────────────────── */
.tt-hstack { display: flex; align-items: center; }
.tt-vstack { display: flex; flex-direction: column; }
.tt-gap-1 { gap: var(--s-1); }
.tt-gap-2 { gap: var(--s-2); }
.tt-gap-3 { gap: var(--s-3); }
.tt-gap-4 { gap: var(--s-4); }
.tt-gap-5 { gap: var(--s-5); }
.tt-gap-6 { gap: var(--s-6); }
.tt-gap-8 { gap: var(--s-8); }
.tt-flex-1 { flex: 1; }

.tt-divider { height: 1px; background: var(--border); margin: var(--s-5) 0; border: 0; }

.tt-text-muted { color: var(--fg-muted); }
.tt-text-faint { color: var(--fg-faint); }
.tt-text-accent { color: var(--accent-fg); }
.tt-text-success { color: var(--success-fg); }
.tt-text-danger { color: var(--danger-fg); }
.tt-text-warn { color: var(--warn-fg); }
.tt-text-sm { font-size: var(--fs-sm); }
.tt-text-xs { font-size: var(--fs-xs); }
.tt-mono { font-family: var(--mono); }

/* Scrollbar discreto */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-track { background: transparent; }
