/* ============================================================================
   PSM-OS v2 — App styles (componentes base)
============================================================================ */

/* ─── Layout ──────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  min-height: 100vh;
}
.app-header  { grid-area: header;  background: var(--bg-2); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 var(--s-5); gap: var(--s-4); z-index: var(--z-header); }
.app-sidebar { grid-area: sidebar; background: var(--psm-navy); color: var(--ink-inverted); padding: var(--s-4); overflow-y: auto; }
.app-main    { grid-area: main;    padding: var(--s-6); overflow-y: auto; background: var(--bg); }

/* ─── Hamburger button (mobile only) ─────────────────────────────────── */
.h-hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 22px; padding: 6px 10px; border-radius: var(--r-sm);
  color: var(--ink);
}
.h-hamburger:hover { background: var(--bg-3); }

/* ─── Backdrop (overlay quando drawer aberto) ───────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 95;
}

/* ─── Mobile (≤ 768px) ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas: "header" "main";
  }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    max-width: 80vw;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }
  .app-sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .h-hamburger { display: inline-flex; }

  .app-header { padding: 0 var(--s-3); gap: var(--s-2); }
  .h-title { font-size: var(--fs-base); }
  .h-user { gap: var(--s-2); }
  .h-user span { display: none; }                  /* esconde nome */
  .h-user .h-avatar { width: 28px; height: 28px; font-size: var(--fs-xs); }
  .h-user .btn { padding: 4px 8px; font-size: var(--fs-xs); }

  .app-main { padding: var(--s-3); }

  .card { padding: var(--s-3); }
  .card-title { font-size: var(--fs-base); }

  /* Tabelas: scroll horizontal */
  table { font-size: 11px; }
  .card > div[style*="overflow-x"] { margin: 0 calc(var(--s-3) * -1); padding: 0 var(--s-3); }

  /* KPI cards: stack em 2 colunas */
  .flex.gap-3[style*="flex-wrap"] > div[style*="min-width"] { min-width: calc(50% - 12px) !important; }

  /* Modal: full-width quase total */
  [class="card"][style*="max-width:520px"],
  [class*="card"][style*="max-width:560px"] { max-width: 100% !important; max-height: 95vh !important; }

  /* Drawer de notificações: ajusta largura */
  #notif-badge { font-size: 9px !important; }
}

@media (max-width: 480px) {
  .app-main { padding: var(--s-2); }
  .card { padding: var(--s-3); border-radius: var(--r-md); }
  .h-title { font-size: var(--fs-sm); font-weight: 800; }
  /* KPI cards: stack em 1 coluna */
  .flex.gap-3[style*="flex-wrap"] > div[style*="min-width"] { min-width: 100% !important; }
}

