/* ============================================================
   FICHAS TÉCNICAS — Sistema de design v3.1 (responsivo)
   Estética: editorial / speakeasy / dourado envelhecido
   Estratégia: mobile-first, 4 breakpoints reais
   ============================================================
   BREAKPOINTS:
     mobile          → até 599px    (1 coluna, bottom nav)
     tablet portrait → 600px-899px  (2 colunas, sidebar drawer)
     tablet land.    → 900px-1199px (sidebar fixa estreita)
     desktop         → 1200px+      (sidebar fixa larga + conforto)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-base:        #0d0c0a;
  --bg-elevated:    #16140f;
  --bg-card:        #1c1914;
  --bg-hover:       #252118;
  --border:         #2d2820;
  --border-strong:  #4a4131;
  --text-primary:   #f4ede0;
  --text-secondary: #a39580;
  --text-tertiary:  #6b6354;
  --accent:         #c9a96e;
  --accent-hover:   #d4b87e;
  --accent-muted:   #8c7649;
  --success:        #7d9e6a;
  --warning:        #d4a04c;
  --danger:         #b04b3f;
  --info:           #6a8da3;

  --font-display:   'Cormorant Garamond', Georgia, serif;
  --font-body:      'Inter Tight', system-ui, sans-serif;
  --font-mono:      'JetBrains Mono', 'Courier New', monospace;

  /* Tipografia fluida */
  --fs-xs:    clamp(0.6875rem, 0.65rem + 0.2vw, 0.75rem);
  --fs-sm:    clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --fs-base:  clamp(0.875rem, 0.825rem + 0.25vw, 0.9375rem);
  --fs-md:    clamp(0.9375rem, 0.9rem + 0.25vw, 1rem);
  --fs-lg:    clamp(1.125rem, 1rem + 0.5vw, 1.25rem);
  --fs-xl:    clamp(1.25rem, 1.125rem + 0.5vw, 1.5rem);
  --fs-2xl:   clamp(1.5rem, 1.25rem + 1vw, 1.75rem);
  --fs-3xl:   clamp(1.875rem, 1.5rem + 1.5vw, 2.5rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --sidebar-w: 0px;
  --main-padding: var(--space-4);
  --main-padding-y: var(--space-5);
  --bottom-nav-h: 64px;
  --touch-min: 44px;

  --shadow-sm:   0 1px 2px rgba(0,0,0,.4);
  --shadow-md:   0 4px 12px rgba(0,0,0,.5);
  --shadow-lg:   0 20px 40px rgba(0,0,0,.6), 0 0 0 1px var(--border);
  --shadow-glow: 0 0 24px rgba(201,169,110,.15);

  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 8px;
}

@media (min-width: 600px) {
  :root { --main-padding: var(--space-5); --main-padding-y: var(--space-6); --touch-min: 40px; }
}
@media (min-width: 900px) {
  :root { --sidebar-w: 220px; --main-padding: var(--space-6); --bottom-nav-h: 0px; --touch-min: 36px; }
}
@media (min-width: 1200px) {
  :root { --sidebar-w: 260px; --main-padding: var(--space-7); }
}

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

html {
  background: var(--bg-base);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(201,169,110,.04) 0%, transparent 50%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(176,75,63,.03) 0%, transparent 50%),
    var(--bg-base);
  background-attachment: fixed;
  color: var(--text-primary);
  font-size: var(--fs-base);
  line-height: 1.6;
  letter-spacing: 0.01em;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  opacity: 0.4;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

img, svg { max-width: 100%; height: auto; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ============================================================
   TIPOGRAFIA
   ============================================================ */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
h1 { font-size: var(--fs-3xl); font-weight: 400; font-style: italic; line-height: 1.1; }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); font-weight: 600; }
h4 {
  font-size: var(--fs-sm); font-weight: 600; font-family: var(--font-body);
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary);
}

.eyebrow {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.mono { font-family: var(--font-mono); }
.italic { font-style: italic; }
.muted { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

/* ============================================================
   LAYOUT — Mobile first
   ============================================================ */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  z-index: 2;
}

.sidebar { display: contents; }

.sidebar .brand {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--main-padding);
  padding-top: calc(var(--space-3) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.sidebar .brand .mark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: var(--fs-xl);
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent) 30%, var(--accent-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.sidebar .brand .sub { display: none; }

.sidebar .bar-selector {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 1 auto;
  min-width: 0;
}
.sidebar .bar-selector .label { display: none; }
.sidebar .bar-selector select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: var(--space-2) var(--space-7) var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: var(--fs-sm);
  min-height: var(--touch-min);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23c9a96e'><path d='M2 4 L6 8 L10 4 Z'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  max-width: 180px;
  text-overflow: ellipsis;
}

/* Bottom nav no mobile */
.sidebar nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: var(--space-2);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-1);
  box-shadow: 0 -8px 24px rgba(0,0,0,.3);
}

