/* ========================================================================== *
 * Trevi Uploader — Internal Tool UI
 * Design system per the guidelines: warm neutrals, ink text scale, one brand
 * accent used by exception. Calm by default, color on exception.
 * ========================================================================== */

:root {
  /* Foundations — warm neutral palette */
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --bg-sunk: #f4f3ee;
  --line: #e8e6df;
  --line-strong: #d8d5cb;

  /* Ink scale */
  --ink: #0f1115;
  --ink-2: #2a2d33;
  --ink-3: #5a5d63;
  --ink-4: #8c8e94;
  --ink-5: #b6b8bd;

  /* Brand accent (orange -> magenta), used sparingly */
  --brand: #ee6420;
  --brand-2: #e91e63;
  --brand-grad: linear-gradient(135deg, #ee6420, #e91e63);

  /* Semantic color + soft pairs */
  --ok: #1f8a52;         --ok-soft: #e0f1e7;
  --warn: #b7791f;       --warn-soft: #fbf1d6;
  --danger: #c7321b;     --danger-soft: #fbe2dc;
  --info: #2563a8;       --info-soft: #ddebf7;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(15, 17, 21, .04);
  --shadow-pop: 0 8px 24px rgba(15, 17, 21, .12);

  --ffs: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ffm: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Consolas", monospace;

  --t: .12s ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--ffs);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--ffm); }

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

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 16px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: var(--radius-pill);
  background: var(--brand-grad);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 2px 6px rgba(233, 30, 99, .25);
}

.brand-text .brand-name {
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
  letter-spacing: -.01em;
}
.brand-text .brand-sub {
  font-size: 11px;
  color: var(--ink-4);
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 12px;
}
.nav-group { margin-bottom: 14px; }
.nav-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-4);
  padding: 6px 8px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-3);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  transition: background var(--t), color var(--t);
}
.nav-item:hover { background: var(--bg-sunk); color: var(--ink-2); }
.nav-item.active { background: var(--ink); color: #fff; }
.nav-item .ico { width: 16px; text-align: center; opacity: .8; }
.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  background: var(--bg-sunk);
  color: var(--ink-3);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
  font-variant-numeric: tabular-nums;
}
.nav-item.active .count { background: rgba(255,255,255,.18); color: #fff; }
.nav-item .count.urgent { background: var(--brand); color: #fff; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunk);
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--ink-3);
}
.sidebar-foot .who { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.sidebar-foot .ctx { font-size: 11px; color: var(--ink-4); }

/* ---------- Main column -------------------------------------------------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 250, 247, .86);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 26px;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.01em;
}
.topbar .status-line { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.topbar .spacer { flex: 1; }
.topbar .topbar-actions { display: flex; align-items: center; gap: 10px; }

.content {
  padding: 24px 26px 40px;
  max-width: 1280px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Card --------------------------------------------------------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.card-header .titles { min-width: 0; }
.card-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.card-sub { font-size: 12px; color: var(--ink-4); margin-top: 1px; }
.card-header .spacer { flex: 1; }
.card-header .actions { display: flex; gap: 8px; align-items: center; }
.card-body { padding: 18px; }
.card-body + .card-body { border-top: 1px solid var(--line); }

/* ---------- Metric tiles ------------------------------------------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
}
.metric {
  background: var(--bg-elev);
  padding: 16px 18px;
}
.metric .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-4);
  font-weight: 600;
}
.metric .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  margin-top: 4px;
}
.metric .value.brand { color: var(--brand); }
.metric .value.danger { color: var(--danger); }
.metric .value.ok { color: var(--ok); }

/* ---------- Field / labels ----------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.micro-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-4);
  font-weight: 600;
}

.input, .dropzone {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink-2);
  transition: border var(--t), background var(--t), box-shadow var(--t);
}
.input:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px rgba(15, 17, 21, .06);
}
.input[readonly] { background: var(--bg-sunk); }

textarea.input {
  width: 100%;
  resize: vertical;
  min-height: 88px;
  line-height: 1.5;
}
textarea.input::placeholder { color: var(--ink-5); }

/* Dropzone (file pickers) */
.dropzone {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
}
.dropzone:hover { border-color: var(--ink-3); background: var(--bg-elev); }
.dropzone.dragover {
  border-color: var(--ink);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px rgba(15, 17, 21, .06);
}
.dropzone .dz-ico {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: var(--radius-md);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 16px;
}
.dropzone .dz-main { min-width: 0; flex: 1; }
.dropzone .dz-title { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.dropzone .dz-hint { font-size: 11.5px; color: var(--ink-4); }
.dropzone .dz-file {
  font-family: var(--ffm);
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ---------- Buttons ------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--t), border var(--t), color var(--t), opacity var(--t);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-sunk); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn--primary:hover { background: #000; }

.btn--brand {
  background: var(--brand-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 1px 2px rgba(233, 30, 99, .25);
}
.btn--brand:hover { filter: brightness(1.04); background: var(--brand-grad); }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-3);
}
.btn--ghost:hover { background: var(--bg-sunk); color: var(--ink-2); }

.btn--sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Checkbox toggles (option chips) ------------------------------ */
.opt-row { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--ink-2);
  transition: background var(--t), border var(--t);
}
.opt:hover { background: var(--bg-sunk); }
.opt input { accent-color: var(--ink); width: 15px; height: 15px; }
.opt.on { border-color: var(--ink-3); background: var(--bg-elev); }