/* ─── Print (global) — Sprint 8.x ─────────────────────────────────── */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .app-sidebar, .app-header, .no-print, #notif-drawer { display: none !important; }
  .app-main { padding: 0 !important; margin: 0 !important; }
  .app-shell { display: block !important; }
  .card, .print-area { box-shadow: none !important; background: #fff !important; color: #000 !important; padding: 0 !important; border: none !important; }
  h1, h2, h3, .card-title { color: #0b1f3a !important; }
  table { page-break-inside: auto; width: 100% !important; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  a { color: #0b1f3a !important; text-decoration: none !important; }
  button, .btn { display: none !important; }
  @page { margin: 1.2cm; }
}

/* ─── Mobile: stack 2-col grids fixos (Sprint 8) ────────────────────── */
@media (max-width: 768px) {
  /* Padrões "320px 1fr" e similares dos simuladores/painéis stack vertical */
  [style*="grid-template-columns:320px"],
  [style*="grid-template-columns: 320px"],
  [style*="grid-template-columns:300px"],
  [style*="grid-template-columns: 300px"] {
    grid-template-columns: 1fr !important;
  }
  /* Grids de KPI em 4 colunas: 2 colunas em mobile */
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  /* Tabelas com min-width grandes: scroll horizontal */
  table[style*="min-width"] {
    font-size: 11px !important;
  }
}

/* ─── Sidebar nav ─────────────────────────────────────────────────────── */
.sb-brand { font-weight: 800; font-size: var(--fs-lg); letter-spacing: 1px; padding: var(--s-2) var(--s-3); margin-bottom: var(--s-4); }
.sb-sec   {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--psm-gold);
  font-weight: 700;
  padding: 14px 12px 6px;
  margin-top: 4px;
  border-top: 1px solid rgba(212,168,67,0.15);
  background: rgba(0,0,0,0.15);
}
.sb-sec:first-of-type { border-top: none; margin-top: 0; padding-top: 6px; }
.sb-link  {
  display: flex; align-items: center; gap: var(--s-2);
  padding: 7px 12px;
  color: rgba(255,255,255,0.78);
  border-radius: var(--r-sm);
  font-size: 13px;
  cursor: pointer; background: none; border: none;
  width: 100%; text-align: left;
  margin: 1px 0;
}
.sb-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sb-link.on    { background: rgba(212,168,67,0.18); color: var(--psm-gold); font-weight: 700; border-left: 3px solid var(--psm-gold); padding-left: 9px; }
.sb-ico   { width: 18px; display: inline-flex; justify-content: center; }

/* ─── Header ──────────────────────────────────────────────────────────── */
.h-title { font-weight: 700; font-size: var(--fs-lg); color: var(--ink); }
.h-spacer { flex: 1; }
.h-user  { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-sm); }
.h-avatar { width: 32px; height: 32px; border-radius: var(--r-full); background: var(--psm-gold); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: var(--fs-sm); }

/* ─── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s-4); }
.card-title {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 var(--s-3);
  display: flex; align-items: center; gap: var(--s-2);
}
.card-sub {
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  margin-bottom: var(--s-4);
}

/* ─── Forms ───────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-4); }
.field label { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.input, .select, .textarea {
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-base);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  background: var(--bg-3);
  color: var(--ink);
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--psm-navy); color: var(--ink-inverted); }
.btn-primary:hover { background: var(--psm-navy-2); }

.btn-gold { background: var(--psm-gold); color: var(--psm-navy); }
.btn-gold:hover { background: var(--psm-gold-2); color: var(--ink-inverted); }

.btn-danger { background: var(--err); color: #fff; }
.btn-ghost  { background: transparent; border-color: var(--border-2); }

.btn-block { width: 100%; justify-content: center; }
.btn-lg    { padding: var(--s-3) var(--s-5); font-size: var(--fs-base); }

/* ─── Login screen ────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(circle at 30% 20%, rgba(212,168,67,0.15), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(59,130,246,0.10), transparent 50%),
    var(--psm-navy);
}
.login-card {
  background: var(--bg-2);
  border-radius: var(--r-xl);
  padding: var(--s-8);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  text-align: center;
  margin-bottom: var(--s-6);
}
.login-brand h1 {
  margin: 0;
  font-size: var(--fs-3xl);
  letter-spacing: 2px;
  color: var(--psm-navy);
}
.login-brand p {
  margin: var(--s-1) 0 0;
  font-size: var(--fs-sm);
  color: var(--ink-muted);
  letter-spacing: 1px;
}

/* ─── Utilities ──────────────────────────────────────────────────────── */
.muted   { color: var(--ink-muted); }
.tiny    { font-size: var(--fs-xs); }
.mt-2    { margin-top: var(--s-2); }
.mt-3    { margin-top: var(--s-3); }
.mt-4    { margin-top: var(--s-4); }
.mt-6    { margin-top: var(--s-6); }
.flex    { display: flex; }
.flex-col{ display: flex; flex-direction: column; }
.gap-2   { gap: var(--s-2); }
.gap-3   { gap: var(--s-3); }
.gap-4   { gap: var(--s-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }

.alert {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
}
.alert-err  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-ok   { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-warn { background: #fef3c7; color: #78350f; border: 1px solid #fde68a; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--info);
  border-radius: var(--r-full);
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
