/* =============================================================================
   MERIDIAN — Design System v1.0
   Emissor Fiscal · CT-e · MDF-e · CIOT
   ============================================================================= */

/* ── Fonts ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
  /* Foundation */
  --void:          #090D13;
  --navy:          #0F1923;
  --navy-h:        #172131;
  --navy-a:        #1B2A3E;
  --navy-rim:      #243347;
  --navy-muted:    #3A506B;

  /* Surface */
  --bg-base:       #F3F5F9;
  --bg-surface:    #FFFFFF;
  --bg-muted:      #EDF0F6;
  --bg-panel:      #F0F3F9;

  /* Borders */
  --border-sm:     #E8ECF4;
  --border-md:     #D5DCE9;
  --border-lg:     #B8C4D8;

  /* Text */
  --tx-hi:         #0F1923;
  --tx-md:         #3D5068;
  --tx-lo:         #6B829E;
  --tx-ghost:      #A0B2C6;
  --tx-inv:        #F4F6FA;

  /* Petrol — Primary action */
  --p700:          #0A5368;
  --p600:          #0D6680;
  --p500:          #0E7A99;
  --p400:          #1190B4;
  --p300:          #5CB8D0;
  --p100:          #D9EFF5;
  --p50:           #EDF7FB;

  /* Status */
  --ok:            #155F38;
  --ok-bg:         #EDF7F2;
  --ok-bd:         #A3D9BD;
  --warn:          #92400E;
  --warn-bg:       #FFFBEB;
  --warn-bd:       #F5D08A;
  --err:           #991B1B;
  --err-bg:        #FFF5F5;
  --err-bd:        #FECACA;

  /* Shadows */
  --shadow-card:   0 1px 3px rgba(15,25,35,.06), 0 1px 2px rgba(15,25,35,.04);
  --shadow-md:     0 4px 14px rgba(15,25,35,.09), 0 2px 4px rgba(15,25,35,.06);
  --shadow-lg:     0 8px 24px rgba(15,25,35,.12), 0 2px 8px rgba(15,25,35,.08);
  --focus-ring:    0 0 0 3px rgba(14,122,153,.14);

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-pill: 20px;
}

/* ── Base Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--tx-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Utility ────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mono   { font-family: 'JetBrains Mono', ui-monospace, monospace !important; font-size: 12px !important; letter-spacing: -0.01em; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.login-screen  { display: flex; min-height: 100vh; }
.app-shell     { display: flex; min-height: 100vh; background: var(--bg-base); }

/* ── LOGIN SCREEN ───────────────────────────────────────────────────────────── */
.login-brand {
  width: 400px; flex-shrink: 0;
  background: var(--navy);
  display: flex; flex-direction: column; justify-content: center;
  align-items: flex-start; padding: 56px 44px;
  position: relative; overflow: hidden;
  border-right: 1px solid var(--navy-rim);
}
.login-brand::before {
  content: ''; position: absolute; top: -80px; right: -80px;
  width: 300px; height: 300px; border-radius: 50%;
  background: rgba(14,122,153,.08); pointer-events: none;
}
.login-brand::after {
  content: ''; position: absolute; bottom: -60px; left: -40px;
  width: 200px; height: 200px; border-radius: 50%;
  background: rgba(14,122,153,.05); pointer-events: none;
}
.login-brand-logo {
 width: 168px;
  height: 92px;
  border-radius: 12px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  overflow: hidden;
  box-shadow: none;
}
.login-brand-logo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.login-brand h1 {
  font-size: 24px; font-weight: 800; margin: 0 0 4px;
  color: var(--tx-inv); letter-spacing: -0.02em;
}
.login-brand-tagline {
  font-size: 12px; color: var(--p300);
  font-weight: 600; margin: 0 0 6px;
  letter-spacing: .04em; text-transform: uppercase;
}
.login-brand-desc {
  font-size: 13px; color: var(--navy-muted); margin: 0 0 36px; line-height: 1.6;
}
.login-brand-modules { display: flex; flex-direction: column; gap: 10px; }
.login-brand-modules span {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: rgba(255,255,255,.55); font-weight: 500;
}
.login-brand-modules span::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: var(--p400); flex-shrink: 0;
}

