/* ============================================================
   GLOBAL.CSS
   Reset, design system (variáveis), tipografia e componentes
   reutilizados em todas as páginas (index, admin, funcionário).
   ============================================================ */

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

ul,
ol {
  list-style: none;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- Design system ---------- */
:root {
  --color-primary: #d62828;
  --color-primary-dark: #b21f1f;
  --color-secondary: #2b2118;
  --color-background: #f7f5f2;
  --color-surface: #ffffff;
  --color-text: #23201d;
  --color-muted: #706a63;
  --color-border: #e7e2db;
  --color-success: #2e7d32;
  --color-success-bg: #e8f5e9;
  --color-danger: #c62828;
  --color-danger-bg: #fdecea;
  --color-warning: #b8860b;

  --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-secondary: Georgia, 'Times New Roman', serif;

  --container-width: 1120px;
  --section-spacing: 1.5rem;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(35, 32, 29, 0.06);
  --shadow-md: 0 4px 16px rgba(35, 32, 29, 0.08);

  --transition-fast: 120ms ease;
  --transition-normal: 220ms ease;
  --transition-slow: 380ms ease;

  --touch-target: 44px;
}

/* ---------- Tipografia ---------- */
h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-secondary);
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

.text-muted { color: var(--color-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--container-width);
  margin-inline: auto;
  padding-inline: 1rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--touch-target);
  padding: 0.65rem 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn--secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--color-primary);
}

.btn--danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.btn--danger:hover:not(:disabled) {
  background: var(--color-danger);
  color: #fff;
}

.btn--ghost {
  background: transparent;
  color: var(--color-muted);
}

.btn--ghost:hover:not(:disabled) {
  color: var(--color-text);
}

.btn--sm {
  min-height: 36px;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
}

.btn--block {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem;
  min-height: var(--touch-target);
}

/* ---------- Formulários ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-secondary);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch-target);
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: 1rem;
  transition: border-color var(--transition-fast);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--color-primary);
}

.field textarea {
  min-height: 80px;
  resize: vertical;
}

.field-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.field-row .field {
  flex: 1 1 140px;
}

.field-error {
  color: var(--color-danger);
  font-size: 0.85rem;
  background: var(--color-danger-bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
}

.field-success {
  color: var(--color-success);
  font-size: 0.85rem;
  background: var(--color-success-bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
}

/* ---------- Stepper de quantidade ---------- */
.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stepper button {
  width: var(--touch-target);
  height: var(--touch-target);
  background: var(--color-surface);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-primary);
}

.stepper button:hover {
  background: var(--color-background);
}

.stepper input {
  width: 3.5rem;
  height: var(--touch-target);
  text-align: center;
  border: none;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.app-header__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.85rem;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.app-header__brand h1 {
  font-size: 1.05rem;
}

.app-header__period {
  font-size: 0.8rem;
  color: var(--color-muted);
}

/* ---------- Navegação (admin) ---------- */
.app-nav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding-block: 0.4rem 0.7rem;
  -webkit-overflow-scrolling: touch;
}

.app-nav button {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-muted);
  white-space: nowrap;
}

.app-nav button.is-active {
  background: var(--color-primary);
  color: #fff;
}

/* ---------- Toast (feedback) ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 2rem);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--color-secondary);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
  z-index: 100;
}

.toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast--success { background: var(--color-success); }
.toast--error { background: var(--color-danger); }

/* ---------- Loading ---------- */
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem 1rem;
  color: var(--color-muted);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Estado vazio ---------- */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-muted);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(35, 32, 29, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal__close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--color-muted);
  padding: 0.4rem;
}

/* ---------- Tabela responsiva (vira cards no mobile) ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.data-table th {
  color: var(--color-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.record-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--color-border);
}

.record-card__title {
  font-weight: 600;
}

.record-card__meta {
  font-size: 0.82rem;
  color: var(--color-muted);
}

.record-card__value {
  font-weight: 700;
  color: var(--color-secondary);
  text-align: right;
}

.record-card__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
