/* ============================================================
   K2 Distribuidora — Painel Administrativo
   Design: Soft UI Evolution / Minimalism — B2B Profissional
   ============================================================ */

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

:root {
  --primary:        #c41c1c;
  --primary-dark:   #991b1b;
  --primary-light:  #ef4444;
  --primary-bg:     #fff1f1;
  --secondary:      #64748b;
  --success:        #16a34a;
  --success-bg:     #f0fdf4;
  --warning:        #d97706;
  --warning-bg:     #fffbeb;
  --danger:         #dc2626;
  --danger-bg:      #fef2f2;
  --info:           #0891b2;
  --info-bg:        #ecfeff;
  --body-bg:        #f1f5f9;
  --sidebar-bg:     #0f172a;
  --sidebar-hover:  #1e293b;
  --sidebar-active: #c41c1c;
  --sidebar-text:   #94a3b8;
  --sidebar-active-text: #ffffff;
  --card-bg:        #ffffff;
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --border:         #e2e8f0;
  --border-focus:   #ef4444;
  --input-bg:       #ffffff;
  --shadow-xs:      0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:      0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 15px rgba(0,0,0,.10), 0 4px 6px rgba(0,0,0,.05);
  --radius:         8px;
  --radius-lg:      12px;
  --radius-xl:      16px;
  --sidebar-width:  260px;
  --header-h:       64px;
  --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --transition:     all 0.2s ease;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--body-bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }
button, [type=button], [type=submit] { cursor: pointer; touch-action: manipulation; }
input, select, textarea { max-width: 100%; }

/* ---- SCROLLBAR ------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---- LAYOUT ---------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  transition: transform 0.3s ease;
  will-change: transform;
  -webkit-overflow-scrolling: touch;
}

.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
  min-width: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 299;
}

/* ---- SIDEBAR BRAND --------------------------------------- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-icon {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 14px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub  { font-size: 11px; color: var(--sidebar-text); white-space: nowrap; }

/* ---- SIDEBAR NAV ----------------------------------------- */
.sidebar-nav { flex: 1; padding: 16px 12px; }

.nav-section { margin-bottom: 4px; }

.nav-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
  padding: 12px 8px 6px;
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
}

.nav-item svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: .7;
  transition: var(--transition);
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #cbd5e1;
}

.nav-item:hover svg { opacity: 1; }

.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.nav-item.active svg { opacity: 1; }

/* ---- SIDEBAR FOOTER -------------------------------------- */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.user-avatar {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-detail { display: flex; flex-direction: column; min-width: 0; }
.user-name   { font-size: 13px; font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role   { font-size: 11px; color: var(--sidebar-text); }

.logout-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  transition: var(--transition);
  flex-shrink: 0;
}
.logout-btn svg { width: 17px; height: 17px; }
.logout-btn:hover { background: #dc262620; color: #ef4444; }

/* ---- TOPBAR ---------------------------------------------- */
.topbar {
  height: var(--header-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-xs);
  width: 100%;
  box-sizing: border-box;
}

.topbar-left  { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 20px; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  padding: 6px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: var(--transition);
}
.menu-toggle svg { width: 22px; height: 22px; display: block; }
.menu-toggle:hover { background: var(--body-bg); color: var(--text-primary); }

.page-heading { font-size: 17px; font-weight: 600; color: var(--text-primary); }

.topbar-date { font-size: 13px; color: var(--text-muted); }

.topbar-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: var(--transition);
}
.topbar-logout svg { width: 16px; height: 16px; }
.topbar-logout:hover { background: var(--danger-bg); color: var(--danger); }

/* ---- CONTENT --------------------------------------------- */
.content { flex: 1; padding: 28px 28px 40px; max-width: 1400px; width: 100%; min-width: 0; box-sizing: border-box; }

/* ---- CARDS ----------------------------------------------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.card-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg { width: 18px; height: 18px; color: var(--primary); }

.card-body { padding: 24px; }

/* ---- STAT CARDS ------------------------------------------ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.blue   { background: var(--primary-bg); color: var(--primary); }
.stat-icon.green  { background: var(--success-bg); color: var(--success); }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red    { background: var(--danger-bg);  color: var(--danger);  }
.stat-icon.cyan   { background: var(--info-bg);    color: var(--info);    }

.stat-info { flex: 1; min-width: 0; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* ---- PAGE HEADER ----------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.page-header-sub   { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ---- BUTTONS --------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: var(--transition);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--primary);   color: #fff; border-color: var(--primary);   }
.btn-primary:hover   { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-secondary { background: #f8fafc; color: var(--text-secondary); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text-primary); }

.btn-success   { background: var(--success);   color: #fff; border-color: var(--success);   }
.btn-success:hover   { background: #15803d; border-color: #15803d; color: #fff; }

.btn-danger    { background: var(--danger);    color: #fff; border-color: var(--danger);    }
.btn-danger:hover    { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn-warning   { background: var(--warning);   color: #fff; border-color: var(--warning);   }
.btn-warning:hover   { background: #b45309; color: #fff; }

.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-bg); }

.btn-outline-danger  { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover  { background: var(--danger-bg); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 8px; gap: 0; }
.btn-icon svg { width: 17px; height: 17px; }

/* ---- TABLE ----------------------------------------------- */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); width: 100%; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  background: #f8fafc;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.15s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

