:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-color: #f1f5f9;
  --surface: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #cbd5e1;

  --status-aberto: #64748b;
  --status-pecas: #f59e0b;
  --status-andamento: #3b82f6;
  --status-concluido: #10b981;
  --status-urgente: #ef4444;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Roboto, sans-serif; }
body { background-color: var(--bg-color); color: var(--text-main); overflow-x: hidden; }

/* SEGURANÇA ADMIN */
body:not(.is-admin) .admin-only { display: none !important; }
body.modal-open { overflow: hidden; }

.animate-hover { transition: all 0.2s ease; }
.animate-hover:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08); }
.animate-pop { transition: transform 0.15s ease; }
.animate-pop:active { transform: scale(0.96); }

.spinning-icon { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.screen { display: none; min-height: 100vh; }
#app-screen.active { display: block; }

.input-group { text-align: left; margin-bottom: 14px; width: 100%; }
.input-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.input-group input, .input-group select, .input-group textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; outline: none; background: #f8fafc; font-size: 0.9rem; }
.input-group input:focus, .input-group textarea:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

.btn-primary { background: var(--primary); color: #fff; border: none; border-radius: 10px; font-size: 0.92rem; font-weight: 600; cursor: pointer; width: 100%; padding: 12px; display: flex; justify-content: center; align-items: center; gap: 8px; box-shadow: 0 4px 12px rgba(37,99,235,0.25); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.7; cursor: not-allowed; }

.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); padding: 8px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; font-size: 0.82rem; }
.btn-outline:hover:not(:disabled) { background: #eff6ff; }
.btn-outline:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-icon { background: transparent; border: none; width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-main); transition: 0.2s; }
.btn-icon:hover { background: var(--bg-color); color: var(--primary); }

