/* ============================================================
   Controle de Enxoval — Grupo 3V / Cantucci
   Mesmo sistema visual de /dashboard/ e do portal: base clara,
   topbar azul, oliva como cor de ação; modo escuro como o portal.
   ============================================================ */

:root {
  --bg: #f4f1ea;
  --surface: #fffefa;
  --surface-2: #f8f5ee;
  --surface-3: #eee7d9;
  --field: #ffffff;
  --line: rgba(22, 58, 66, .14);
  --line-strong: rgba(22, 58, 66, .28);
  --text: #173a43;
  --muted: #637a7c;
  --faint: #8d9b9a;
  --brand-blue: #0e3a45;
  --brand-blue-2: #123f4b;
  --brand: #968b66;
  --brand-strong: #7f7554;
  --brand-ink: #ffffff;
  --ok: #2f9d72;
  --ok-bg: rgba(47, 157, 114, .12);
  --ok-border: rgba(47, 157, 114, .28);
  --warn: #c88424;
  --warn-bg: rgba(200, 132, 36, .13);
  --warn-border: rgba(200, 132, 36, .30);
  --danger: #c84f49;
  --danger-bg: rgba(200, 79, 73, .12);
  --danger-border: rgba(200, 79, 73, .30);
  --blue: #1e6f91;
  --shadow: 0 14px 34px rgba(14, 58, 69, .10);
  --r: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #081d23;
    --surface: #10303b;
    --surface-2: #193e4c;
    --surface-3: #1f4e60;
    --field: #0c2730;
    --line: rgba(240, 237, 229, .12);
    --line-strong: rgba(240, 237, 229, .22);
    --text: #f0ede5;
    --muted: #8fb3b0;
    --faint: #5d827f;
    --brand: #a29c7e;
    --brand-strong: #c3bd9e;
    --brand-ink: #081d23;
    --ok: #3aab82;
    --warn: #d4952a;
    --danger: #d8605a;
    --blue: #5aa6cf;
    --shadow: 0 10px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--brand) 18%, transparent), transparent 34rem),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; text-decoration: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 66px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-2));
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  color: white;
  box-shadow: 0 12px 32px rgba(14, 58, 69, .14);
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand span > span { display: block; color: rgba(255, 255, 255, .72); font-size: 12px; }

.mark {
  width: 44px; height: 44px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .10);
  border: 1px solid rgba(255, 255, 255, .28);
  color: #f3ead3; font-weight: 800; letter-spacing: .04em;
}
.mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 12px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border-bottom: 2px solid transparent;
  color: rgba(255, 255, 255, .68);
  padding: 12px 10px;
  white-space: nowrap;
  font-size: 14px;
}
.tab:hover, .tab.active { color: white; }
.tab.active { border-bottom-color: var(--brand); }

.top-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.unit-picker select {
  width: auto; max-width: 220px;
  background: rgba(255, 255, 255, .10);
  border: 1px solid rgba(255, 255, 255, .26);
  color: white; font-weight: 700; font-size: 13px;
  padding: 7px 10px; border-radius: var(--r);
}
.unit-picker select option { color: #173a43; background: #fff; }

/* ---------- Botões ---------- */
.button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r);
  padding: 8px 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px;
  font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.button:hover:not(:disabled) { border-color: var(--line-strong); filter: brightness(1.03); }
.button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.button.primary:hover:not(:disabled) { background: var(--brand-strong); }
.button.ok { background: var(--ok); border-color: var(--ok); color: white; }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); border-color: var(--danger-border); background: transparent; }
.button.danger:hover:not(:disabled) { background: var(--danger-bg); }
.button.small { padding: 5px 10px; font-size: 12.5px; min-height: 32px; }
.button.icon { padding: 5px 9px; min-height: 32px; }
.topbar .button.ghost { color: rgba(255, 255, 255, .9); border-color: rgba(255, 255, 255, .24); }
.topbar .button.ghost:hover { background: rgba(255, 255, 255, .10); }
.topbar .button.gestor-on { color: #f3ead3; border-color: var(--brand); background: rgba(150, 139, 102, .25); }

/* ---------- Formulários ---------- */
label, .label {
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  font-size: 11px; font-weight: 700;
}
.field { display: grid; gap: 4px; min-width: 0; }
input, select, textarea {
  width: 100%;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 10px;
  outline: none;
  font-size: 15px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); flex: 0 0 auto; }

/* ---------- Página ---------- */
.page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 64px;
}
.loading, .empty {
  color: var(--muted); text-align: center; padding: 48px 16px;
}
.empty .empty-icon { font-size: 34px; margin-bottom: 6px; }
.empty p { margin: 4px 0; }