tbody td { padding: 13px 16px; color: var(--text-primary); vertical-align: middle; }

.table-actions { display: flex; gap: 6px; align-items: center; }
.no-results { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.no-results svg { width: 40px; height: 40px; opacity: .4; display: block; margin: 0 auto 10px; }

/* ---- FORMS ----------------------------------------------- */
.form-grid   { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr;           gap: 20px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr;       gap: 20px; max-width: 100%; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr);    gap: 20px; }

/* ---- VENDAS GRID (nova/editar venda) --------------------- */
.vendas-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
  max-width: 100%;
}
.vendas-grid > * { min-width: 0; }
.vendas-grid > div:last-child { position: sticky; top: calc(var(--header-h) + 20px); }

.form-section { margin-bottom: 28px; }
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.required::after { content: ' *'; color: var(--danger); }

input[type=text],
input[type=email],
input[type=number],
input[type=password],
input[type=date],
input[type=tel],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--input-bg);
  transition: var(--transition);
  font-family: var(--font);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(196,28,28,.15);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='%2394a3b8' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; padding-right: 36px; cursor: pointer; }

.input-group { display: flex; }
.input-group input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .input-addon { background: #f8fafc; border: 1.5px solid var(--border); border-left: none; padding: 9px 12px; border-radius: 0 var(--radius) var(--radius) 0; color: var(--text-muted); font-size: 13px; white-space: nowrap; display: flex; align-items: center; }

.form-hint { font-size: 12px; color: var(--text-muted); }
.form-error { font-size: 12px; color: var(--danger); }

/* ---- BADGES ---------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}
.badge-primary  { background: var(--primary-bg); color: var(--primary); }
.badge-success  { background: var(--success-bg); color: var(--success); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); }
.badge-danger   { background: var(--danger-bg);  color: var(--danger);  }
.badge-info     { background: var(--info-bg);    color: var(--info);    }
.badge-secondary{ background: #f1f5f9;           color: var(--secondary);}

/* ---- ALERTS ---------------------------------------------- */
.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  border: 1px solid transparent;
  animation: slideDown 0.3s ease;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.alert-content { display: flex; align-items: center; gap: 10px; flex: 1; font-size: 13.5px; font-weight: 500; }
.alert-content svg { width: 18px; height: 18px; flex-shrink: 0; }

.alert-success { background: var(--success-bg); border-color: #bbf7d0; color: #166534; }
.alert-error   { background: var(--danger-bg);  border-color: #fecaca; color: #991b1b; }
.alert-warning { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }
.alert-info    { background: var(--info-bg);    border-color: #a5f3fc; color: #155e75; }

.alert-close { background: none; border: none; font-size: 20px; line-height: 1; opacity: .6; padding: 0 4px; transition: var(--transition); }
.alert-close:hover { opacity: 1; }

/* ---- TOOLBAR (search + actions) -------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.search-box { position: relative; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.search-box input { padding-left: 36px; width: 280px; }

.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- PAGINATION ------------------------------------------ */
.pagination { display: flex; align-items: center; gap: 4px; padding: 20px 24px; border-top: 1px solid var(--border); justify-content: center; }
.page-btn { padding: 6px 11px; border-radius: var(--radius); font-size: 13px; color: var(--text-secondary); border: 1px solid var(--border); background: var(--card-bg); transition: var(--transition); }
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.page-dots { color: var(--text-muted); padding: 6px 4px; }

/* ---- DETAIL VIEW ----------------------------------------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }
.detail-item label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; display: block; }
.detail-item p { font-size: 14px; color: var(--text-primary); font-weight: 500; }

/* ---- VENDA ITEMS TABLE ----------------------------------- */
.items-table-wrapper { overflow-x: auto; width: 100%; max-width: 100%; -webkit-overflow-scrolling: touch; }
.items-table { min-width: 700px; }
.items-table thead th { background: #f8fafc; }
.items-table input, .items-table select { border-radius: var(--radius); }
.remove-item-btn { padding: 6px 8px; background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; border-radius: var(--radius); transition: var(--transition); display: flex; align-items: center; justify-content: center; }
.remove-item-btn:hover { background: var(--danger); color: #fff; }
.remove-item-btn svg { width: 15px; height: 15px; }

/* ---- TOTAL SUMMARY --------------------------------------- */
.total-summary {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  max-width: 400px;
  margin-left: auto;
}
.total-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; color: var(--text-secondary); }
.total-row.subtotal { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 4px; }
.total-row.total-final { font-size: 18px; font-weight: 700; color: var(--text-primary); border-top: 2px solid var(--border); margin-top: 4px; padding-top: 10px; }
.total-row.discount { color: var(--danger); }

/* ---- MODAL ---------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 500; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; visibility: hidden; transition: var(--transition); }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { background: var(--card-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); max-width: 480px; width: 100%; padding: 32px; transform: translateY(-12px); transition: var(--transition); }
.modal-overlay.active .modal { transform: translateY(0); }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.modal-body  { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- LOGIN PAGE ------------------------------------------ */
.login-page { min-height: 100vh; background: var(--sidebar-bg); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--card-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 48px 44px; width: 100%; max-width: 420px; }
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo-icon { width: 56px; height: 56px; background: var(--primary); border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; color: #fff; margin: 0 auto 12px; letter-spacing: -1px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.login-logo p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.login-form .form-group { margin-bottom: 18px; }
.login-form label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 7px; }
.login-submit { width: 100%; margin-top: 8px; justify-content: center; padding: 12px; font-size: 15px; }
.login-footer { text-align: center; margin-top: 24px; font-size: 12.5px; color: var(--text-muted); }

/* ---- PRODUCT SEARCH (in vendas) -------------------------- */
.product-search-wrapper { position: relative; }
.product-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--card-bg); border: 1.5px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow-md); z-index: 50; max-height: 220px; overflow-y: auto; }
.product-result-item { padding: 10px 14px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.product-result-item:last-child { border-bottom: none; }
.product-result-item:hover,
.product-result-item.hover { background: var(--primary-bg); color: var(--primary); }
.product-result-item strong { font-weight: 600; }
.product-result-item small  { color: var(--text-muted); font-size: 11.5px; display: block; }

/* ---- CHIPS / FILTER ------------------------------------- */
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 500; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-secondary); transition: var(--transition); cursor: pointer; }
.chip:hover, .chip.active { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

/* ---- BREADCRUMB ----------------------------------------- */
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span { color: var(--text-primary); font-weight: 500; }
.breadcrumb-sep { color: var(--border); }

/* ---- TABS ----------------------------------------------- */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 24px; gap: 2px; }
.tab { padding: 10px 18px; font-size: 13.5px; font-weight: 500; color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: var(--transition); cursor: pointer; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---- EMPTY STATE ---------------------------------------- */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-state svg { width: 52px; height: 52px; color: var(--text-muted); margin: 0 auto 16px; opacity: .4; display: block; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p  { font-size: 13.5px; color: var(--text-muted); }

/* ---- ESTOQUE BAIXO -------------------------------------- */
.estoque-baixo { color: var(--danger); font-weight: 600; }
.estoque-ok    { color: var(--success); }
.estoque-zero  { color: var(--danger); font-weight: 700; }

/* ---- DIVIDER -------------------------------------------- */
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ---- UTILITY -------------------------------------------- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.text-primary-color { color: var(--primary); }
.fw-bold     { font-weight: 700; }
.fw-medium   { font-weight: 500; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }

/* ---- FORM ACTIONS --------------------------------------- */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 24px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

/* ---- RESPONSIVE ----------------------------------------- */

/* Tablet e abaixo (< 1024px) */
@media (max-width: 1024px) {
  /* Sidebar deslizante */
  .sidebar {
    transform: translateX(-100%);
    z-index: 300;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .main-wrapper { margin-left: 0 !important; max-width: 100vw; overflow-x: hidden; }
  .content { overflow-x: hidden; max-width: 100%; }
  .sidebar-overlay { display: block; opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; }
  .sidebar-overlay.visible { opacity: 1; visibility: visible; }
  .menu-toggle { display: flex; }

  /* Grids de formulário */
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
  .form-grid-4 { grid-template-columns: 1fr 1fr; }

  /* Vendas: colapsa para 1 coluna */
  .vendas-grid {
    grid-template-columns: 1fr !important;
  }
  /* Evita que filhos flex/grid extrapolem a largura do grid */
  .vendas-grid > * { min-width: 0; }
  /* Painel direito: remove sticky em mobile (fica abaixo do form) */
  .vendas-grid > div:last-child { position: static !important; top: auto !important; }

  /* Tabelas: scroll horizontal com suavidade */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  /* Layout geral */
  .content { padding: 16px 14px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }

  /* Topbar */
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar-date { display: none; }
  .topbar-logout span { display: none; }
  .topbar-logout { padding: 6px 8px; }
  .page-heading { font-size: 15px; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header > div:last-child { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .page-header .btn { flex: 1 1 auto; justify-content: center; min-width: 140px; }

  /* Cards */
  .card-body { padding: 16px; }
  .card-header { padding: 14px 16px 12px; flex-direction: row; flex-wrap: wrap; gap: 10px; }
  .card-header .btn { padding: 6px 12px; font-size: 12px; }

  /* Stats */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
  .stat-card { padding: 16px; gap: 12px; }
  .stat-value { font-size: 18px; }
  .stat-icon { width: 42px; height: 42px; }
  .stat-icon svg { width: 20px; height: 20px; }

  /* Formulários: tudo 1 coluna */
  .form-grid,
  .form-grid-2,
  .form-grid-3,
  .form-grid-4 { grid-template-columns: 1fr !important; }

  /* Sobrescrever grid-column:span nos formulários */
  .form-group[style*="grid-column"] { grid-column: 1 / -1 !important; }

  /* Toolbar de filtros */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 14px; }
  .search-box { width: 100%; }
  .search-box input { width: 100%; }
  .toolbar form { width: 100%; flex-wrap: wrap; gap: 8px; }
  .toolbar form input[type=date] { flex: 1 1 120px; width: auto; }
  .toolbar form .btn { flex-shrink: 0; }
  .filter-chips { flex-wrap: wrap; gap: 6px; }

  /* Tabelas */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0; width: 100%; }
  thead th { padding: 10px 12px; }
  tbody td { padding: 11px 12px; }

  /* Ações nas tabelas: botões menores */
  .table-actions { gap: 4px; }
  .table-actions .btn-sm { padding: 5px 8px; font-size: 12px; }

  /* Breadcrumb */
  .breadcrumb { flex-wrap: wrap; font-size: 12px; margin-bottom: 14px; }

  /* Botões gerais */
  .btn-lg { padding: 11px 20px; font-size: 14px; }

  /* Total summary */
  .total-summary { max-width: 100%; margin: 0; }

  /* Form actions */
  .form-actions { flex-direction: column-reverse; gap: 10px; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* Modal */
  .modal { padding: 24px 20px; margin: 16px; max-width: calc(100vw - 32px); }

  /* Detalhes de venda */
  .detail-grid { grid-template-columns: 1fr !important; gap: 14px; }

  /* Dashboard / Configurações / Visualizar venda: 2 col → 1 col */
  .dash-grid { grid-template-columns: 1fr !important; }
}

/* Mobile pequeno (< 480px) */
@media (max-width: 480px) {
  /* Layout */
  .content { padding: 12px 12px 36px; }

  /* Topbar */
  .topbar { padding: 0 12px; }
  .menu-toggle svg { width: 20px; height: 20px; }
  .page-heading { font-size: 14px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Stats: 1 coluna */
  .stats-grid { grid-template-columns: 1fr; gap: 10px; }
  .stat-card { padding: 14px 16px; }

  /* Login */
  .login-card { padding: 28px 20px; }
  .login-logo-icon { width: 48px; height: 48px; font-size: 18px; }
  .login-logo h1 { font-size: 18px; }

  /* Cards */
  .card-header { padding: 12px 14px 10px; }
  .card-body { padding: 14px 12px; }
  .card-title { font-size: 13.5px; }

  /* Botões: touch-friendly (min 44px altura) */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }

  /* Tabelas ainda menores */
  table { font-size: 12.5px; }
  thead th { font-size: 11px; padding: 8px 10px; }
  tbody td { padding: 9px 10px; }

  /* Toolbar */
  .toolbar { padding: 12px; }

  /* Formulário de vendas: tabela de itens - Mobile Card Layout */
  .items-table-wrapper { border-radius: 0; overflow-x: visible; }
  .items-table { min-width: 0; width: 100%; display: block; }
  .items-table thead { display: none; }
  .items-table tbody, .items-table tr, .items-table td { display: block; width: 100%; }
  .items-table tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  .items-table td {
    padding: 6px 0;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .items-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    min-width: 80px;
    flex-shrink: 0;
  }
  .items-table td:first-child::before { content: 'Produto'; }
  .items-table td:nth-child(2)::before { content: 'Qtde'; }
  .items-table td:nth-child(3)::before { content: 'Preço'; }
  .items-table td:nth-child(4)::before { content: 'Desc.'; }
  .items-table td:nth-child(5)::before { content: 'Acr.%'; }
  .items-table td:nth-child(6) { justify-content: space-between; }
  .items-table td:nth-child(6)::before { content: 'Subtotal'; }
  .items-table td:last-child::before { display: none; }
  .items-table td:last-child {
    justify-content: center;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    margin-top: 8px;
  }
  .items-table input {
    flex: 1;
    min-width: 0;
    width: 100% !important;
  }
  .items-table .product-search-wrapper { width: 100%; }
  .items-table .remove-item-btn {
    width: 100%;
    padding: 10px;
    font-size: 13px;
    gap: 6px;
  }

  /* Sobrepor inline style="width:Xpx" em inputs de toolbars e formulários */
  .toolbar input[type=date] { width: auto !important; max-width: 140px !important; }
  .toolbar .search-box input { width: 100% !important; max-width: 100% !important; }
  .card { max-width: 100%; }
  form { max-width: 100%; }

  /* Page header: botões empilhados */
  .page-header .btn { min-width: 0; flex: 1 1 100%; }

  /* Vendas e dash grids já colapsados desde 768px */
  .vendas-grid, .dash-grid { gap: 16px !important; }

  /* Tabela de vendas (index) - Mobile Card Layout */
  #mainTable { min-width: 0; width: 100%; display: block; }
  #mainTable thead { display: none; }
  #mainTable tbody, #mainTable tr, #mainTable td { display: block; width: 100%; }
  #mainTable tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: relative;
  }
  #mainTable td {
    padding: 4px 0;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  #mainTable td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    min-width: 70px;
    flex-shrink: 0;
  }
  #mainTable td:nth-child(1)::before { content: 'Nº'; }
  #mainTable td:nth-child(2)::before { content: 'Data'; }
  #mainTable td:nth-child(3)::before { content: 'Cliente'; }
  #mainTable td:nth-child(4)::before { content: 'Operador'; }
  #mainTable td:nth-child(5)::before { content: 'Subtotal'; }
  #mainTable td:nth-child(6)::before { content: 'Desc.'; }
  #mainTable td:nth-child(7) { font-weight: 700; color: var(--primary); }
  #mainTable td:nth-child(7)::before { content: 'Total'; }
  #mainTable td:nth-child(8)::before { content: 'Pagto'; }
  #mainTable td:nth-child(9)::before { content: 'Status'; }
  #mainTable td:nth-child(10)::before { display: none; }
  #mainTable td:nth-child(10) {
    justify-content: flex-start;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
    margin-top: 8px;
  }
  #mainTable .table-actions { justify-content: flex-start !important; }

}

/* ---- TELEMARKETING DRAWER -------------------------------- */
.tm-trigger {
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  touch-action: manipulation;
}
.tm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9998;
  transition: opacity .3s;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tm-overlay.open { display: block; }

.tm-drawer {
  position: fixed;
  top: 0; right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  height: -webkit-fill-available;
  background: var(--card-bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,.18);
  transform: translateX(100%);
  -webkit-transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  -webkit-transition: -webkit-transform .35s cubic-bezier(.4,0,.2,1);
  will-change: transform;
  touch-action: none;
  cursor: pointer;
}
.tm-drawer.open {
  transform: translateX(0);
  -webkit-transform: translateX(0);
}

.tm-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #fff;
  border-radius: 0;
}
.tm-drawer-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.tm-drawer-header h2 svg { width: 18px; height: 18px; opacity: .85; }
.tm-close-btn {
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
}
.tm-close-btn:hover { background: rgba(255,255,255,.25); }
.tm-close-btn svg { width: 18px; height: 18px; }

.tm-stats {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: #f8fafc;
}
.tm-stat-item {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  border-right: 1px solid var(--border);
}
.tm-stat-item:last-child { border-right: none; }
.tm-stat-num {
  font-size: 18px;
  font-weight: 700;
  display: block;
  line-height: 1.2;
}
.tm-stat-num.color-warn { color: var(--warning); }
.tm-stat-num.color-orange { color: #ea580c; }
.tm-stat-num.color-danger { color: var(--danger); }
.tm-stat-num.color-success { color: var(--success); }
.tm-stat-label { font-size: 10px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }

.tm-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  background: #fff;
  overflow-x: auto;
}
.tm-tab {
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color .2s, border-color .2s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tm-tab:hover { color: var(--text-primary); }
.tm-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tm-tab-badge {
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}
.tm-tab.active .tm-tab-badge { background: var(--primary); color: #fff; }
.tm-tab[data-tab="nunca"] .tm-tab-badge { background: #faf5ff; color: #6b21a8; }
.tm-tab[data-tab="nunca"].active .tm-tab-badge { background: #6b21a8; color: #fff; }
.tm-tab[data-tab="comunicados"] .tm-tab-badge { background: #f0fdf4; color: var(--success); }
.tm-tab[data-tab="comunicados"].active .tm-tab-badge { background: var(--success); color: #fff; }

.tm-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.tm-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 180px;
  color: var(--text-muted);
  font-size: 13.5px;
}
.tm-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: tm-spin .7s linear infinite;
}
@keyframes tm-spin { to { transform: rotate(360deg); } }

.tm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 20px;
  color: var(--text-muted);
  text-align: center;
}
.tm-empty svg { width: 40px; height: 40px; opacity: .4; }
.tm-empty p { font-size: 13.5px; }

.tm-client-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: box-shadow .2s;
}
.tm-client-card:hover { box-shadow: var(--shadow-md); }

.tm-client-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.tm-client-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tm-client-info { flex: 1; min-width: 0; }
.tm-client-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tm-client-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 3px;
  align-items: center;
}
.tm-client-meta small { font-size: 11.5px; color: var(--text-muted); }

.tm-last-purchase {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tm-last-purchase.warn   { background: var(--warning-bg); color: var(--warning); }
.tm-last-purchase.orange { background: #fff7ed; color: #ea580c; }
.tm-last-purchase.danger { background: var(--danger-bg); color: var(--danger); }
.tm-last-purchase.muted  { background: #f1f5f9; color: var(--text-muted); }

.tm-client-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tm-btn-wa {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: #25D366;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s;
}
.tm-btn-wa:hover { background: #128C7E; color: #fff; }
.tm-btn-wa svg { width: 14px; height: 14px; }

.tm-btn-contact {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.tm-btn-contact:hover { background: var(--primary); color: #fff; }
.tm-btn-contact.done { background: var(--success-bg); color: var(--success); border-color: #86efac; cursor: default; }
.tm-btn-contact svg { width: 14px; height: 14px; }

.tm-contact-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--success);
  background: var(--success-bg);
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 600;
}

.tm-comunicado-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  background: #fff;
}
.tm-comunicado-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.tm-comunicado-nome { font-weight: 600; font-size: 13.5px; color: var(--text-primary); }
.tm-comunicado-data { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.tm-comunicado-obs  { font-size: 12px; color: var(--text-secondary); margin-top: 3px; font-style: italic; }
.tm-comunicado-op   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.tm-obs-area {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--text-primary);
  resize: none;
  margin-top: 8px;
  font-family: var(--font);
  background: #f8fafc;
  transition: border-color .2s;
  display: none;
}
.tm-obs-area:focus { outline: none; border-color: var(--border-focus); background: #fff; }
.tm-obs-area.visible { display: block; }

@media (max-width: 540px) {
  .tm-drawer { width: 100vw; }

  /* Paginação */
  .pagination { gap: 2px; padding: 14px 12px; flex-wrap: wrap; justify-content: center; }
  .page-btn { padding: 5px 9px; font-size: 12px; }

  /* Topbar logout: só ícone */
  .topbar-logout { display: none; }
}