.login-form-panel {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: var(--bg-muted); padding: 40px;
}
.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  padding: 40px 36px; width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-card-hdr { text-align: center; margin-bottom: 28px; }
.login-card-hdr-icon {
  width: 52px; height: 52px; border-radius: 12px;
  background: var(--p50); border: 1px solid var(--p100);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin: 0 auto 14px;
}
.login-card-hdr h2 {
  font-size: 20px; font-weight: 800; color: var(--tx-hi);
  margin: 0 0 5px; letter-spacing: -0.02em;
}
.login-card-hdr p { font-size: 12px; color: var(--tx-lo); margin: 0; }

.login-submit {
  width: 100%; height: 38px; margin-top: 20px;
  background: var(--p600); color: white;
  border: 1px solid var(--p700); border-radius: var(--r-md);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background 120ms, box-shadow 120ms;
  box-shadow: 0 1px 3px rgba(14,122,153,.3), inset 0 1px 0 rgba(255,255,255,.08);
}
.login-submit:hover:not(:disabled) { background: var(--p700); }
.login-submit:active:not(:disabled) { transform: scale(.99); }
.login-submit:disabled { opacity: .55; cursor: not-allowed; }
.login-footer-txt {
  text-align: center; font-size: 11px; color: var(--tx-ghost);
  margin-top: 18px; margin-bottom: 0;
}
#loginError {
  margin-top: 10px; padding: 9px 12px;
  background: var(--err-bg); border: 1px solid var(--err-bd);
  border-radius: var(--r-md); font-size: 12px; color: var(--err); font-weight: 500;
}

/* ── SIDEBAR ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--navy);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 30; overflow-y: auto;
  transition: transform .22s ease;
  border-right: 1px solid var(--navy-rim);
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--navy-rim);
  flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 38px; height: 32px; border-radius: 7px;
  background: transparent; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: var(--p600);
  flex-shrink: 0; letter-spacing: -0.5px; overflow: hidden;
}
.sidebar-logo-icon img { width: 100%; height: 100%; object-fit: contain; padding: 2px; }
.sidebar-logo-name { font-size: 13px; font-weight: 700; color: var(--tx-inv); line-height: 1.2; letter-spacing: -0.01em; }
.sidebar-logo-sub  { font-size: 9px; color: var(--navy-muted); font-weight: 500; letter-spacing: .04em; margin-top: 1px; text-transform: uppercase; }

/* Status bar */
.sidebar-status {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; font-size: 11px; color: var(--navy-muted);
  border-bottom: 1px solid rgba(255,255,255,.04);
  cursor: pointer; transition: background 100ms;
}
.sidebar-status:hover { background: rgba(255,255,255,.03); }
.status-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.online  { background: #34D399; box-shadow: 0 0 5px rgba(52,211,153,.45); }
.status-dot.offline { background: #F87171; }
.status-dot.unknown { background: #94A3B8; }
.sidebar-status-text { flex: 1; font-size: 11px; }
.sidebar-status-uf {
  font-size: 9px; font-weight: 700; color: var(--navy-rim);
  background: rgba(255,255,255,.06); padding: 1px 6px;
  border-radius: 10px; text-transform: uppercase;
}

/* Nav */
.sidebar-nav { flex: 1; padding: 10px 0 8px; overflow-y: auto; }

.nav-group {
  padding: 12px 14px 3px;
  font-size: 9px; font-weight: 700; color: rgba(255,255,255,.22);
  text-transform: uppercase; letter-spacing: .1em;
  user-select: none;
}
.nav-group:first-child { padding-top: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  font-size: 12.5px; font-weight: 500;
  color: #7A94AE;
  cursor: pointer; transition: background 100ms, color 100ms, border-color 100ms;
  user-select: none; margin-bottom: 1px;
  border-left: 2px solid transparent;
  text-decoration: none;
}
.nav-item:hover { background: var(--navy-h); color: #C8D8E8; border-left-color: transparent; }
.nav-item.active {
  background: var(--navy-a); color: var(--tx-inv);
  border-left-color: var(--p400); font-weight: 600;
}
.nav-icon { flex-shrink: 0; width: 18px; display: inline-flex; align-items: center; justify-content: center; opacity: .8; }
.nav-icon svg { width: 15px; height: 15px; }
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
  flex-shrink: 0;
  padding: 8px 8px 12px;
  border-top: 1px solid var(--navy-rim);
}
.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 6px; border-radius: var(--r-md);
  transition: background 100ms; cursor: default;
}
.sidebar-user:hover { background: rgba(255,255,255,.04); }
.sidebar-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--p600); border: 1px solid var(--p700);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white; flex-shrink: 0;
}
.sidebar-user-name {
  font-size: 12px; font-weight: 600; color: rgba(255,255,255,.75);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font-size: 10px; color: var(--navy-muted); }