.sidebar nav .section { display: none; }

.sidebar nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-2) var(--space-1);
  min-height: var(--touch-min);
  color: var(--text-tertiary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease;
  text-align: center;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.sidebar nav a:hover, .sidebar nav a:active { color: var(--text-primary); }
.sidebar nav a.active { color: var(--accent); }
.sidebar nav a.active::before {
  content: "";
  position: absolute; top: 0; left: 25%; right: 25%;
  height: 2px; background: var(--accent);
}

.sidebar nav a .icon { font-size: 1.25rem; line-height: 1; }
.sidebar nav a .label-text {
  font-size: 10px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Esconder secundários no mobile */
.sidebar nav a.nav-secondary { display: none; }

/* ---------- Tablet portrait ---------- */
@media (min-width: 600px) {
  .sidebar nav a .label-text { font-size: 11px; }
  .sidebar .brand { padding: var(--space-4) var(--main-padding); }
}

/* ---------- Tablet landscape e desktop ---------- */
@media (min-width: 900px) {
  .app {
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: 1fr;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    grid-row: 1;
    grid-column: 1;
    height: 100vh;
    height: 100dvh;
    position: sticky;
    top: 0;
    overflow-y: auto;
  }

  .sidebar .brand {
    position: static;
    flex-direction: column;
    align-items: flex-start;
    padding: var(--space-5) var(--space-5);
    gap: var(--space-1);
    padding-top: var(--space-5);
  }
  .sidebar .brand .mark { font-size: 1.5rem; }
  .sidebar .brand .sub {
    display: block;
    font-size: var(--fs-xs);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-tertiary);
  }

  .sidebar .bar-selector {
    order: 99;
    margin-top: auto;
    padding: var(--space-5);
    border-top: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }
  .sidebar .bar-selector .label {
    display: block;
    font-size: var(--fs-xs);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-tertiary);
  }
  .sidebar .bar-selector select { max-width: none; }

  .sidebar nav {
    position: static;
    display: block;
    background: transparent;
    border-top: none;
    box-shadow: none;
    padding: var(--space-3);
    flex: 1;
  }

  .sidebar nav .section {
    display: block;
    font-size: 0.625rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    padding: var(--space-4) var(--space-3) var(--space-2);
  }

  .sidebar nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    text-align: left;
    min-height: 0;
  }

  .sidebar nav a:hover { background: var(--bg-hover); }
  .sidebar nav a.active {
    background: linear-gradient(90deg, rgba(201,169,110,.08) 0%, transparent 100%);
  }
  .sidebar nav a.active::before {
    top: 20%; left: 0; right: auto; bottom: 20%;
    width: 2px; height: auto;
  }
  .sidebar nav a .icon {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    opacity: 0.85;
  }
  .sidebar nav a .label-text { font-size: var(--fs-sm); }
  .sidebar nav a.nav-secondary { display: flex; }
}

/* ============================================================
   MAIN
   ============================================================ */

main {
  padding: var(--main-padding-y) var(--main-padding);
  padding-bottom: calc(var(--main-padding) + var(--bottom-nav-h) + env(safe-area-inset-bottom));
  max-width: 100%;
  overflow-x: hidden;
}

@media (min-width: 900px) {
  main {
    grid-row: 1;
    grid-column: 2;
    padding-bottom: var(--main-padding);
    max-width: 1400px;
  }
}

/* ============================================================
   PAGE HEADER
   ============================================================ */

.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.page-header h1 { margin-bottom: var(--space-2); }
.page-header .description {
  color: var(--text-secondary);
  font-size: var(--fs-md);
  max-width: 60ch;
}

.page-header .actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

@media (max-width: 599px) {
  .page-header .actions { width: 100%; }
  .page-header .actions .btn { flex: 1; }
}

@media (min-width: 900px) {
  .page-header {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-5);
    margin-bottom: var(--space-7);
    padding-bottom: var(--space-5);
  }
  .page-header .actions { gap: var(--space-3); }
}

/* ============================================================
   BOTÕES
   ============================================================ */

