/* =========================================================
   Cerealista Safra — Identidade Visual
   Verde escuro estrutural, verde médio para ações,
   detalhes dourados/trigo, cartões brancos.
   ========================================================= */
:root {
  --green-900: #14401f;
  --green-800: #1b5e20;
  --green-700: #226a2a;
  --green-600: #2e7d32;
  --green-500: #388e3c;
  --green-400: #4caf50;
  --green-50: #e8f3ea;
  --gold-600: #b8860b;
  --gold-500: #c9a227;
  --gold-400: #d4af37;
  --wheat: #f5efdf;
  --wheat-dark: #e8dcc0;
  --bg: #f4f6f3;
  --card: #ffffff;
  --border: #e2e8e3;
  --text: #1f2a24;
  --text-muted: #5e6e64;
  --text-faint: #93a399;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --warn: #e8a317;
  --warn-bg: #fdf6e3;
  --success: #2e7d32;
  --info: #1565c0;
  --shadow: 0 1px 3px rgba(20, 64, 31, .08), 0 1px 2px rgba(20, 64, 31, .06);
  --shadow-lg: 0 8px 30px rgba(20, 64, 31, .12);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 244px;
  --sidebar-w-collapsed: 64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---- Tema escuro ---- */
body.theme-dark {
  --bg: #0f1814;
  --card: #16211b;
  --border: #25342b;
  --text: #e6eee8;
  --text-muted: #9fb0a5;
  --text-faint: #6c7d72;
  --green-50: #1c2c22;
  --wheat: #1f2a24;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
a { color: var(--green-600); text-decoration: none; }
.hidden { display: none !important; }
.app-root { min-height: 100vh; }

/* =========================================================
   Botões
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: 13.5px; font-weight: 500;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-danger-outline { color: var(--danger); border-color: #f0c4c4; background: #fff; }
.btn-danger-outline:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); }
.btn-gold { background: #fff; border-color: var(--gold-400); color: var(--gold-600); }
.btn-gold:hover { background: var(--wheat); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

/* =========================================================
   Cartões
   ========================================================= */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.card-sub { font-size: 12.5px; color: var(--text-muted); }

/* =========================================================
   Formulários
   ========================================================= */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
label.field-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
label.field-label .req { color: var(--danger); }
.field-input, .field-select, .field-textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--card); color: var(--text);
  font-size: 13.5px; transition: border-color .15s, box-shadow .15s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  outline: none; border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(46,125,50,.12);
}
.field-textarea { resize: vertical; min-height: 90px; }
.field-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.field-error { font-size: 11.5px; color: var(--danger); margin-top: 4px; }
.input-icon { position: relative; }
.input-icon .field-input { padding-right: 38px; }
.input-icon .icon-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-faint); padding: 6px; border-radius: 5px;
}
.input-icon .icon-btn:hover { color: var(--text); }
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--green-700); margin: 22px 0 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.section-title:first-child { margin-top: 0; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 23px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #c5d0c8; border-radius: 23px; transition: .2s;
}
.switch .slider:before {
  content: ''; position: absolute; height: 17px; width: 17px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--green-500); }
.switch input:checked + .slider:before { transform: translateX(19px); }
.toggle-row { display: flex; align-items: center; gap: 12px; }

/* =========================================================
   Tabelas
   ========================================================= */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table thead th {
  text-align: left; padding: 11px 14px; background: var(--green-50);
  color: var(--green-800); font-weight: 600; font-size: 12px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.data-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data-table tbody tr:hover { background: var(--bg); }
table.data-table tbody tr.selected { background: var(--green-50); }

/* =========================================================
   Badges
   ========================================================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 20px; font-size: 11.5px; font-weight: 600;
}
.badge-success { background: #e3f1e4; color: var(--green-700); }
.badge-warn { background: var(--warn-bg); color: #a6760a; }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: #e3effa; color: var(--info); }
.badge-muted { background: #eef1ef; color: var(--text-muted); }

/* =========================================================
   Estado vazio
   ========================================================= */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 56px; color: var(--wheat-dark); margin-bottom: 18px; }
.empty-state h3 { font-size: 16px; color: var(--text); font-weight: 600; margin-bottom: 6px; }
.empty-state p { font-size: 13px; margin-bottom: 18px; }
body.theme-dark .empty-state .empty-icon { color: #3a4a40; }

/* =========================================================
   App shell — header / sidebar / content / footer
   ========================================================= */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--green-900); color: #cfe0d3;
  display: flex; flex-direction: column; flex-shrink: 0; transition: width .2s;
  position: sticky; top: 0; height: 100vh;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar-brand { padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; flex-shrink: 0; }