.sidebar-logout-btn {
  background: none; border: none; color: rgba(255,255,255,.25);
  cursor: pointer; font-size: 14px; padding: 4px 5px; border-radius: var(--r-sm);
  transition: color 100ms, background 100ms; flex-shrink: 0; line-height: 1;
}
.sidebar-logout-btn:hover { color: #F87171; background: rgba(248,113,113,.1); }

/* ── MAIN AREA ───────────────────────────────────────────────────────────────── */
.main-area {
  flex: 1; margin-left: 220px;
  display: flex; flex-direction: column; min-height: 100vh;
  transition: margin-left .22s ease;
}
.app-shell.sidebar-collapsed .sidebar { transform: translateX(-220px); }
.app-shell.sidebar-collapsed .main-area { margin-left: 0; }

/* ── TOPBAR ──────────────────────────────────────────────────────────────────── */
.topbar {
  height: 48px; background: var(--bg-surface);
  border-bottom: 1px solid var(--border-sm);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
  flex-shrink: 0;
}
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.sidebar-toggle-btn {
  background: none; border: none; font-size: 16px; cursor: pointer;
  color: var(--tx-lo); padding: 5px 7px; border-radius: var(--r-md);
  line-height: 1; transition: background 100ms, color 100ms;
}
.sidebar-toggle-btn:hover { background: var(--bg-muted); color: var(--tx-hi); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.bc-root { color: var(--tx-ghost); }
.bc-sep  { color: var(--border-md); font-size: 14px; }
.bc-cur  { color: var(--tx-hi); font-weight: 600; font-size: 13px; }

/* Env badge */
.env-badge {
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; white-space: nowrap; border: 1px solid;
}
.env-hml  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-bd); }
.env-prod { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-bd); }

/* SEFAZ pill */
.sefaz-pill {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg-muted); border: 1px solid var(--border-md);
  border-radius: var(--r-pill); padding: 3px 10px;
  font-size: 11px; font-weight: 600; color: var(--tx-lo);
  cursor: pointer; transition: background 100ms; white-space: nowrap;
}
.sefaz-pill:hover { background: var(--bg-panel); border-color: var(--border-lg); }

/* ── MODULE SECTIONS ─────────────────────────────────────────────────────────── */
.module-content { flex: 1; overflow-y: auto; }
.module-section { display: flex; flex-direction: column; }
.module-header {
  padding: 18px 24px 14px; background: var(--bg-surface);
  border-bottom: 1px solid var(--border-sm); flex-shrink: 0;
}
.module-title-grp { display: flex; align-items: center; gap: 12px; }
.module-icon { line-height: 1; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; background: var(--p50); border: 1px solid var(--p100); color: var(--p600); flex-shrink: 0; }
.module-icon svg { width: 18px; height: 18px; }
.module-title {
  font-size: 17px; font-weight: 800; color: var(--tx-hi);
  margin: 0 0 1px; letter-spacing: -0.02em;
}
.module-subtitle { font-size: 11px; color: var(--tx-lo); margin: 0; }
.module-body  { flex: 1; padding: 20px 24px; }
.module-inner { max-width: 860px; margin: 0 auto; }

/* ── DASHBOARD ────────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  position: relative; overflow: hidden;
  transition: box-shadow 150ms, border-color 150ms;
}
.stat-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-lg); }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 3px; border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.stat-card-cte::before    { background: var(--p500); }
.stat-card-mdfe::before   { background: #7C3AED; }
.stat-card-ciot::before   { background: #0E7A99; opacity: .6; }
.stat-card-reject::before { background: var(--err); }

.stat-card-icon  { margin-bottom: 8px; height: 18px; }
.stat-card-icon svg { width: 18px; height: 18px; }
.stat-card-cte    .stat-card-icon { color: var(--p500); }
.stat-card-mdfe   .stat-card-icon { color: #7C3AED; }
.stat-card-ciot   .stat-card-icon { color: var(--p600); }
.stat-card-reject .stat-card-icon { color: var(--err); }
.stat-card-label {
  font-size: 9px; font-weight: 700; color: var(--tx-lo);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px;
}
.stat-card-val   {
  font-size: 28px; font-weight: 800; color: var(--tx-hi);
  line-height: 1; margin-bottom: 4px; letter-spacing: -0.02em;
}
.stat-card-sub   { font-size: 10px; color: var(--tx-ghost); }

/* Quick actions */
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.quick-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg-surface); border: 1px solid var(--border-md);
  border-radius: var(--r-md); padding: 8px 14px;
  font-size: 12px; font-weight: 600; color: var(--tx-md);
  cursor: pointer; transition: all 120ms;
  text-decoration: none; box-shadow: var(--shadow-card);
}
.quick-btn:hover {
  border-color: var(--p400); color: var(--p500);
  box-shadow: 0 2px 8px rgba(14,122,153,.14);
  background: var(--p50);
}