.app-header { background: var(--surface); padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.header-brand { display: flex; align-items: center; gap: 12px; }
.header-brand span { font-size: 32px; color: var(--primary); }
.header-brand h1 { font-size: 1.2rem; margin-bottom: 2px; }
.header-brand p { font-size: 0.8rem; color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 12px; }

.add-btn { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(37,99,235,0.3); width: auto; padding: 0 16px; border-radius: 20px; font-weight: 600; font-size: 0.9rem; }
.add-btn:hover { background: var(--primary-hover); color: white; }

#top-cards-wrap { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease-out; background-color: var(--bg-color); opacity: 1; }
.collapsible-inner { overflow: hidden; }
.dashboard-cards-container { padding: 15px 20px 5px 20px; max-width: 1200px; margin: 0 auto; }
body.hide-cards #top-cards-wrap { grid-template-rows: 0fr; opacity: 0; }

.dashboard-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 12px; }
.dash-card { background: var(--surface); padding: 12px; border-radius: 12px; display: flex; align-items: center; gap: 12px; border: 2px solid transparent; box-shadow: 0 2px 6px rgba(0,0,0,0.04); cursor: pointer; }
.dash-card.active { border-color: var(--primary); background: #eff6ff; }
.dash-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dash-icon span { font-size: 20px; color: white; }
.dash-info h3 { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.dash-info h2 { font-size: 1.2rem; color: var(--text-main); }
.status-aberto .dash-icon { background: var(--status-aberto); }
.status-pecas .dash-icon { background: var(--status-pecas); }
.status-andamento .dash-icon { background: var(--status-andamento); }
.status-concluido .dash-icon { background: var(--status-concluido); }

.sticky-filters-container { position: sticky; top: 68px; background-color: var(--bg-color); padding: 10px 20px; z-index: 90; border-bottom: 1px solid var(--border); box-shadow: 0 6px 12px -6px rgba(0,0,0,0.06); }
.app-content-inner { max-width: 1200px; margin: 0 auto; }
.filters-bar { display: flex; flex-direction: column; gap: 10px; }
.search-box { display: flex; align-items: center; background: var(--surface); padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); width: 100%; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.search-box input { border: none; padding: 9px 6px; outline: none; width: 100%; background: transparent; font-size: 0.88rem; }
.filter-chips-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.chip { width: 100%; padding: 7px 4px; display: flex; justify-content: center; align-items: center; text-align: center; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 0.78rem; cursor: pointer; white-space: nowrap; gap: 3px; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active, .chip.active-all { background: var(--primary); color: white; border-color: var(--primary); }

.app-content { padding: 15px 20px 40px 20px; max-width: 1200px; margin: 0 auto; width: 100%; }
.os-list { display: flex; flex-direction: column; gap: 16px; }

.os-card { background: var(--surface); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.os-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.os-id { font-family: monospace; font-weight: 800; color: var(--primary); font-size: 0.92rem; display: flex; align-items: center; gap: 5px; }
.badge-prioridade { padding: 4px 8px; border-radius: 10px; font-size: 0.72rem; font-weight: bold; white-space: nowrap; }
.os-titulo { font-size: 1.05rem; color: var(--text-main); line-height: 1.35; font-weight: 600; margin-bottom: 12px; }

.os-meta-grid { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; }
.meta-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.meta-lbl { font-weight: 600; color: var(--text-muted); width: 135px; flex-shrink: 0; }
.meta-val { color: var(--text-main); display: flex; align-items: center; gap: 4px; font-weight: 500; }

.os-card-actions-grid { display: grid; gap: 8px; width: 100%; margin-bottom: 8px; }
.btn-texto-card { padding: 8px 4px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; justify-content: center; gap: 5px; cursor: pointer; font-size: 0.75rem; font-weight: 600; color: var(--text-main); transition: 0.2s; }
.btn-texto-card:hover:not(:disabled) { border-color: var(--primary); background: #eff6ff; color: var(--primary); }

.btn-detalhes-full { background: transparent; color: var(--primary); border: 2px solid var(--primary); padding: 10px; border-radius: 10px; font-size: 0.83rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px; width: 100%; transition: 0.15s; }
.btn-detalhes-full:hover { background: #eff6ff; }
.btn-detalhes-full.primary-style { background: var(--primary); color: white; }
.btn-detalhes-full.primary-style:hover { background: var(--primary-hover); }

.mini-progress-bg { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; display: inline-block; }
.mini-progress-fill { height: 100%; transition: width 0.3s ease; }
.progress-bar-fill { height: 100%; transition: width 0.3s ease; }

/* MODAIS */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65); display: none; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal-overlay.active { display: flex; }
.modal-content { background: var(--surface); width: 95%; max-width: 500px; border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; max-height: 90vh; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); }
.modal-large { max-width: 650px; }
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: #f8fafc; }
.modal-body { padding: 18px; overflow-y: auto; }

/* UPLOAD NA CRIAÇÃO DA OS */
.upload-buttons-row { display: flex; gap: 10px; margin-bottom: 12px; width: 100%; }
.btn-upload-split { flex: 1; justify-content: center; padding: 10px 8px; }
.preview-anexos-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.anexo-item-card { display: flex; align-items: center; justify-content: space-between; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; gap: 10px; }
.anexo-item-info { display: flex; align-items: center; gap: 10px; overflow: hidden; flex: 1; }
.anexo-thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); flex-shrink: 0; }
.anexo-doc-icon { width: 42px; height: 42px; border-radius: 6px; background: #eff6ff; color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.anexo-nome { font-size: 0.8rem; font-weight: 600; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-remover-anexo { background: #fee2e2; color: var(--status-urgente); border: none; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.btn-remover-anexo:hover { background: #fecaca; }

.os-info-grid { display: flex; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 10px; font-size: 0.82rem; color: var(--text-muted); background: var(--bg-color); padding: 10px 12px; border-radius: 8px; }
.action-bar-os-compact { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

/* SUBTAREFAS E COMENTÁRIOS */
.sub-task-item { background: var(--bg-color); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.sub-task-info { flex: 1; min-width: 160px; font-size: 0.85rem; }
.sub-task-actions { display: flex; gap: 6px; }
.btn-sub-acao { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 16px; transition: 0.2s; }
.btn-sub-acao:hover { border-color: var(--primary); transform: scale(1.05); color: var(--primary); }
.btn-sub-acao.ok:hover { border-color: var(--status-concluido); background: #ecfdf5; color: var(--status-concluido); }
.btn-sub-acao.reverter:hover { border-color: #f59e0b; background: #fffbeb; color: #f59e0b; }
.btn-sub-acao.del { color: var(--status-urgente); }
.btn-sub-acao.del:hover { border-color: var(--status-urgente); background: #fef2f2; }

.sub-comentarios-box { margin-top: -6px; margin-bottom: 10px; padding: 8px 10px; background: #ffffff; border: 1px solid var(--border); border-top: none; border-radius: 0 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.comentario-linha { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 6px 8px; background: #f8fafc; border-radius: 8px; font-size: 0.8rem; }
.comentario-texto { flex: 1; line-height: 1.35; word-break: break-word; }
.comentario-acoes { display: flex; gap: 4px; flex-shrink: 0; }
.btn-mini-acao { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.btn-mini-acao:hover:not(:disabled) { background: #e2e8f0; color: var(--primary); }
.btn-mini-acao.del:hover:not(:disabled) { background: #fee2e2; color: var(--status-urgente); }

.loading-state { text-align: center; padding: 25px; color: var(--text-muted); width: 100%; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top: 3px solid var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; margin: 0 auto 8px; }

@media (max-width: 768px) {
  .app-header { padding: 10px 14px; flex-wrap: wrap; }
  .header-brand h1 { font-size: 1.05rem; margin-bottom: 0; }
  .add-btn { padding: 0 10px; }
  .add-btn-text { display: none; }
  .sticky-filters-container { padding: 10px 12px 8px 12px; top: 60px; }
  .dashboard-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .dash-card { padding: 8px 10px; gap: 8px; }
  .os-card-actions-grid { grid-template-columns: 1fr; }
  .upload-buttons-row { flex-direction: column; }
}