:root {
  /* Palete de Cinzas Grafite / Neutros */
  --bg-page: #121214;
  --bg-surface: #1b1c1f;
  --bg-surface-alt: #232529;
  --bg-input: #16171a;
  --bg-input-hover: #1e2024;

  --border-subtle: #2e3036;
  --border-strong: #43464f;
  --border-focus: #a1a1aa;

  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  /* Acentos em Cinza Claro / Prata */
  --accent: #e4e4e7;
  --accent-hover: #ffffff;
  --accent-text: #121214;

  /* Estados */
  --success-bg: rgba(34, 197, 94, 0.12);
  --success-border: rgba(34, 197, 94, 0.35);
  --success-text: #86efac;

  --error-bg: rgba(239, 68, 68, 0.12);
  --error-border: rgba(239, 68, 68, 0.35);
  --error-text: #fca5a5;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --tap-min: 46px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: rgba(228, 228, 231, 0.14);
}

html,
body {
  min-height: 100%;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app-shell,
.container,
main {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 0.9rem 5.5rem;
}

/* Cabeçalho adaptado a mobile */
header,
.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
  margin-bottom: 1.15rem;
}

header h1,
.brand h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

header p,
.brand p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.header-actions,
.topbar-actions,
.lang-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

/* Cartões / Painéis */
.card,
.panel,
section.box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  margin-bottom: 1rem;
}

.subcard,
.inner-box,
.role-banner {
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 1rem;
}

h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

p.muted,
.subtitle,
.help-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

hr,
.divider {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 1rem 0;
}

/* Cabeçalho do Utilizador Autenticado */
.user-header,
.session-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.view-switcher {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

/* Formulários (16px evita zoom automático no telemóvel) */
form {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  margin-top: 0.85rem;
}

.form-group,
.field {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}

label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="time"],
input[type="search"],
textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0.78rem 0.95rem;
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input:hover,
textarea:hover {
  border-color: var(--border-strong);
  background-color: var(--bg-input-hover);
}

input:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(161, 161, 170, 0.18);
}

/* Selects estilizados em cinza escuro e confortáveis ao toque */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  min-height: var(--tap-min);
  padding: 0.78rem 2.6rem 0.78rem 0.95rem;
  font-family: inherit;
  font-size: 16px;
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 18px;
}

select:hover {
  border-color: var(--border-strong);
  background-color: var(--bg-input-hover);
}

select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(161, 161, 170, 0.18);
}

select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

header select,
.topbar select,
.view-switcher select {
  min-width: 96px;
  min-height: 42px;
  padding: 0.55rem 2.2rem 0.55rem 0.8rem;
  font-size: 0.95rem;
}

/* Botões com área de toque generosa */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap-min);
  padding: 0.78rem 1.15rem;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--accent-text);
  background-color: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.18s ease, transform 0.08s ease, border-color 0.18s ease;
}

button:hover,
.btn:hover {
  background-color: var(--accent-hover);
}

button:active,
.btn:active {
  transform: scale(0.99);
}

button:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary,
.btn-secondary,
header button,
.topbar button {
  min-height: 44px;
  padding: 0.6rem 0.95rem;
  font-size: 0.92rem;
  color: var(--text-primary);
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-strong);
}

button.secondary:hover,
.btn-secondary:hover,
header button:hover,
.topbar button:hover {
  background-color: #2e3036;
  border-color: var(--text-secondary);
}

/* Mensagens de Estado / Feedback */
.status-bar,
.status-box,
.message {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-top: 1rem;
}

.status-ok,
.success {
  background-color: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.status-error,
.error {
  background-color: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

/* Backoffice da Empresa — Mobile-First */
.backoffice-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 0.85rem;
}

.backoffice-span-2 {
  grid-column: auto;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.inline-actions > button {
  flex: 1 1 auto;
}

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.7rem;
  min-height: var(--tap-min);
  padding: 0.35rem 0;
}

.checkbox-row input[type="checkbox"] {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-row label {
  margin: 0;
  cursor: pointer;
  font-size: 0.96rem;
  color: var(--text-primary);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 1rem;
}

.list-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.list-item-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  flex: 1;
}

.list-item-title {
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.list-item-sub {
  font-size: 0.88rem;
  color: var(--text-secondary);
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: 999px;
  background-color: var(--bg-surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.shift-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.btn-sm {
  min-height: 44px;
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
}

.order-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-strong);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Utilitários */
.hidden {
  display: none !important;
}

/* Ajustes para ecrãs maiores (tablet / desktop) */
@media (min-width: 768px) {
  .app-shell,
  .container,
  main {
    padding: 1.5rem 1.25rem 3rem;
  }

  header,
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
  }

  .header-actions,
  .topbar-actions,
  .lang-bar {
    justify-content: flex-end;
  }

  .card,
  .panel,
  section.box {
    padding: 1.5rem;
    margin-bottom: 1.25rem;
  }

  .user-header,
  .session-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .view-switcher {
    flex-direction: row;
    align-items: center;
  }

  .inline-actions > button {
    flex: 0 0 auto;
  }

  .list-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .backoffice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
  }

  .backoffice-span-2 {
    grid-column: 1 / -1;
  }

  .shift-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}