/* Dashboard grid */
.dash-grid {
  display: grid; grid-template-columns: 1fr 260px; gap: 14px;
}

/* Recent emissions panel */
.recent-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.recent-panel-hdr {
  padding: 12px 16px; border-bottom: 1px solid var(--border-sm);
  font-weight: 700; font-size: 12px; color: var(--tx-hi);
  display: flex; align-items: center; justify-content: space-between;
}
.recent-empty-msg {
  padding: 40px 20px; text-align: center;
  color: var(--tx-ghost); font-size: 12px; line-height: 1.7;
}
.recent-empty-icon { font-size: 28px; margin-bottom: 10px; opacity: .5; }

/* Recent table */
#recentTable { width: 100%; font-size: 12px; }
#recentTable thead tr { border-bottom: 1px solid var(--border-sm); }
#recentTable thead th {
  padding: 8px 14px; text-align: left;
  font-size: 9px; color: var(--tx-ghost);
  font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
#recentTable tbody tr { border-bottom: 1px solid var(--border-sm); transition: background 80ms; }
#recentTable tbody tr:last-child { border-bottom: none; }
#recentTable tbody tr:hover { background: var(--bg-muted); }
#recentTable tbody td { padding: 9px 14px; }

/* System status card */
.system-status-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
}
.system-status-title {
  font-size: 10px; font-weight: 700; color: var(--tx-lo);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border-sm);
}
.status-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0;
  font-size: 12px; color: var(--tx-md);
}
.status-row + .status-row { border-top: 1px solid var(--border-sm); }

/* Banner ambiental no dashboard */
.dash-env-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; margin-bottom: 14px;
  border-radius: var(--r-md);
  font-size: 12px; font-weight: 500;
  border: 1px solid;
}
.dash-env-banner.hml {
  background: var(--warn-bg); color: var(--warn); border-color: var(--warn-bd);
}
.dash-env-banner.prod {
  background: var(--ok-bg); color: var(--ok); border-color: var(--ok-bd);
}

/* ── FORM COMPONENTS ─────────────────────────────────────────────────────────── */

/* Card */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: 10px;
}

.card-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-sm);
  cursor: pointer; user-select: none;
  transition: background 100ms;
}
.card-header:hover { background: var(--bg-muted); }

.card-body { padding: 16px; }
.card-body.collapsed { display: none; }

/* Step badge */
.step-badge {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--tx-hi); color: white;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step-badge.done { background: var(--ok); }

/* Fields */
.field { display: flex; flex-direction: column; }
.field label {
  display: block;
  font-size: 10px; font-weight: 700; color: var(--tx-lo);
  margin-bottom: 4px; text-transform: uppercase; letter-spacing: .06em;
}
.field label .req { color: var(--err); }

.field input,
.field select,
.field textarea {
  width: 100%;
  height: 33px;
  padding: 0 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-md);
  font-size: 12.5px; color: var(--tx-hi);
  font-family: inherit;
  transition: border-color 120ms, box-shadow 120ms;
  outline: none;
}
.field textarea { height: auto; padding: 8px 10px; resize: vertical; }
.field input::placeholder,
.field select::placeholder,
.field textarea::placeholder { color: var(--tx-ghost); }
.field input:hover,
.field select:hover { border-color: var(--border-lg); }
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--p500);
  box-shadow: var(--focus-ring);
}
.field input[type="file"] {
  height: auto; padding: 6px 10px; cursor: pointer;
  font-size: 12px; color: var(--tx-lo);
}
.field input[disabled],
.field select[disabled] {
  background: var(--bg-muted); color: var(--tx-ghost); cursor: not-allowed;
}
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236B829E'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 28px;
}

/* Grid helpers */
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.g4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 10px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

/* Address toggle */
.addr-toggle {
  color: var(--p400); font-size: 11px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  margin-top: 6px; background: none; border: none; padding: 0;
  transition: color 100ms;
}
.addr-toggle:hover { color: var(--p600); }

