/* ============================================================
   Tejido Counter - Estilo Apple-like
   Light + Dark mode automatico, mobile-first
   ============================================================ */

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

:root {
  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --text: #1d1d1f;
  --text-soft: #6e6e73;
  --text-muted: #86868b;
  --accent: #007aff;
  --accent-hover: #0056d6;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --gray: #8e8e93;
  --shadow: 0 4px 24px rgba(0,0,0,0.06);
  --shadow-hover: 0 8px 32px rgba(0,0,0,0.10);
  --radius: 18px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-card: #1c1c1e;
    --bg-input: #2c2c2e;
    --border: rgba(255, 255, 255, 0.08);
    --text: #f5f5f7;
    --text-soft: #a1a1a6;
    --text-muted: #6e6e73;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --shadow-hover: 0 8px 32px rgba(0,0,0,0.6);
  }
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.topbar-actions {
  display: flex;
  gap: .75rem;
  align-items: center;
}

.topbar-actions .text-muted { font-size: .85rem; }

/* ---------- Headings ---------- */

h1 { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.4rem; font-weight: 600; letter-spacing: -.01em; margin-bottom: 1rem; }
h3 { font-size: 1.05rem; font-weight: 600; }

.text-muted { color: var(--text-soft); }
.text-small { font-size: .85rem; }
.text-mono { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: .9em; }

/* ---------- Cards ---------- */

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  transition: box-shadow .2s ease, transform .2s ease;
  border: 1px solid var(--border);
}

.card-link {
  display: block;
  color: inherit;
  cursor: pointer;
}
.card-link:hover {
  text-decoration: none;
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

/* ---------- Grid de maquinas ---------- */

.grid-maquinas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.maquina-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.maquina-codigo {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.maquina-piezas-hoy {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -.03em;
}

.maquina-piezas-label {
  font-size: .8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: -.25rem;
}

/* Carro mini-bar */
.carro-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .75rem;
}
.carro-label {
  font-size: .85rem;
  color: var(--text-soft);
  width: 50px;
  flex-shrink: 0;
}
.carro-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.carro-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .3s ease;
}
.carro-piezas {
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  width: 50px;
  text-align: right;
}

/* Estado dot */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: .35rem;
  vertical-align: middle;
}
.status-dot.green { background: var(--green); box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.15); }
.status-dot.orange { background: var(--orange); box-shadow: 0 0 0 4px rgba(255, 149, 0, 0.15); }
.status-dot.red { background: var(--red); box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.15); }
.status-dot.gray { background: var(--gray); }

.maquina-status {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .85rem;
  color: var(--text-soft);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--red); }
.btn-danger:hover { background: #c41e15; }

.btn-success { background: var(--green); }
.btn-success:hover { background: #28a745; }

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  border-radius: 14px;
  width: 100%;
}

/* ---------- Forms ---------- */

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-soft);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.form-input, .form-select {
  width: 100%;
  padding: .75rem .9rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

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

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 2.5rem 2rem;
}

.login-card h1 { margin-bottom: .5rem; font-size: 1.6rem; }
.login-card .text-muted { margin-bottom: 1.75rem; }

/* ---------- Detalle maquina ---------- */

.detalle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.kvlist {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem 1rem;
  font-size: .9rem;
}
.kvlist dt { color: var(--text-soft); }
.kvlist dd { font-weight: 500; text-align: right; }

/* Lote actual card */
.lote-actual h3 { margin-bottom: .25rem; }
.lote-actual .pedido { color: var(--text-soft); font-size: .9rem; margin-bottom: 1rem; }
.progress-wrap {
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: .75rem 0 .25rem;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width .4s ease;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  color: var(--text-soft);
}

.lote-actions {
  display: flex;
  gap: .5rem;
  margin-top: 1rem;
}
.lote-actions .btn { flex: 1; }

/* Tabla simple */
.table-simple {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table-simple th {
  text-align: left;
  padding: .5rem .75rem;
  font-weight: 500;
  color: var(--text-soft);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
}
.table-simple td {
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--border);
}
.table-simple tr:last-child td { border-bottom: none; }

/* Categoria de paro - badge */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-corto { background: rgba(255, 149, 0, 0.15); color: var(--orange); }
.badge-medio { background: rgba(255, 59, 48, 0.15); color: var(--red); }
.badge-largo { background: rgba(255, 59, 48, 0.25); color: var(--red); font-weight: 600; }
.badge-almuerzo { background: rgba(0, 122, 255, 0.15); color: var(--accent); }

/* Chart container */
.chart-container {
  position: relative;
  height: 280px;
  margin-top: 1rem;
}

/* ---------- Mobile (lote.html) ---------- */

.mobile-wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding: .5rem 0;
}

.lote-activo-display {
  background: linear-gradient(135deg, var(--accent), #5856d6);
  color: white;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}
.lote-activo-display .label {
  text-transform: uppercase;
  font-size: .75rem;
  opacity: .8;
  letter-spacing: .05em;
}
.lote-activo-display .tipo { font-size: 1.4rem; font-weight: 600; margin: .25rem 0; }
.lote-activo-display .pedido { opacity: .9; }
.lote-activo-display .piezas-grande { font-size: 3.5rem; font-weight: 700; margin: 1rem 0 0; letter-spacing: -.04em; }
.lote-activo-display .meta-text { opacity: .8; font-size: .9rem; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--text);
  color: var(--bg);
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-hover);
  transition: transform .25s ease;
  z-index: 100;
  max-width: 90vw;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); color: #fff; }
.toast.success { background: var(--green); color: #fff; }

/* ---------- Loading + empty states ---------- */

.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: .95rem;
}

/* ---------- Utilities ---------- */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

@media (max-width: 600px) {
  .container { padding: 1rem; }
  h1 { font-size: 1.6rem; }
  .maquina-codigo { font-size: 1.4rem; }
  .maquina-piezas-hoy { font-size: 1.8rem; }
}