/* ---------- Badges ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--neutral { background: var(--bg-sunk); color: var(--ink-3); }

/* ---------- Status dots -------------------------------------------------- */
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0 3px var(--bg-elev);
  flex: 0 0 9px;
}
.dot--pending { background: var(--ink-5); }
.dot--success { background: var(--ok); }
.dot--failed { background: var(--danger); }
.dot--skipped { background: var(--ink-4); }
.dot--running {
  background: var(--info);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--bg-elev), 0 0 0 3px rgba(37,99,168,.35); }
  50% { box-shadow: 0 0 0 3px var(--bg-elev), 0 0 0 7px rgba(37,99,168,0); }
}

/* ---------- Table -------------------------------------------------------- */
.table-wrap {
  max-height: 460px;
  overflow: auto;
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.tbl thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-sunk);
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-4);
  font-weight: 600;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.tbl tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: var(--bg-sunk); }
table.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.pnr {
  font-family: var(--ffm);
  font-weight: 500;
  color: var(--ink);
}
.pnr-link { cursor: pointer; text-decoration: none; color: inherit; }
.pnr-link:hover { color: var(--brand-2); text-decoration: underline; }
.cell-status { display: flex; align-items: center; gap: 8px; }
.cell-status .txt {
  color: var(--ink-3);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 420px;
}

/* ---------- Log console (the deliberately dark surface) ------------------ */
.console {
  background: var(--ink);
  border-radius: 0;
  max-height: 320px;
  overflow: auto;
  padding: 14px 16px;
  font-family: var(--ffm);
  font-size: 12px;
  line-height: 1.6;
  color: #c9cdd4;
}
.console .ln { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.console .ts { color: #6b7078; flex: 0 0 auto; }
.console .ln.err .msg { color: #f0a99a; }
.console .ln.ok .msg { color: #9fe0b8; }
.console .msg { color: #c9cdd4; }

/* ---------- Empty state -------------------------------------------------- */
.empty {
  text-align: center;
  color: var(--ink-4);
  padding: 40px 20px;
  font-size: 13px;
}
.empty .em-ico { font-size: 26px; margin-bottom: 8px; opacity: .5; }

/* ---------- Toast -------------------------------------------------------- */
.toast-wrap {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 260px;
  max-width: 380px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-pop);
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: toast-in .18s ease;
}
.toast.out { animation: toast-out .18s ease forwards; }
.toast--ok { background: #12603a; }
.toast--danger { background: #8c2415; }
.toast--warn { background: #7a5312; }
.toast .t-title { font-weight: 600; }
.toast .t-body { color: rgba(255,255,255,.8); font-size: 12px; margin-top: 1px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* Progress bar (brand — signature run) */
.progress {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunk);
  overflow: hidden;
}
.progress .bar {
  height: 100%;
  width: 0;
  background: var(--brand-grad);
  border-radius: var(--radius-pill);
  transition: width .25s ease;
}

.hidden { display: none !important; }

/* ---------- Responsive: collapse sidebar under ~880px -------------------- */
@media (max-width: 880px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 30;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .brand { padding: 10px 14px; }
  .nav {
    display: flex;
    flex-direction: row;
    gap: 4px;
    padding: 8px 10px;
    overflow-x: auto;
  }
  .nav-group { margin: 0; display: flex; align-items: center; gap: 4px; }
  .nav-title { display: none; }
  .sidebar-foot { display: none; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}