/* Submit button */
#btnEmitir {
  background: var(--p600); color: white;
  border: 1px solid var(--p700); border-radius: var(--r-lg);
  width: 100%; padding: 13px; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background 120ms, box-shadow 120ms;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 1px 3px rgba(14,122,153,.3), inset 0 1px 0 rgba(255,255,255,.08);
}
#btnEmitir:hover:not(:disabled) { background: var(--p700); }
#btnEmitir:active:not(:disabled) { transform: scale(.99); }
#btnEmitir:disabled { opacity: .55; cursor: not-allowed; }

/* MDF-e/CIOT submit button */
#btnEmitirMdfe, #btnDeclararCiot {
  background: var(--p600); color: white;
  border: 1px solid var(--p700); border-radius: var(--r-lg);
  width: 100%; padding: 12px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: background 120ms;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 1px 3px rgba(14,122,153,.3);
}
#btnEmitirMdfe:hover:not(:disabled),
#btnDeclararCiot:hover:not(:disabled) { background: var(--p700); }
#btnEmitirMdfe:disabled,
#btnDeclararCiot:disabled { opacity: .55; cursor: not-allowed; }

/* Tomador chips */
.toma-opt {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: var(--r-pill);
  cursor: pointer; border: 1px solid var(--border-md);
  font-size: 11px; font-weight: 600; color: var(--tx-lo);
  transition: all 120ms; background: var(--bg-surface);
}
.toma-opt:has(input:checked) {
  border-color: var(--p400); background: var(--p50); color: var(--p600);
}
.toma-opt input { display: none; }

/* Route arrow */
.route-arrow {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--border-lg);
  font-size: 18px; padding: 0 6px; flex-shrink: 0;
}

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border-md); border-radius: 22px; transition: .2s;
}
.slider:before {
  content: ""; position: absolute; width: 16px; height: 16px;
  left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s;
}
.toggle input:checked + .slider { background: var(--p500); }
.toggle input:checked + .slider:before { transform: translateX(16px); }

/* Chip */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--p50); color: var(--p600);
  border: 1px solid var(--p100); border-radius: var(--r-pill);
  padding: 3px 9px; font-size: 10px; font-weight: 600;
}

/* ── RESULT CARDS ─────────────────────────────────────────────────────────────── */
.result-authorized { background: var(--ok-bg); border-color: var(--ok-bd) !important; }
.result-rejected   { background: var(--err-bg); border-color: var(--err-bd) !important; }
.result-error      { background: var(--warn-bg); border-color: var(--warn-bd) !important; }

/* ── XML VIEWER ──────────────────────────────────────────────────────────────── */
pre.xml-view {
  font-size: 11px; font-family: 'JetBrains Mono', ui-monospace, monospace;
  background: var(--void); color: #8BA7C0;
  border-radius: var(--r-md); padding: 14px;
  max-height: 300px; overflow: auto;
  white-space: pre-wrap; word-break: break-all; line-height: 1.65;
  border: 1px solid var(--navy-rim);
}
pre.xml-view .tag  { color: #5CB8D0; }
pre.xml-view .attr { color: #E2B96A; }
pre.xml-view .val  { color: #A3D9BD; }

/* ── BADGES ───────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: var(--r-pill);
  font-size: 9px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; border: 1px solid;
}
.badge-ok     { color: var(--ok);   background: var(--ok-bg);   border-color: var(--ok-bd); }
.badge-err    { color: var(--err);  background: var(--err-bg);  border-color: var(--err-bd); }
.badge-warn   { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-bd); }
.badge-neutral{ color: var(--tx-lo); background: var(--bg-panel); border-color: var(--border-md); }

/* Permission chip */
.perm-chip {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 3px;
  font-size: 9px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase;
  background: var(--bg-panel); color: var(--tx-md);
  border: 1px solid var(--border-md); margin-right: 3px;
}
.perm-chip.all { background: var(--tx-hi); color: var(--tx-inv); border-color: var(--navy-rim); }

/* ── INTEGRATIONS MODULE ─────────────────────────────────────────────────────── */
.api-url-banner {
  background: var(--navy);
  border: 1px solid var(--navy-rim);
  border-radius: var(--r-lg); padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 16px;
}
.api-url-label {
  font-size: 9px; font-weight: 700; color: var(--navy-muted);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px;
}
.api-url-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; color: var(--p300); font-weight: 500;
}
.api-url-copy {
  background: rgba(255,255,255,.08); color: var(--tx-inv);
  border: 1px solid var(--navy-rim); border-radius: var(--r-md);
  padding: 6px 12px; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: background 100ms; white-space: nowrap; flex-shrink: 0;
}
.api-url-copy:hover { background: rgba(255,255,255,.13); }

/* API Key card */
.api-key-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg); padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-card);
  display: grid; grid-template-columns: 1fr auto;
  gap: 10px; align-items: start;
  transition: box-shadow 150ms, border-color 150ms;
}
.api-key-card:hover { border-color: var(--border-lg); box-shadow: var(--shadow-md); }
.api-key-name {
  font-size: 13px; font-weight: 700; color: var(--tx-hi); margin-bottom: 4px;
}
.api-key-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--tx-lo);
  background: var(--bg-muted); border: 1px solid var(--border-sm);
  border-radius: var(--r-sm); padding: 2px 8px;
  display: inline-block; margin-right: 6px;
}
.api-key-meta { font-size: 10px; color: var(--tx-ghost); margin-top: 5px; }