.brand-text .brand-name { font-weight: 700; font-size: 16px; color: #fff; line-height: 1.1; }
.brand-text .brand-name span { color: var(--gold-400); }
.brand-text .brand-sub { font-size: 9.5px; color: #8fae97; }
.sidebar.collapsed .brand-text, .sidebar.collapsed .nav-group-label, .sidebar.collapsed .nav-link span { display: none; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-group-label { padding: 14px 18px 6px; font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: #6f8c77; font-weight: 700; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 18px; color: #cfe0d3;
  font-size: 13.5px; border-left: 3px solid transparent; transition: background .15s;
}
.nav-link i { width: 18px; text-align: center; font-size: 15px; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--gold-400); }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .collapse-btn { background: none; border: none; color: #8fae97; display: flex; align-items: center; gap: 8px; font-size: 12.5px; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-header {
  background: var(--card); border-bottom: 1px solid var(--border); padding: 0 20px;
  height: 56px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.header-sel { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); }
.header-sel select { padding: 5px 8px; font-size: 12.5px; border: 1px solid var(--border); border-radius: 5px; background: var(--card); color: var(--text); }
.header-spacer { flex: 1; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-500); display: inline-block; }
.conn-dot.off { background: var(--text-faint); }
.header-user { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.icon-action { background: none; border: none; color: var(--text-muted); padding: 7px; border-radius: 6px; }
.icon-action:hover { background: var(--bg); color: var(--text); }

.content { flex: 1; padding: 22px; overflow-y: auto; }
.page-head { margin-bottom: 18px; display: flex; align-items: flex-start; gap: 12px; }
.page-head .page-icon { width: 40px; height: 40px; border-radius: 9px; background: var(--green-50); color: var(--green-700); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.page-head h1 { font-size: 19px; font-weight: 700; }
.page-head p { font-size: 13px; color: var(--text-muted); }

.app-footer {
  background: var(--card); border-top: 1px solid var(--border); padding: 8px 20px;
  font-size: 11.5px; color: var(--text-muted); display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}

/* =========================================================
   KPI cards
   ========================================================= */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-card .kpi-top { display: flex; align-items: center; gap: 9px; color: var(--text-muted); font-size: 12px; }
.kpi-card .kpi-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--green-50); color: var(--green-700); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 700; margin-top: 8px; }
.kpi-card .kpi-value small { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.kpi-card .kpi-foot { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* =========================================================
   Modal
   ========================================================= */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,40,28,.5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* =========================================================
   Alerts inline
   ========================================================= */
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; align-items: flex-start; }
.alert i { margin-top: 2px; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f3cccc; }
.alert-warn { background: var(--warn-bg); color: #9a6c08; border: 1px solid #f0dca8; }
.alert-success { background: #e3f1e4; color: var(--green-700); border: 1px solid #c3e0c5; }
.alert-info { background: #e9f1fa; color: var(--info); border: 1px solid #c6dcf2; }

/* =========================================================
   Filtros
   ========================================================= */
.filters-bar { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; align-items: end; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* =========================================================
   Stepper (wizard)
   ========================================================= */
.wizard { display: flex; gap: 0; }
.wizard-steps { width: 220px; flex-shrink: 0; background: var(--green-50); border-radius: var(--radius) 0 0 var(--radius); padding: 22px 18px; }
.wizard-step { display: flex; gap: 11px; padding: 11px 0; align-items: flex-start; }
.wizard-step .step-num { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--text-muted); flex-shrink: 0; }
.wizard-step.active .step-num { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.wizard-step.done .step-num { background: var(--green-500); border-color: var(--green-500); color: #fff; }
.wizard-step .step-label { font-size: 13px; font-weight: 600; }
.wizard-step .step-status { font-size: 11px; color: var(--text-faint); }
.wizard-body { flex: 1; padding: 26px; }

/* Login / standalone screens */
.standalone { min-height: 100vh; display: flex; }
.standalone-art { flex: 1; background: linear-gradient(135deg, var(--green-800), var(--green-900)); position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; padding: 40px; }
.standalone-art .brand-big .brand-name { font-size: 34px; font-weight: 800; }
.standalone-art .brand-big .brand-name span { color: var(--gold-400); }
.standalone-panel { width: 460px; max-width: 100%; background: var(--card); display: flex; flex-direction: column; justify-content: center; padding: 40px; }

/* spinner */
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(46,125,50,.25); border-top-color: var(--green-600); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 60px; color: var(--text-muted); }

/* timeline */
.timeline { position: relative; padding-left: 30px; }
.timeline:before { content: ''; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item .tl-dot { position: absolute; left: -25px; top: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--green-500); border: 3px solid var(--card); }
.timeline-item.danger .tl-dot { background: var(--danger); }
.timeline-item .tl-title { font-weight: 600; font-size: 13.5px; }
.timeline-item .tl-meta { font-size: 12px; color: var(--text-muted); }

/* checklist */
.checklist-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.checklist-item .chk-ico { color: var(--green-500); margin-top: 1px; }
.checklist-item.warn .chk-ico { color: var(--warn); }
.checklist-item .chk-title { font-weight: 600; font-size: 13px; }
.checklist-item .chk-sub { font-size: 11.5px; color: var(--text-muted); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 9px 16px; font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent; background: none; border-top: none; border-left: none; border-right: none; }
.tab.active { color: var(--green-700); border-bottom-color: var(--green-600); font-weight: 600; }

/* responsive */
@media (max-width: 1100px) {
  .form-row.cols-3, .form-row.cols-2 { grid-template-columns: 1fr; }
  .wizard { flex-direction: column; }
  .wizard-steps { width: 100%; display: flex; overflow-x: auto; border-radius: var(--radius) var(--radius) 0 0; }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 100; box-shadow: var(--shadow-lg); }
  .standalone-art { display: none; }
}

/* print */
@media print {
  .sidebar, .app-header, .app-footer, .no-print { display: none !important; }
  .content { padding: 0; }
}