.btn {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-decoration: none;
  white-space: nowrap;
  min-height: var(--touch-min);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover, .btn:focus-visible {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  outline: none;
}
.btn:focus-visible {
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--accent);
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-base);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: var(--fs-xs);
}
.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

.btn-ghost { border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--accent); background: var(--bg-hover); }

.btn-danger { color: var(--danger); border-color: rgba(176,75,63,.3); }
.btn-danger:hover { background: rgba(176,75,63,.08); border-color: var(--danger); }

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  min-height: 32px;
}

.btn-icon {
  padding: var(--space-2);
  width: var(--touch-min);
  height: var(--touch-min);
  min-height: var(--touch-min);
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
@media (min-width: 600px) { .card { padding: var(--space-5); } }
@media (min-width: 900px) { .card { padding: var(--space-6); } }

.card-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 500;
}

@media (min-width: 600px) {
  .card-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
  }
}

/* Métrica */
.metric {
  position: relative;
  padding: var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
@media (min-width: 600px) { .metric { padding: var(--space-5); } }
@media (min-width: 900px) { .metric { padding: var(--space-6); } }

.metric::after {
  content: "";
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent) 0%, transparent 100%);
  opacity: 0.6;
}

.metric .label {
  font-size: var(--fs-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}

.metric .value {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
  white-space: nowrap;
}

/* Em viewports estreitos, deixar quebrar é melhor que cortar */
@media (max-width: 599px) {
  .metric .value { white-space: normal; word-break: break-word; font-size: var(--fs-3xl); }
}

.metric .value .currency {
  font-size: 0.5em;
  font-style: italic;
  color: var(--text-secondary);
  margin-right: var(--space-2);
  vertical-align: top;
  line-height: 2;
}

.metric .delta {
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.metric .delta .pct { font-weight: 600; font-family: var(--font-mono); }

/* ============================================================
   GRIDS
   ============================================================ */

.grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr;
}

@media (min-width: 600px) {
  .grid { gap: var(--space-4); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .grid { gap: var(--space-5); }
  .grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .grid-4 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}

.grid-split-2 {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .grid-split-2 { grid-template-columns: 1fr 1fr; gap: var(--space-5); }
}

/* ============================================================
   TABELAS → CARDS no mobile
   ============================================================ */

.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

/* Mobile: cada linha vira card */
table thead { display: none; }
table tbody, table tr { display: block; width: 100%; }

table tbody tr {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: background 0.2s ease;
}

table tbody tr:last-child { border-bottom: none; }
table tbody tr:hover, table tbody tr:active { background: var(--bg-hover); }

table tbody td {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0;
  border-bottom: none;
  font-size: var(--fs-sm);
  min-width: 0;
}

table tbody td::before {
  content: attr(data-label);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  font-weight: 600;
  flex-shrink: 0;
}

table tbody td:first-child {
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-1);
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}
table tbody td:first-child::before { display: none; }

table tbody td.no-mobile { display: none; }

table .num { font-family: var(--font-mono); font-size: var(--fs-sm); }
table .ficha-name {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-lg);
  font-weight: 500;
  color: var(--text-primary);
}

/* ----- Tablet em diante: tabela tradicional ----- */
@media (min-width: 900px) {
  table thead { display: table-header-group; }
  table tbody { display: table-row-group; }
  table tbody tr {
    display: table-row;
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 0;
    border-radius: 0;
  }
  table tbody td {
    display: table-cell;
    padding: var(--space-4);
    text-align: left;
    vertical-align: middle;
  }
  table tbody td:first-child {
    grid-column: auto;
    border-bottom: none;
    padding: var(--space-4);
    margin-bottom: 0;
    flex-direction: row;
  }
  table tbody td::before { display: none; }
  table tbody td.no-mobile { display: table-cell; }
  table .num { text-align: right; }
  table thead th {
    text-align: left;
    font-weight: 600;
    font-size: var(--fs-xs);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-strong);
    background: rgba(0,0,0,.2);
  }
  table thead th.num { text-align: right; }
  table .ficha-name { font-size: 1.0625rem; }
}

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 3px var(--space-3);
  border-radius: 12px;
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255,255,255,.04);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.tag.estrela { background: rgba(212,160,76,.12);  color: var(--warning);  border-color: rgba(212,160,76,.3); }
.tag.cavalo  { background: rgba(106,141,163,.12); color: var(--info);     border-color: rgba(106,141,163,.3); }
.tag.quebra  { background: rgba(125,158,106,.12); color: var(--success);  border-color: rgba(125,158,106,.3); }
.tag.abacaxi { background: rgba(176,75,63,.12);   color: var(--danger);   border-color: rgba(176,75,63,.3); }
.tag.severidade-critica { background: rgba(176,75,63,.2);  color: #d8847a; border-color: var(--danger); }
.tag.severidade-alta    { background: rgba(212,160,76,.15); color: var(--warning); border-color: rgba(212,160,76,.4); }
.tag.severidade-media   { background: rgba(106,141,163,.12); color: var(--info); border-color: rgba(106,141,163,.3); }
.tag.severidade-baixa   { background: rgba(125,158,106,.1); color: var(--success); border-color: rgba(125,158,106,.3); }

/* ============================================================
   FORMULÁRIOS
   ============================================================ */

.form-row {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
  margin-bottom: var(--space-4);
}

@media (min-width: 600px) {
  .form-row { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .form-row {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-5);
  }
}

.form-field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }

.form-field label {
  font-size: var(--fs-xs);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
  font-family: var(--font-body);
  font-size: var(--fs-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: var(--touch-min);
  width: 100%;
}

/* Anti-zoom iOS */
@media (max-width: 599px) {
  .form-field input,
  .form-field select,
  .form-field textarea { font-size: 16px; }
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201,169,110,.15);
}

.form-field input::placeholder { color: var(--text-tertiary); }

.input-currency { position: relative; }
.input-currency .symbol {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-family: var(--font-display);
  font-style: italic;
  pointer-events: none;
  font-size: var(--fs-md);
}
.input-currency input { padding-left: var(--space-6); }

/* ============================================================
   TABS — scrollable horizontalmente no mobile
   ============================================================ */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.2s ease, border-color 0.2s ease;
  min-height: var(--touch-min);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================
   COMBOBOX
   ============================================================ */

.combobox { position: relative; min-width: 0; }

.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  max-height: min(60vh, 280px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.combobox-item {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  font-size: var(--fs-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
  min-height: var(--touch-min);
  -webkit-tap-highlight-color: transparent;
}
.combobox-item:last-child { border-bottom: none; }
.combobox-item:hover, .combobox-item.highlight, .combobox-item:active {
  background: var(--bg-hover);
  color: var(--accent);
}
.combobox-item .meta {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  white-space: nowrap;
}
.combobox-item.empty {
  cursor: default;
  color: var(--text-tertiary);
  font-style: italic;
  justify-content: center;
}
.combobox-item.create-new {
  background: rgba(201,169,110,.06);
  color: var(--accent);
  font-weight: 500;
}

/* ============================================================
   RECEITA — Editor (CARDS no mobile, GRID no desktop)
   ============================================================ */

.receita-table {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.receita-header { display: none; }

.receita-row {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "ordem nome remover"
    "qtd qtd qtd"
    "uni perda custo";
  gap: var(--space-3);
  align-items: end;
}

.receita-row.subproduto {
  background: linear-gradient(135deg, rgba(201,169,110,.06) 0%, var(--bg-elevated) 100%);
  border-color: rgba(201,169,110,.2);
}

.receita-row > .ordem        { grid-area: ordem; align-self: center; }
.receita-row > .combobox     { grid-area: nome; }
.receita-row > .qtd-cell     { grid-area: qtd; }
.receita-row > .uni-cell     { grid-area: uni; }
.receita-row > .perda-cell   { grid-area: perda; }
.receita-row > .custo-cell   { grid-area: custo; text-align: right; }
.receita-row > .remover-cell { grid-area: remover; align-self: center; }

.receita-row .ordem {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  width: 24px;
  text-align: center;
}

.receita-row .field-label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 4px;
  font-weight: 600;
}

.receita-row input, .receita-row select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  min-height: var(--touch-min);
}

@media (max-width: 599px) {
  .receita-row input, .receita-row select { font-size: 16px; }
}

.receita-row input:focus, .receita-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.receita-row .custo-cell {
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  color: var(--text-primary);
  font-weight: 600;
}
.receita-row .custo-cell .field-label { text-align: right; }

/* Tablet */
@media (min-width: 600px) {
  .receita-row {
    grid-template-columns: auto minmax(0, 1fr) 90px 80px 80px auto;
    grid-template-areas:
      "ordem nome qtd uni perda remover"
      "ordem nome custo custo custo custo";
    gap: var(--space-2) var(--space-3);
  }
  .receita-row > .custo-cell {
    grid-area: custo;
    padding-top: var(--space-2);
    border-top: 1px dashed var(--border);
  }
}

/* Desktop: grid horizontal completo */
@media (min-width: 1000px) {
  .receita-table {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 100px 80px 80px 110px 40px;
    gap: var(--space-2);
    align-items: center;
  }

  .receita-header { display: contents; }
  .receita-header > div {
    font-size: var(--fs-xs);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    padding: 0 var(--space-2) var(--space-2);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
  }

  .receita-row { display: contents; }
  /* Reseta grid-areas atribuídas no mobile/tablet */
  .receita-row > .ordem,
  .receita-row > .combobox,
  .receita-row > .qtd-cell,
  .receita-row > .uni-cell,
  .receita-row > .perda-cell,
  .receita-row > .custo-cell,
  .receita-row > .remover-cell { grid-area: auto; }

  .receita-row.subproduto > * {
    background: linear-gradient(90deg, rgba(201,169,110,.04) 0%, transparent 100%);
  }
  .receita-row > * {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    border-top: none;
  }
  .receita-row .field-label { display: none; }
  .receita-row input, .receita-row select {
    background: transparent;
    border: 1px solid transparent;
  }
  .receita-row input:hover, .receita-row select:hover {
    border-color: var(--border);
    background: var(--bg-hover);
  }
  .receita-row input:focus, .receita-row select:focus {
    border-color: var(--accent);
    background: var(--bg-elevated);
  }
  .receita-row .custo-cell {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    text-align: right;
    padding-right: var(--space-3);
    font-weight: 400;
    border-top: none;
  }
}

/* Footer da receita */
.receita-footer {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 2px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.receita-footer .totalizadores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

.receita-footer .totalizador {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-align: center;
  padding: var(--space-3);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.receita-footer .totalizador .label {
  font-size: var(--fs-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.receita-footer .totalizador .value {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-xl);
  font-weight: 500;
}

.receita-footer .totalizador .value.danger { color: var(--danger); }
.receita-footer .totalizador .value.success { color: var(--success); }

.receita-footer .note {
  color: var(--text-tertiary);
  font-style: italic;
  font-size: var(--fs-xs);
  line-height: 1.5;
}

@media (min-width: 900px) {
  .receita-footer {
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-5);
  }
  .receita-footer .totalizadores { display: flex; gap: var(--space-6); }
  .receita-footer .totalizador {
    background: transparent;
    padding: 0;
    text-align: left;
  }
  .receita-footer .note { max-width: 300px; text-align: right; }
}

/* ============================================================
   TOAST
   ============================================================ */

.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--space-3) + env(safe-area-inset-bottom));
  left: var(--space-3);
  right: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  font-size: var(--fs-sm);
  animation: toast-in 0.3s ease-out;
}