/* Key created result */
.key-created-banner {
  background: var(--ok-bg); border: 1px solid var(--ok-bd);
  border-radius: var(--r-lg); padding: 16px 18px; margin-bottom: 14px;
}
.key-created-title {
  font-size: 13px; font-weight: 700; color: var(--ok); margin-bottom: 8px;
}
.key-created-value {
  display: flex; align-items: center; gap: 8px;
}
.key-created-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; background: #D1FAE5; padding: 8px 12px;
  border-radius: var(--r-md); flex: 1; word-break: break-all;
  border: 1px solid var(--ok-bd); color: var(--ok);
}

/* Code example block */
.code-block {
  background: var(--void); border: 1px solid var(--navy-rim);
  border-radius: var(--r-md); padding: 14px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: #8BA7C0; line-height: 1.7;
  overflow-x: auto;
}
.code-block .kw  { color: var(--p300); }
.code-block .str { color: #A3D9BD; }
.code-block .key { color: #E2B96A; }

/* ── SETTINGS / CERT ─────────────────────────────────────────────────────────── */
.cert-card {
  background: var(--bg-surface); border: 1px solid var(--border-md);
  border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-card);
  margin-bottom: 12px;
}
.cert-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.cert-icon-wrap {
  width: 40px; height: 40px; border-radius: var(--r-md);
  background: var(--p50); border: 1px solid var(--p100);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  flex-shrink: 0;
}
.cert-company { font-size: 14px; font-weight: 700; color: var(--tx-hi); }
.cert-cnpj    {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--tx-lo); margin-top: 2px;
}
.cert-meta-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 12px;
  background: var(--bg-muted); border-radius: var(--r-md);
  margin-bottom: 12px;
}
.cert-meta-key {
  font-size: 9px; color: var(--tx-ghost); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.cert-meta-val {
  font-size: 12px; color: var(--tx-hi); font-weight: 600; margin-top: 2px;
}
.cert-notice {
  font-size: 11px; color: var(--warn);
  background: var(--warn-bg); border: 1px solid var(--warn-bd);
  border-radius: var(--r-md); padding: 9px 12px; margin-bottom: 12px;
  line-height: 1.5;
}
.cert-actions { display: flex; gap: 8px; }

/* Dropzone */
.cert-dropzone {
  border: 2px dashed var(--border-md); border-radius: var(--r-lg);
  padding: 28px; text-align: center; background: var(--bg-panel);
  cursor: pointer; transition: border-color 150ms, background 150ms;
}
.cert-dropzone:hover, .cert-dropzone.dragover {
  border-color: var(--p400); background: var(--p50);
}
.cert-dropzone-icon { font-size: 24px; margin-bottom: 8px; opacity: .5; }
.cert-dropzone-text { font-size: 13px; color: var(--tx-lo); font-weight: 500; }
.cert-dropzone-hint { font-size: 11px; color: var(--tx-ghost); margin-top: 3px; }

/* ── EMPTY STATES ─────────────────────────────────────────────────────────────── */
.empty-state {
  max-width: 400px; margin: 56px auto;
  text-align: center; padding: 0 24px;
}
.empty-icon { margin-bottom: 18px; opacity: .8; }
.empty-title { font-size: 16px; font-weight: 700; color: var(--tx-hi); margin-bottom: 6px; letter-spacing: -0.01em; }
.empty-desc  { font-size: 12px; color: var(--tx-lo); line-height: 1.65; margin-bottom: 16px; }
.empty-preview {
  background: var(--bg-panel); border: 1px solid var(--border-sm);
  border-radius: var(--r-md); padding: 10px 14px; margin-bottom: 16px; text-align: left;
}
.empty-preview-label {
  font-size: 9px; font-weight: 700; color: var(--tx-ghost);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 7px;
}
.empty-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; }

