/* ============ Tokens ============ */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e2e5ea;
  --line-strong: #cfd4dc;
  --ink: #0f1720;
  --ink-2: #4a5462;
  --muted: #7b8490;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --danger: #c53030;
  --danger-soft: #fdeaea;
  /* estados (siempre con texto, nunca solo color) */
  --st-pend-bg: #fff4d6; --st-pend-ink: #8a5a00;
  --st-proc-bg: #e3eefc; --st-proc-ink: #1c5cab;
  --st-ok-bg:   #e2f5e2; --st-ok-ink:   #006300;
  --st-na-bg:   #eeeeec; --st-na-ink:   #52514e;
  --pr-alta: #d03b3b; --pr-media: #c98500; --pr-baja: #0ca30c;
  /* gráficos */
  --series-1: #2a78d6; --series-2: #eb6834;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  --grid: #e1e0d9; --axis: #898781;
  --shadow: 0 1px 2px rgba(15, 23, 32, .06), 0 4px 16px rgba(15, 23, 32, .05);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115; --surface: #171a20; --surface-2: #1d2128;
    --line: #2a2f38; --line-strong: #3a414c;
    --ink: #f1f3f6; --ink-2: #c3c8d0; --muted: #8b939e;
    --accent: #3987e5; --accent-soft: #1b2a3f;
    --danger: #e66767; --danger-soft: #3a1d1f;
    --st-pend-bg: #3a2e10; --st-pend-ink: #fab219;
    --st-proc-bg: #16294a; --st-proc-ink: #86b6ef;
    --st-ok-bg:   #133018; --st-ok-ink:   #4fc94f;
    --st-na-bg:   #2a2b2e; --st-na-ink:   #c3c2b7;
    --series-1: #3987e5; --series-2: #d95926;
    --grid: #2c2c2a; --axis: #898781;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115; --surface: #171a20; --surface-2: #1d2128;
  --line: #2a2f38; --line-strong: #3a414c;
  --ink: #f1f3f6; --ink-2: #c3c8d0; --muted: #8b939e;
  --accent: #3987e5; --accent-soft: #1b2a3f;
  --danger: #e66767; --danger-soft: #3a1d1f;
  --st-pend-bg: #3a2e10; --st-pend-ink: #fab219;
  --st-proc-bg: #16294a; --st-proc-ink: #86b6ef;
  --st-ok-bg:   #133018; --st-ok-ink:   #4fc94f;
  --st-na-bg:   #2a2b2e; --st-na-ink:   #c3c2b7;
  --series-1: #3987e5; --series-2: #d95926;
  --grid: #2c2c2a; --axis: #898781;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ============ Layout ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; color: var(--muted); font-size: 11px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--accent) 70%, white); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.usuario { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.usuario select { min-width: 180px; }