.toast.success { border-left-color: var(--success); }
.toast.danger  { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (min-width: 600px) {
  .toast-container {
    bottom: var(--space-5);
    right: var(--space-5);
    left: auto;
    max-width: 360px;
  }
  .toast { min-width: 280px; }
}

/* ============================================================
   ANIMAÇÕES + UTILS
   ============================================================ */

.fade-in { animation: fadeIn 0.4s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.shimmer {
  background: linear-gradient(90deg, var(--bg-card) 0%, var(--bg-hover) 50%, var(--bg-card) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-md);
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============================================================
   STATES + ACESSIBILIDADE
   ============================================================ */

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--text-tertiary);
}
.empty-state .icon { font-size: 2.5rem; opacity: 0.3; margin-bottom: var(--space-3); }
.empty-state h3 {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

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

/* ============================================================
   CMV — fórmula e gráfico de tendência
   ============================================================ */
.cmv-formula { display: flex; flex-direction: column; gap: var(--space-3); }

/* Tabela larga (muitas colunas) — no desktop cabe no container; scroll só no mobile se necessário */
@media (min-width: 900px) {
  .table-wide { width: 100%; table-layout: auto; }
  .table-wide th:first-child, .table-wide td:first-child { width: 1%; white-space: nowrap; }
  .table-wide th, .table-wide td { padding-left: var(--space-2); padding-right: var(--space-2); }
}

.cmv-trend {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-2);
  height: 200px;
  padding-top: var(--space-5);
}
.cmv-trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  gap: var(--space-2);
}
.cmv-trend-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  max-width: 56px;
}
.cmv-trend-bar {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  position: relative;
  min-height: 4px;
  transition: height 0.4s ease;
  display: flex;
  justify-content: center;
}
.cmv-trend-val {
  position: absolute;
  top: -22px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}
.cmv-trend-label {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