/* Coming soon legacy */
.coming-soon {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}

/* ── BUTTONS (utility) ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: var(--r-md);
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: all 120ms; border: 1px solid; white-space: nowrap;
}
.btn-primary {
  background: var(--p600); color: white; border-color: var(--p700);
  box-shadow: 0 1px 2px rgba(14,122,153,.25);
}
.btn-primary:hover { background: var(--p700); }
.btn-secondary {
  background: var(--bg-surface); color: var(--tx-md); border-color: var(--border-md);
  box-shadow: var(--shadow-card);
}
.btn-secondary:hover { background: var(--bg-muted); border-color: var(--border-lg); }
.btn-destructive {
  background: transparent; color: var(--err); border-color: var(--err-bd);
}
.btn-destructive:hover { background: var(--err-bg); }
.btn-ghost {
  background: transparent; color: var(--tx-lo); border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-muted); }
.btn-sm { height: 27px; padding: 0 10px; font-size: 11px; }

/* Section header within module */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-size: 12px; font-weight: 700; color: var(--tx-hi);
}
.section-sub {
  font-size: 11px; color: var(--tx-lo); margin-left: 6px;
}

/* Info box */
.info-box {
  background: var(--p50); border: 1px solid var(--p100);
  border-radius: var(--r-md); padding: 12px 14px; margin-top: 12px;
  font-size: 12px; color: var(--p600); line-height: 1.6;
}
.info-box strong { font-weight: 700; display: block; margin-bottom: 4px; }
.info-box ul { margin: 4px 0 0; padding-left: 14px; }
.info-box ul li { margin-bottom: 2px; }

/* ── TOAST ────────────────────────────────────────────────────────────────────── */
#toastContainer {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999; display: flex; flex-direction: column; gap: 6px;
}
.toast {
  min-width: 280px; max-width: 380px;
  background: var(--bg-surface); border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 11px 14px;
  display: flex; align-items: flex-start; gap: 9px;
  animation: toastIn 200ms ease;
  position: relative; overflow: hidden;
}
.toast::before {
  content: ''; position: absolute;
  left: 0; top: 0; bottom: 0; width: 3px;
  border-radius: var(--r-lg) 0 0 var(--r-lg);
}
.toast.ok::before  { background: var(--ok); }
.toast.err::before { background: var(--err); }
.toast.warn::before{ background: var(--warn); }
.toast.info::before{ background: var(--p500); }

.toast-icon  { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.toast-msg   { font-size: 12px; color: var(--tx-md); flex: 1; line-height: 1.4; font-weight: 500; }
.toast-close {
  background: none; border: none; color: var(--tx-ghost);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; flex-shrink: 0;
}
@keyframes toastIn {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── MDFE AMBER CARD (encerramento) ──────────────────────────────────────────── */
.card-amber { border-color: var(--warn-bd) !important; }
.card-amber .card-header { background: var(--warn-bg); }
.card-amber .card-header .step-badge { background: #D97706; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-220px); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-area { margin-left: 0 !important; }
  .login-brand { display: none; }
  .module-body { padding: 14px; }
  .module-header { padding: 14px; }
  .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .span3 { grid-column: span 2; }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: span 1; }
}

/* =============================================================================
   WIZARD LAYOUT — Forms CT-e / MDF-e / CIOT
   ============================================================================= */

.wizard-wrap {
  display: grid;
  grid-template-columns: 172px 1fr 228px;
  align-items: start;
}

/* ── Step panel (left) ──────────────────────────────────────────────────────── */
.wizard-steps-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border-sm);
  padding: 18px 0 40px;
  position: sticky; top: 48px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  align-self: start;
}

.wizard-step {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 8px 14px; cursor: pointer;
  transition: background 100ms;
}
.wizard-step:hover { background: var(--border-sm); }
.wizard-step.active { background: rgba(14,122,153,.06); }

.ws-num {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; flex-shrink: 0; margin-top: 1px;
  transition: all 140ms;
}
.wizard-step.todo   .ws-num { background: transparent; color: var(--tx-ghost); border: 1.5px solid var(--border-md); }
.wizard-step.active .ws-num { background: var(--tx-hi); color: white; border: none; }
.wizard-step.done   .ws-num { background: var(--ok); color: white; border: none; }

