/* IOT-CRM — estilos globais */
:root {
  --red: #d32f2f;
  --red-dark: #a82424;
  --black: #111111;
  --white: #ffffff;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --topnav-h: 52px;
  --subnav-h: 44px;
  --nav-total: 96px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #f0f2f5;
  color: var(--black);
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =========================================================
   TOPNAV — barra escura fixa no topo
   ========================================================= */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topnav-h);
  background: var(--black);
  color: var(--white);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 200;
  gap: 12px;
}

.topnav-brand {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--white);
  margin-right: auto;
  text-decoration: none;
}
.topnav-brand span { color: var(--red); }

.topnav-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--red);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.nav-user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.nav-username { font-size: 13px; font-weight: 600; color: var(--white); }
.nav-role    { font-size: 11px; color: #9ca3af; }

.nav-logout {
  color: #9ca3af;
  font-size: 18px;
  margin-left: 6px;
  line-height: 1;
  display: flex;
  align-items: center;
}
.nav-logout:hover { color: var(--white); text-decoration: none; }

/* =========================================================
   SUBNAV — barra de navegação secundária
   ========================================================= */
.subnav {
  position: fixed;
  top: var(--topnav-h);
  left: 0; right: 0;
  height: var(--subnav-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 8px;
  z-index: 199;
  overflow: visible;
}

.subnav > a {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
  cursor: pointer;
}
.subnav > a:hover { color: var(--black); text-decoration: none; }
.subnav > a.active {
  color: var(--red);
  border-bottom-color: var(--red);
  font-weight: 600;
}

.subnav-sep {
  width: 1px;
  background: var(--border);
  margin: 10px 4px;
  flex-shrink: 0;
}

/* Dropdown no subnav */
.subnav-dropdown {
  position: relative;
  display: flex;
  align-items: stretch;
}

.subnav-dropdown > a {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
  cursor: pointer;
  user-select: none;
}
.subnav-dropdown > a:hover { color: var(--black); text-decoration: none; }
.subnav-dropdown > a.active {
  color: var(--red);
  border-bottom-color: var(--red);
  font-weight: 600;
}

.subnav-caret { font-size: 10px; margin-left: 2px; opacity: 0.6; }

.subnav-menu {
  display: none;
  position: absolute;
  top: calc(100% + 1px);
  left: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 190px;
  box-shadow: var(--shadow);
  z-index: 300;
  padding: 4px 0;
}
.subnav-dropdown:hover .subnav-menu { display: block; }

.subnav-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
  border-bottom: none;
}
.subnav-menu a:hover { background: var(--gray-light); color: var(--black); text-decoration: none; }
.subnav-menu a.active { color: var(--red); font-weight: 600; }
.subnav-menu a i { font-size: 14px; width: 16px; text-align: center; }

/* =========================================================
   LAYOUT PRINCIPAL
   ========================================================= */
.main { margin-top: var(--nav-total); min-height: calc(100vh - var(--nav-total)); }

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; color: var(--black); }

.content { padding: 24px; }

/* =========================================================
   COMPONENTES
   ========================================================= */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--red-dark); text-decoration: none; color: var(--white); }
.btn-secondary { background: var(--gray); }
.btn-secondary:hover { background: #4b5563; }
.btn-outline {
  background: transparent;
  color: #374151;
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--gray-light); color: var(--black); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-sm i { font-size: 13px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(211,47,47,0.12);
}
label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: #374151; }

table { width: 100%; border-collapse: collapse; background: var(--white); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th {
  background: #fafafa;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray);
  font-weight: 600;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbff; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-red   { background: #fee2e2; color: #b91c1c; }
.badge-gray  { background: var(--gray-light); color: var(--gray); }
.badge-black { background: #1f2937; color: var(--white); }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue  { background: #dbeafe; color: #1d4ed8; }
.badge-yellow { background: #fef9c3; color: #a16207; }

/* --- Flash --- */
.flash {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* --- Modal (dialog) --- */
dialog {
  border: none;
  border-radius: 12px;
  padding: 28px;
  width: 500px;
  max-width: 94vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
dialog::backdrop { background: rgba(0,0,0,0.45); }
dialog h3 { margin-top: 0; font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* --- Feed --- */
.feed-item {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
}
.feed-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--red);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.feed-body { font-size: 14px; }
.feed-meta { font-size: 12px; color: var(--gray); margin-top: 4px; }

/* --- Kanban --- */
.kanban { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 16px; }
.kanban-col {
  background: #f8f9fb;
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 270px;
  width: 270px;
  flex-shrink: 0;
}
.kanban-col-header {
  padding: 12px 14px;
  font-weight: 700;
  font-size: 13px;
  border-bottom: 2px solid var(--red);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 10px 10px 0 0;
}
.kanban-col-header .total { font-size: 11px; color: var(--gray); font-weight: 400; }
.kanban-cards { padding: 8px; min-height: 60px; }
.kanban-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: grab;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.1s;
}
.kanban-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kanban-card:active { cursor: grabbing; }
.kanban-card .deal-title { font-weight: 600; margin-bottom: 4px; }
.kanban-card .deal-client { color: var(--gray); font-size: 12px; }
.kanban-card .deal-value { color: var(--red); font-weight: 700; margin-top: 8px; font-size: 13px; }
.kanban-card.sortable-ghost { opacity: 0.35; }

/* --- Tarefas --- */
.task-done { opacity: 0.6; }
.task-done .task-title { text-decoration: line-through; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 8px 16px;
  font-size: 14px;
  color: var(--gray);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.active {
  color: var(--red);
  font-weight: 600;
  border-bottom-color: var(--red);
}

/* --- Login --- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
}
.auth-card {
  background: var(--white);
  border-radius: 14px;
  padding: 40px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
}
.auth-card .logo { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 28px; }
.auth-card .logo span { color: var(--red); }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 18px; padding: 10px; }

/* --- Preço --- */
.price-tag { font-weight: 700; color: var(--red); }

/* --- Visualizador de documento --- */
.doc-preview {
  padding: 32px 40px;
  min-height: 200px;
  font-size: 14px;
  line-height: 1.7;
}
.doc-preview h1, .doc-preview h2, .doc-preview h3 { color: var(--red); }
.doc-preview table { margin: 12px 0; }

/* --- Utilidades --- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { margin: 0; font-size: 20px; font-weight: 700; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.muted { color: var(--gray); font-size: 13px; }
.empty-state { text-align: center; color: var(--gray); padding: 60px 40px; }
.empty-state i { font-size: 40px; display: block; margin-bottom: 12px; opacity: 0.4; }

/* --- Texto truncado com tooltip nativo --- */
.truncate-tip {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: middle;
  cursor: default;
}

/* --- Tabela com wrapper card --- */
.table-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table-card table { margin: 0; }