.view-header {
  display: flex; justify-content: space-between; gap: 18px; align-items: flex-end;
  flex-wrap: wrap; margin: 0 0 18px;
}
.eyebrow {
  display: block; color: var(--brand); font-size: 11px; font-weight: 800;
  letter-spacing: .09em; text-transform: uppercase; margin-bottom: 4px;
}
.view-header h1 { margin: 0; font-size: 26px; line-height: 1.15; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.stat-grid > .card, .chart-grid > .card, .groups-grid > .card { margin-top: 0; }
.card-pad { padding: 18px; }
.card-title {
  margin: 0 0 12px; font-size: 13px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
}

.toolbar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 14px; margin-bottom: 18px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 10px 28px rgba(14, 58, 69, .06);
}
.toolbar .field { min-width: 150px; }
.toolbar .spacer { flex: 1; }

.notice {
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 16px;
  border-radius: 14px; border: 1px solid var(--warn-border); background: var(--warn-bg);
  font-size: 14px;
}

/* ---------- Contagem ---------- */
.session-bar {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  padding: 16px 18px; margin-bottom: 18px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-2));
  color: white;
  box-shadow: var(--shadow);
}
.session-bar label { color: rgba(255, 255, 255, .62); }
.session-bar input {
  background: rgba(255, 255, 255, .10); border-color: rgba(255, 255, 255, .22); color: white;
  min-width: 160px; color-scheme: dark;
}
.session-bar input::placeholder { color: rgba(255, 255, 255, .4); }
.session-bar .spacer { flex: 1; }
.session-bar .button.ghost { color: white; border-color: rgba(255, 255, 255, .28); }
.session-bar .button.ghost:hover { background: rgba(255, 255, 255, .1); }
.session-progress { font-size: 12px; color: rgba(255, 255, 255, .72); width: 100%; margin-top: -2px; }
.progress-track { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .14); overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--brand); transition: width .3s; }

.start-card { max-width: 520px; margin: 24px auto; padding: 24px; }
.start-card h2 { margin: 0 0 6px; font-size: 20px; }
.start-card .form-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin: 16px 0; }

.groups-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.group-card { overflow: hidden; }
.group-header {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.group-header .resp { font-size: 12px; color: var(--muted); }
.group-header .name { font-size: 15px; font-weight: 750; }
.group-header .actions { display: flex; gap: 6px; }
.group-items { padding: 8px; }
.count-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 10px;
}
.count-row:hover { background: var(--surface-2); }
.count-row .item-name { flex: 1; min-width: 0; font-size: 14px; line-height: 1.3; }
.count-row .item-name small { display: block; color: var(--muted); font-size: 12px; }
.count-input {
  width: 78px; flex: 0 0 auto;
  text-align: center; font-weight: 750; font-size: 16px;
  font-variant-numeric: tabular-nums;
  padding: 7px 6px;
}
.count-input.filled { border-color: var(--ok-border); background: var(--ok-bg); }
.count-input.saving { border-color: var(--warn-border); }
.count-input.error { border-color: var(--danger); background: var(--danger-bg); }
.group-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}

.thumb {
  width: 38px; height: 38px; border-radius: 8px; object-fit: cover; flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--surface-3); cursor: zoom-in;
}
.thumb.lg { width: 64px; height: 64px; border-radius: 12px; }
.thumb-empty {
  display: grid; place-items: center; color: var(--faint); font-size: 16px; cursor: default;
}

/* ---------- Itens ---------- */
.cat-header {
  padding: 10px 18px 6px; font-size: 11px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--brand); background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.item-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
}
.item-row:last-child { border-bottom: none; }
.item-row .item-label { flex: 1; min-width: 0; }
.item-row .item-label small { color: var(--muted); }
.item-row .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.item-row.inativo { opacity: .6; }
.file-button { position: relative; overflow: hidden; }
.file-button input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.new-item {
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: minmax(180px, 2fr) minmax(140px, 1.4fr) minmax(120px, 1fr) auto auto;
  padding: 18px;
}
.photo-drop {
  width: 64px; height: 64px; border-radius: 12px; position: relative; overflow: hidden;
  border: 2px dashed var(--line-strong); display: grid; place-items: center;
  color: var(--muted); font-size: 20px; background: var(--surface-2); cursor: pointer;
}
.photo-drop img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

details.inativos summary { cursor: pointer; padding: 14px 18px; color: var(--muted); font-size: 14px; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; padding: 10px 14px; white-space: nowrap;
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 800;
  color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line-strong);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td small { color: var(--muted); display: block; font-size: 12px; }

.delta-up { color: var(--ok); font-weight: 750; }
.delta-down { color: var(--danger); font-weight: 750; }
.delta-zero { color: var(--muted); }

.pill {
  display: inline-block; border-radius: 999px; padding: 2px 9px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
  background: var(--surface-3); color: var(--muted);
}
.pill.alta { background: var(--danger-bg); color: var(--danger); }
.pill.media { background: var(--warn-bg); color: var(--warn); }
.pill.baixa { background: var(--ok-bg); color: var(--ok); }