.ws-label { font-size: 12px; font-weight: 600; color: var(--tx-lo); line-height: 1.3; }
.wizard-step.active .ws-label { color: var(--tx-hi); }
.wizard-step.done   .ws-label { color: var(--tx-md); }
.ws-sub { font-size: 10px; color: var(--tx-ghost); margin-top: 1px; }

.wizard-connector {
  width: 1.5px; height: 10px;
  background: var(--border-md); margin: 0 0 0 23px;
}
.wizard-connector.done { background: var(--ok); }

/* ── Main content (center) ──────────────────────────────────────────────────── */
.wizard-main {
  padding: 20px 22px 0;
  min-width: 0;
}

.pane-title {
  font-size: 15px; font-weight: 800; color: var(--tx-hi);
  letter-spacing: -0.02em; margin-bottom: 3px;
}
.pane-subtitle { font-size: 11px; color: var(--tx-lo); margin-bottom: 16px; }

/* Section block inside a pane */
.pane-section {
  background: var(--bg-muted); border: 1px solid var(--border-sm);
  border-radius: var(--r-lg); padding: 14px; margin-bottom: 12px;
}
.pane-section-title {
  font-size: 9px; font-weight: 700; color: var(--tx-lo);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border-sm);
}

/* Route visual */
.route-cols { display: grid; grid-template-columns: 1fr 36px 1fr; gap: 8px; align-items: start; }
.route-divider {
  display: flex; flex-direction: column; align-items: center;
  padding-top: 40px; color: var(--border-lg); font-size: 16px; gap: 2px;
}
.route-divider-line { width: 1px; height: 24px; background: var(--border-md); }

/* Inline cert confirmation */
.cert-ok-inline {
  background: var(--ok-bg); border: 1px solid var(--ok-bd);
  border-radius: var(--r-md); padding: 10px 12px;
  margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;
}

/* Pane 5 — Review */
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.review-item {
  background: var(--bg-muted); border: 1px solid var(--border-sm);
  border-radius: var(--r-md); padding: 10px 12px;
}
.review-key { font-size: 9px; font-weight: 700; color: var(--tx-ghost); text-transform: uppercase; letter-spacing: .05em; }
.review-val { font-size: 13px; font-weight: 600; color: var(--tx-hi); margin-top: 2px; }
.review-val.empty { color: var(--tx-ghost); font-weight: 400; font-style: italic; }
.review-val.mono { font-family: 'JetBrains Mono', monospace; font-size: 11px; }
.review-val.status-ok   { color: var(--ok); }
.review-val.status-warn { color: var(--warn); }

/* Wizard nav footer */
.wizard-footer {
  position: sticky; bottom: 0;
  background: var(--bg-surface); border-top: 1px solid var(--border-sm);
  padding: 11px 22px; margin: 16px -22px 0;
  display: flex; align-items: center; gap: 10px; z-index: 10;
}
.wizard-step-indicator {
  font-size: 11px; color: var(--tx-ghost); font-weight: 500; flex: 1; text-align: center;
}

/* ── Summary panel (right) ──────────────────────────────────────────────────── */
.wizard-summary-panel {
  border-left: 1px solid var(--border-sm);
  background: var(--bg-panel); padding: 16px 14px;
  position: sticky; top: 48px;
  max-height: calc(100vh - 60px); overflow-y: auto;
  align-self: start;
}
.wsp-title {
  font-size: 9px; font-weight: 700; color: var(--tx-ghost);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border-sm);
}
.wsp-row { margin-bottom: 10px; }
.wsp-key { font-size: 9px; color: var(--tx-ghost); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.wsp-val { font-size: 11.5px; color: var(--tx-hi); font-weight: 500; margin-top: 2px; word-break: break-all; }
.wsp-val.empty { color: var(--tx-ghost); font-style: italic; font-weight: 400; }
.wsp-val.mono { font-family: 'JetBrains Mono', monospace; font-size: 10px; }
.wsp-divider { border: none; border-top: 1px solid var(--border-sm); margin: 10px 0; }
.wsp-badge { display: block; margin-top: 3px; }

/* ── Responsive wizard ──────────────────────────────────────────────────────── */
@media (max-width: 1060px) {
  .wizard-wrap { grid-template-columns: 152px 1fr 0; }
  .wizard-summary-panel { display: none; }
}
@media (max-width: 720px) {
  .wizard-wrap { grid-template-columns: 1fr; }
  .wizard-steps-panel { display: none; }
  .wizard-main { padding: 14px; }
}
