/* ============================================================================
   GESTIND — Sistema de Design
   Paleta: painel de controlo industrial. Grafite escuro + âmbar de segurança.
   Tipografia: Space Grotesk (títulos, técnica/geométrica) + IBM Plex Sans
   (corpo) + IBM Plex Mono (dados, códigos, quantidades).
   Assinatura visual: o "dial" (mostrador analógico) usado nos indicadores
   de estado — eco direto aos manómetros e controladores com que a equipa
   trabalha no terreno.
============================================================================ */

:root {
  --ink-900: #0D1216;
  --ink-800: #161D22;
  --ink-750: #1B242A;
  --ink-700: #212B32;
  --ink-600: #2C3941;
  --line: #2A353D;
  --steel-400: #7C93A3;
  --steel-300: #9AAEBB;
  --paper: #EDEAE1;
  --paper-dim: #C9C4B6;

  --amber: #F2A93B;
  --amber-dim: #C98A2C;
  --azure: #5B8DBE;
  --teal: #4CA98A;
  --rust: #D2572D;

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-lift: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink-900);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--amber); }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.muted { color: var(--steel-400); }
.small { font-size: 0.82rem; }

/* ---- Offline banner --------------------------------------------------- */
#offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: var(--rust); color: #1a0d06;
  font-weight: 600; font-size: 0.85rem;
  text-align: center; padding: 8px 16px;
  transform: translateY(-100%);
  transition: transform 0.25s ease;
}
#offline-banner.show { transform: translateY(0); }

/* ---- Toasts ------------------------------------------------------------ */
.toast-wrap {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  z-index: 10000; display: flex; flex-direction: column; gap: 8px;
  width: min(420px, 92vw);
  pointer-events: none;
}
.toast {
  background: var(--ink-700); border: 1px solid var(--line);
  color: var(--paper); padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 0.9rem;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--teal); }
.toast-danger { border-color: var(--rust); }

/* ---- Login -------------------------------------------------------------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(242,169,59,0.08), transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(91,141,190,0.08), transparent 45%),
    var(--ink-900);
}
.login-form {
  width: min(380px, 100%);
  background: var(--ink-800); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow-lift);
}
.login-mark { text-align: center; margin-bottom: 8px; }
.login-gear {
  font-size: 2rem; color: var(--amber); display: inline-block;
  animation: spin 12s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-mark h1 { font-size: 1.5rem; margin-top: 8px; }
.login-mark p { color: var(--steel-400); font-size: 0.85rem; margin-top: 2px; }
.login-hint { text-align: center; font-size: 0.78rem; color: var(--steel-400); }
.error-detail {
  background: var(--ink-750); border: 1px solid var(--rust); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font-mono); font-size: 0.78rem; color: var(--paper-dim);
  white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow-y: auto;
}

/* ---- Fields / forms ------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--steel-300); }
.field > span { font-weight: 500; }
input, select, textarea {
  background: var(--ink-750); border: 1px solid var(--line); color: var(--paper);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.92rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--amber); }
textarea { resize: vertical; }
.form-grid { display: flex; flex-direction: column; gap: 14px; }
.inline-form { display: flex; gap: 8px; margin: 10px 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin: 6px 0; }
.checkbox-row input { width: auto; }

/* ---- Buttons -------------------------------------------------------------- */
.btn {
  border: 1px solid var(--line); background: var(--ink-700); color: var(--paper);
  border-radius: var(--radius-sm); padding: 10px 16px; font-size: 0.88rem; font-weight: 500;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--amber); color: #251705; border-color: var(--amber); font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.icon-btn {
  background: transparent; border: none; color: var(--steel-300);
  font-size: 1rem; padding: 4px 8px; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--ink-700); color: var(--paper); }

/* ---- Shell / layout -------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--ink-800); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 20px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; padding: 0 6px; }
.brand-gear { color: var(--amber); }
.sidebar-links { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px; background: transparent; border: none;
  color: var(--steel-300); padding: 10px 12px; border-radius: var(--radius-sm); text-align: left; font-size: 0.9rem;
}
.nav-link:hover { background: var(--ink-750); color: var(--paper); }
.nav-link.active { background: var(--ink-700); color: var(--amber); font-weight: 600; }
.nav-icon { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-footer { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--amber); color: #251705;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.user-chip div { display: flex; flex-direction: column; line-height: 1.2; overflow: hidden; }
.user-chip strong { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip span { font-size: 0.72rem; color: var(--steel-400); }

.main { flex: 1; min-width: 0; }
.view-container { padding: 28px 32px 100px; max-width: 1180px; margin: 0 auto; }

.bottom-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .view-container { padding: 18px 16px 96px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 500;
    background: var(--ink-800); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav .nav-link { flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 0.65rem; }
  .nav-label-sm { font-size: 0.65rem; }
}

/* ---- View head -------------------------------------------------------------- */
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head h2 { font-size: 1.4rem; }
.view-head p { color: var(--steel-400); font-size: 0.88rem; margin-top: 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Dashboard -------------------------------------------------------------- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 24px; }
.dash-card {
  background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; align-items: center; gap: 16px;
  min-width: 0; /* impede que o conteúdo force o cartão a alargar e transborde para o vizinho */
  overflow: hidden;
}
.dash-card > div:last-child { min-width: 0; } /* permite que o texto encolha e faça wrap em vez de transbordar */
.dash-card h4 { font-size: 0.95rem; overflow-wrap: break-word; }
.dash-card p { color: var(--steel-400); font-size: 0.8rem; margin-top: 4px; overflow-wrap: break-word; }