.container { max-width: 1320px; margin: 0 auto; padding: 20px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); align-items: start; }
@media (max-width: 1000px) { .grid-side, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px)  { .grid-side, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .container { padding: 16px; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ============ Formularios ============ */
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields .full { grid-column: 1 / -1; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=number] { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; font: inherit; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 4px 8px; }

/* ============ Tablas ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td input[type=number] { width: 80px; }

/* ============ Badges ============ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-PENDIENTE { background: var(--st-pend-bg); color: var(--st-pend-ink); }
.st-EN-PROCESO { background: var(--st-proc-bg); color: var(--st-proc-ink); }
.st-TERMINADO, .st-FINALIZADO, .st-ENTREGADO, .st-LISTO-PARA-ENTREGA { background: var(--st-ok-bg); color: var(--st-ok-ink); }
.st-NO-REQUIERE { background: var(--st-na-bg); color: var(--st-na-ink); }
.pr { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; }
.pr::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: var(--c); }
.pr-ALTA { --c: var(--pr-alta); } .pr-MEDIA { --c: var(--pr-media); } .pr-BAJA { --c: var(--pr-baja); }

.progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress.ok > span { background: var(--good); }

.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); flex: none; display: inline-grid; place-items: center; color: var(--muted); font-size: 10px; }
.senal-cell { display: flex; gap: 10px; align-items: center; }
.senal-cell strong { display: block; }

/* ============ Tablero de trabajo ============ */
.pedido-block { margin-bottom: 16px; }
.pedido-block .card-head h3 { display: flex; gap: 10px; align-items: center; }
.linea { display: grid; grid-template-columns: minmax(220px, 1.3fr) minmax(150px, .7fr) minmax(280px, 2fr); gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: start; }
.linea:last-child { border-bottom: 0; }
@media (max-width: 900px) { .linea { grid-template-columns: 1fr; } }
.etapas { display: flex; flex-direction: column; gap: 8px; }
.etapa { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.etapa .nombre { font-weight: 600; min-width: 130px; }
.etapa.corriendo { border-color: var(--accent); background: var(--accent-soft); }
.etapa .timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.etapa input[type=number] { width: 80px; }
details.sesiones summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 4px; }
details.sesiones table { margin-top: 6px; font-size: 12px; }
details.sesiones td, details.sesiones th { padding: 5px 8px; }

/* ============ KPIs ============ */
.stat { padding: 16px; }
.stat .label { color: var(--ink-2); font-size: 12px; font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.chart-box { position: relative; height: 260px; }

/* ============ Modal / toasts ============ */
.modal { border: 0; padding: 0; background: transparent; width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px); color: var(--ink); }
.modal::backdrop { background: rgba(10, 14, 20, .55); }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal.narrow { width: min(520px, calc(100vw - 32px)); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-foot:empty { display: none; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kv > div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kv > div > span:first-child { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv strong { font-size: 15px; }
.kv .progress { margin-top: 6px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: tin .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.hint { background: var(--accent-soft); color: var(--ink-2); border-radius: 8px; padding: 8px 10px; font-size: 12px; }

/* ============ Usuario & Quick Login ============ */
.usuario-badge { display: flex; align-items: center; }
.btn-usuario {
  display: flex; align-items: center; gap: 10px; padding: 5px 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px;
  cursor: pointer; font: inherit; color: var(--ink); text-align: left;
  transition: all .15s ease;
}
.btn-usuario:hover { border-color: var(--accent); background: var(--accent-soft); }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent);
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: bold; flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; line-height: 1.15; }
.user-info strong { font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info small { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }

.login-area-group { margin-bottom: 16px; }
.login-area-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.login-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.colab-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; text-align: center;
  font: inherit; transition: all .15s ease;
}
.colab-card:hover {
  border-color: var(--accent); background: var(--accent-soft);
  transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.colab-card .avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
}
.colab-card strong { font-size: 12px; color: var(--ink); }
.colab-card small { font-size: 10px; color: var(--muted); }

/* ============ Sesiones de tiempo - Acciones ============ */
.btn-icon-action {
  background: transparent; border: 1px solid transparent; cursor: pointer;
  font-size: 14px; padding: 4px 6px; border-radius: 6px; opacity: 0.8;
  transition: all .15s ease; display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon-action:hover { opacity: 1; background: var(--surface-2); border-color: var(--line); transform: scale(1.1); }
.btn-icon-action.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ============ Selector de imagen (PC / URL web / SharePoint) ============ */
.image-picker-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface-2);
}
.image-source-seg {
  display: inline-flex;
  margin-bottom: 10px;
}
.dropzone-box {
  border: 2px dashed var(--line-strong);
  border-radius: 8px;
  padding: 16px 12px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
  transition: all .2s ease;
  position: relative;
}
.dropzone-box:hover, .dropzone-box.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.dropzone-icon {
  font-size: 26px;
}
.file-hidden-input {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}
.preview-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}
.preview-img {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
}
.preview-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.preview-meta strong {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge-sp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, #0078d4 15%, transparent);
  color: #0078d4;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  width: fit-content;
}
.sp-uploading-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  padding: 8px 0;
}
.spinner-sm {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============ Topbar derecho ============ */
.topbar-right {
  display: flex; align-items: center; gap: 10px; margin-left: auto;
}

/* ============ Botón campana de notificaciones ============ */
.btn-notif {
  position: relative;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 50%;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 17px; transition: all .15s ease;
}
.btn-notif:hover { border-color: var(--accent); background: var(--accent-soft); }

.notif-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
  animation: pulse-badge .4s ease-out;
}
@keyframes pulse-badge {
  from { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.25); }
  to   { transform: scale(1); opacity: 1; }
}

/* ============ Vista de Notificaciones ============ */
.notif-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: var(--surface); transition: background .15s;
}
.notif-item:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
.notif-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.notif-item.nueva { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.notif-item.leida { opacity: .75; }
.notif-item:hover { background: var(--surface-2); }

.notif-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--line);
}
.tipo-urgente { background: var(--danger-soft); }
.tipo-alerta  { background: #fff8e0; }
.tipo-info    { background: var(--accent-soft); }

.notif-body { flex: 1; min-width: 0; }
.notif-titulo  { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.notif-mensaje { color: var(--ink-2); font-size: 13px; line-height: 1.4; margin-bottom: 6px; }
.notif-meta    { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notif-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; flex-shrink: 0; }

/* Lista envuelta en tarjeta */
#notif-lista { border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