/* ---------- Dashboard ---------- */
.stat-grid {
  display: grid; gap: 12px; margin: 0 0 18px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.stat-card { padding: 16px; min-height: 104px; }
.stat-value {
  display: block; color: var(--text); font-size: 26px; line-height: 1.05; font-weight: 850;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.stat-label { display: block; color: var(--muted); font-size: 12px; margin-top: 7px; }
.stat-card small { display: block; font-size: 12px; margin-top: 4px; font-weight: 700; }

.segmented {
  display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background: var(--surface); margin-bottom: 16px; max-width: 100%; overflow-x: auto;
}
.segmented button {
  border: 0; background: transparent; padding: 8px 16px; font-size: 13px; font-weight: 650;
  color: var(--muted); white-space: nowrap; border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--brand-blue); color: white; }

.chart-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 340px; }

/* ---------- Recompra ---------- */
.recompra-table input, .recompra-table select { font-size: 14px; padding: 6px 8px; }
.recompra-table .in-qtd { width: 84px; text-align: right; }
.recompra-table .in-valor { width: 104px; text-align: right; }
.recompra-table .in-urg { width: 124px; }
.recompra-table .in-obs { min-width: 200px; }
.recompra-table .saving { border-color: var(--warn-border); }
.recompra-table .error { border-color: var(--danger); }
.recompra-table .item-cell { display: flex; gap: 10px; align-items: center; min-width: 200px; }

.budget {
  display: flex; flex-wrap: wrap; gap: 22px; align-items: center; justify-content: space-between;
  padding: 18px 22px; margin-top: 16px; border-radius: 18px;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-2));
  color: white; box-shadow: var(--shadow);
}
.budget .b-item { text-align: center; min-width: 110px; }
.budget .b-val { font-size: 24px; font-weight: 850; color: #e7dcb8; font-variant-numeric: tabular-nums; }
.budget .b-lbl { font-size: 11px; color: rgba(255, 255, 255, .65); text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Modal, lightbox, toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 29, 35, .55);
  display: grid; place-items: center; padding: 16px;
}
.modal-card {
  width: min(520px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3); padding: 20px;
}
.modal-card.wide { width: min(760px, 100%); }
.modal-card h3 { margin: 0 0 14px; font-size: 18px; }
.modal-card .field + .field { margin-top: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modal-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 6px; }

.check-list {
  max-height: 300px; overflow-y: auto; margin-top: 8px;
  border: 1px solid var(--line); border-radius: 12px; padding: 4px 8px;
}
.check-cat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px 4px; border-bottom: 1px solid var(--line);
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--brand);
}
.check-cat button { border: 0; background: none; color: var(--blue); font-size: 12px; text-transform: none; letter-spacing: 0; }
.check-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-radius: 8px;
  text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
}
.check-row small { color: var(--muted); }
.check-row:hover { background: var(--surface-2); }

.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .86);
  display: grid; place-items: center; padding: 20px; cursor: zoom-out;
}
.lightbox img { max-width: min(560px, 92vw); max-height: 80vh; border-radius: 12px; object-fit: contain; }
.lightbox .caption { color: rgba(255, 255, 255, .78); text-align: center; margin-top: 10px; font-size: 14px; }

#toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 70;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--brand-blue); color: white; padding: 11px 16px; border-radius: 12px;
  border-left: 4px solid var(--brand); font-size: 14px; max-width: 340px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .25);
  animation: toast-in .2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Responsivo ---------- */
@media (max-width: 980px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
  .tabs { grid-column: 1 / -1; grid-row: 2; margin: 0 -8px -10px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr; }
  .new-item { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .topbar { padding: 8px 12px; grid-template-columns: minmax(0, 1fr) auto; }
  .top-actions { display: contents; }
  .brand { grid-column: 1; grid-row: 1; }
  .brand span > span { display: none; }
  .brand strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #gestor-btn { grid-column: 2; grid-row: 1; padding: 5px 10px; }
  .unit-picker { grid-column: 1 / -1; grid-row: 2; }
  .unit-picker select { width: 100%; max-width: none; }
  .tabs { grid-row: 3; }
  .page { width: calc(100% - 32px); padding-top: 18px; }
  .view-header h1 { font-size: 22px; }
  .groups-grid { grid-template-columns: 1fr; }
  .start-card .form-grid { grid-template-columns: 1fr; }
  .session-bar input { min-width: 0; }
  .session-bar .field { flex: 1 1 140px; }
  .new-item { grid-template-columns: 1fr; }
  .item-row { flex-wrap: wrap; }
  .item-row .actions { width: 100%; justify-content: flex-start; }
  .stat-value { font-size: 20px; }
  .budget { justify-content: center; }
}