.panel { background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.panel h3 { font-size: 1rem; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.count-pill {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--steel-400);
  background: var(--ink-750); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px;
}

.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--ink-750); border-radius: var(--radius-sm); font-size: 0.85rem; }
.mini-title { font-weight: 500; flex: 1; }
.mini-sub { color: var(--steel-400); font-size: 0.78rem; }
.mini-date { font-family: var(--font-mono); font-size: 0.78rem; color: var(--steel-300); }

/* ---- Gauge (elemento de assinatura) ------------------------------------------ */
.gauge { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.gauge-svg { flex-shrink: 0; }
.gauge-track { fill: none; stroke: var(--ink-600); stroke-width: 6; stroke-linecap: round; }
.gauge-fill { fill: none; stroke-width: 6; stroke-linecap: round; }
.gauge-needle { stroke: var(--paper); stroke-width: 2; }
.gauge-hub { fill: var(--paper); }
.gauge-label { display: flex; flex-direction: column; font-family: var(--font-mono); }
.gauge-label strong { font-size: 1.3rem; font-family: var(--font-display); }
.gauge-label span { font-size: 0.72rem; color: var(--steel-400); }
.st-emdia .gauge-fill, .st-emdia { color: var(--teal); }
.st-avencer .gauge-fill, .st-avencer { color: var(--amber); }
.st-atrasado .gauge-fill, .st-atrasado { color: var(--rust); }
.st-info .gauge-fill, .st-info { color: var(--azure); }
.st-neutro .gauge-fill, .st-neutro { color: var(--steel-400); }
.gauge-fill { stroke: currentColor; }

/* ---- Status dots / badges ------------------------------------------------------ */
.dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  background: var(--ink-700); color: var(--steel-300); border: 1px solid var(--line);
}
.badge.st-emdia { color: var(--teal); border-color: var(--teal); }
.badge.st-avencer { color: var(--amber); border-color: var(--amber); }
.badge.st-atrasado { color: var(--rust); border-color: var(--rust); }
.badge.st-info { color: var(--azure); border-color: var(--azure); }

/* ---- Filter bar ------------------------------------------------------------------ */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-input { max-width: 220px; }

/* ---- Cards / lists ------------------------------------------------------------------ */
.card-list { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-actions { display: flex; align-items: center; gap: 8px; }
.plano-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.plano-row { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--ink-750); border-radius: var(--radius-sm); flex-wrap: wrap; }
.plano-info { display: flex; flex-direction: column; flex: 1; min-width: 140px; }
.row-actions { display: flex; gap: 6px; }

.avaria-card p { margin: 8px 0; font-size: 0.9rem; line-height: 1.5; }
.foto-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.foto-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); }

/* ---- Tables ------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th { text-align: left; padding: 12px 14px; color: var(--steel-400); font-weight: 500; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--line); }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--ink-750); font-family: var(--font-mono); font-size: 0.84rem; }
.data-table tbody tr:hover { background: var(--ink-750); cursor: pointer; }
.data-table tbody tr:last-child td { border-bottom: none; }
.truncate-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Tabs ---------------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tab-btn { background: transparent; border: none; color: var(--steel-400); padding: 10px 16px; font-size: 0.88rem; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--amber); border-color: var(--amber); font-weight: 600; }

/* ---- Empty state --------------------------------------------------------------------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--steel-400); }
.empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.5; }
.empty-sub { font-size: 0.8rem; margin-top: 4px; }

/* ---- Modal --------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(6,9,11,0.72); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 20px;
}
.modal {
  width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--ink-800); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--ink-800); }
.modal-head h3 { font-size: 1.05rem; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--ink-800); }

/* ---- Tarefas / anexos ------------------------------------------------------------------ */
.tarefa-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.tarefa-item { background: var(--ink-750); border-radius: var(--radius-sm); padding: 12px; }
.tarefa-item-head { display: flex; align-items: center; justify-content: space-between; }
.anexo-list { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.anexo-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--ink-700); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 0.75rem; color: var(--paper); text-decoration: none; }
.checklist-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 0.88rem; }
.checklist-row input { width: auto; }

/* ---- Técnico selector ------------------------------------------------------------------ */
.tecnico-select { display: flex; gap: 8px; flex-wrap: wrap; }
.tecnico-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--ink-750); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; cursor: pointer; }
.tecnico-chip input { width: auto; }
.tecnico-chip.checked { background: var(--amber); color: #251705; border-color: var(--amber); font-weight: 600; }

/* ---- Materiais (intervenções) ------------------------------------------------------------ */
.materiais-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.material-row { display: flex; gap: 8px; align-items: center; }
.material-row select { flex: 1; }

/* ---- Import preview ------------------------------------------------------------------------ */
.import-preview-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; margin-top: 10px; }
.import-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--ink-750); border-radius: var(--radius-sm); font-size: 0.85rem; }
.import-row select { max-width: 160px; margin-left: auto; }
.tag { font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.tag-new { background: rgba(76,169,138,0.15); color: var(--teal); }
.tag-dup { background: rgba(242,169,59,0.15); color: var(--amber); }

/* ---- Detail grid (modal de detalhe) ---------------------------------------------------------- */
.detail-grid { display: flex; flex-direction: column; gap: 12px; }
.detail-row { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--ink-750); font-size: 0.9rem; }
.detail-row:last-child { border-bottom: none; }

/* ---- Horários ------------------------------------------------------------------------ */
.horarios-table th, .horarios-table td { white-space: pre-line; text-align: center; padding: 6px 4px; font-size: 0.72rem; }
.horarios-table td:first-child, .horarios-table th:first-child { text-align: left; white-space: nowrap; padding-right: 12px; }
.horarios-table .weekend-col { background: rgba(210,87,45,0.06); }
.horarios-table .day-error { background: rgba(210,87,45,0.16); }
.horario-cell-select { padding: 2px 2px; font-size: 0.68rem; width: 62px; }
