@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700;800&family=Manrope:wght@400;500;600;700&display=swap');

:root {
  --bg-main: #061733;
  --bg-secondary: #03102A;
  --bg-outer: #02091A;
  --body-gradient-start: #0b2555;
  --yellow: #FFD000;
  --accent-text: #FFCC00; /* amarelo usado como texto/borda - precisa ficar mais escuro no tema claro */
  --on-accent: #04101f; /* texto sobre fundo amarelo solido - sempre escuro, nos dois temas */
  --accent-blue: #0C88FA; /* azul ClimaDek (paleta oficial) - usado em foco/links, junto do dourado */
  --focus-color: var(--yellow);
  --focus-shadow: rgba(255,204,0,0.15);
  --orange: #F5A623;
  --green: #34D399;
  --text: #F2F6FC;
  --text-muted: rgba(242, 246, 252, 0.6);
  --border: rgba(255, 255, 255, 0.14);
  --border-soft: rgba(255, 255, 255, 0.08);
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-bg-hover: rgba(255, 255, 255, 0.09);
  --input-bg: rgba(255, 255, 255, 0.07);
  --wash-weak: rgba(255, 255, 255, 0.03);
  --wash-mid: rgba(255, 255, 255, 0.06);
  --wash-strong: rgba(255, 255, 255, 0.09);
  --danger: #e0473e;
  --radius: 15px;
  --sidebar-w: 230px;

  --sidebar-bg: #03102A;
  --sidebar-text: #F2F6FC;
  --sidebar-text-muted: rgba(242, 246, 252, 0.6);
  --sidebar-border: rgba(255, 255, 255, 0.1);
  --sidebar-wash: rgba(255, 255, 255, 0.05);

  /* aliases legados (mantidos para nao quebrar referencias antigas) */
  --navy: var(--bg-secondary);
  --navy-dark: var(--bg-outer);
  --blue: var(--yellow);
  --blue-medium: var(--orange);
  --blue-light: var(--yellow);
  --yellow-dark: #e0b700;
  --gray: var(--text-muted);
  --gray-light: var(--bg-main);
  --success: var(--green);
  --white: var(--text);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg-main: #eef2f8;
  --bg-secondary: #ffffff;
  --bg-outer: #e4e9f2;
  --body-gradient-start: #ffffff;
  --accent-text: #9c6b0a;
  --text: #0b1220;
  --text-muted: #5b6b87;
  --border: #dde5f0;
  --border-soft: #e6ebf3;
  --card-bg: #ffffff;
  --card-bg-hover: #f7f9fc;
  --input-bg: #ffffff;
  --wash-weak: rgba(6, 23, 51, 0.035);
  --wash-mid: rgba(6, 23, 51, 0.055);
  --wash-strong: rgba(6, 23, 51, 0.08);
  --focus-color: var(--accent-blue);
  --focus-shadow: rgba(12, 136, 250, 0.18);

  /* sidebar clara com um leve tom azulado; usa a logo com texto preto (logo-light.png) */
  --sidebar-bg: #f2f6fd;
  --sidebar-text: #0b1220;
  --sidebar-text-muted: #5b6b87;
  --sidebar-border: #dde5f0;
  --sidebar-wash: rgba(12, 136, 250, 0.07);

  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  font-family: "Manrope", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background: radial-gradient(circle at 15% 0%, var(--body-gradient-start) 0%, var(--bg-main) 45%, var(--bg-outer) 100%);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

h1, h2, h3, .brand-font { font-family: "Sora", "Manrope", sans-serif; }

a { color: inherit; text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar - acompanha o tema. No escuro usa a logo com fundo navy (logo-navy.png);
   no claro, a logo com texto preto e fundo transparente (logo-light.png).
   Fica fixa na tela (position: sticky) com altura de 100vh: com muitos itens de
   menu, so a lista de navegacao rola por dentro - o rodape (usuario/Sair) sempre
   fica visivel, sem precisar rolar a pagina inteira pra encontrar o botao Sair. */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}
.sidebar .logo { padding: 0 20px 20px; flex-shrink: 0; }
.sidebar .logo img { width: 100%; max-width: 170px; display: block; border-radius: 10px; }
.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.sidebar nav a {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: "Sora", sans-serif;
  color: var(--sidebar-text-muted);
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--sidebar-wash); color: var(--sidebar-text); }
.sidebar nav a.active {
  background: rgba(255, 204, 0, 0.1);
  color: var(--accent-text);
  border-left-color: var(--accent-text);
}

/* Botao de tema (canto da sidebar) */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 20px 4px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--sidebar-border);
  background: var(--sidebar-wash);
  color: var(--sidebar-text-muted);
  font-family: "Sora", sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  width: calc(100% - 40px);
  transition: filter 0.15s;
}
.theme-toggle:hover { filter: brightness(1.15); color: var(--sidebar-text); border-color: var(--accent-blue); }
.theme-toggle .icon { font-size: 14px; line-height: 1; }

/* Main */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--wash-weak);
  border-bottom: 1px solid var(--border);
  padding: 18px 76px 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: relative;
}
.topbar h1 { font-size: 21px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input[type="date"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background-color: var(--input-bg);
  color: var(--text);
}
.filters select { padding-right: 28px; }
.content { padding: 26px 28px; overflow-x: auto; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 12px;
  border: none;
  font-size: 13px;
  font-weight: 700;
  font-family: "Sora", sans-serif;
  cursor: pointer;
  background: var(--wash-strong);
  color: var(--text);
  border: 1px solid var(--border);
  transition: filter 0.15s, transform 0.1s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--yellow);
  color: var(--on-accent);
  font-weight: 800;
  border: none;
  box-shadow: 0 0 0 rgba(255,204,0,0.4);
}
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 0 18px rgba(255,204,0,0.35); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent-text); color: var(--accent-text); }
.btn.ghost.active { border-color: var(--accent-text); color: var(--accent-text); background: var(--wash-mid); }
.btn.danger { background: var(--danger); color: #fff; border: none; }
.btn.small { padding: 6px 12px; font-size: 12px; }

/* Cards / stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(6px);
  min-width: 0;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  margin-top: 8px;
  color: var(--text);
  font-size: clamp(17px, 1.6vw + 10px, 28px);
  line-height: 1.15;
  word-break: break-word;
}
.stat-card .value.yellow { color: var(--accent-text); }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  backdrop-filter: blur(6px);
}
.panel h2 { font-size: 15px; margin: 0 0 14px; font-weight: 700; }

/* Kanban */
.kanban {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.kanban-col {
  background: var(--wash-weak);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 270px;
  max-width: 270px;
  flex-shrink: 0;
  padding: 12px;
  min-height: 200px;
}
.kanban-col.dragover { background: var(--focus-shadow); outline: 2px dashed var(--focus-color); }
.kanban-col h3 {
  font-size: 13px;
  margin: 4px 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  color: var(--text);
  font-weight: 700;
  gap: 8px;
}
.kanban-col h3 .stage-title { flex: 1; }
.kanban-col h3 .stage-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; }
.kanban-col h3 .count {
  background: var(--wash-strong);
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}
.kanban-col h3 .col-value {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 9px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  cursor: grab;
  border-left: 3px solid var(--accent-text);
  touch-action: none;
  user-select: none;
}
.card:hover { background: var(--card-bg-hover); }
.card:active { cursor: grabbing; }
.card.dragging { box-shadow: 0 10px 28px rgba(0,0,0,0.35); opacity: 0.9; cursor: grabbing; }
.card.stale-warn { border-left-color: var(--orange); }
.card.stale-danger { border-left-color: var(--danger); }
.card .name { font-weight: 700; font-size: 13px; margin-bottom: 4px; font-family: "Sora", sans-serif; user-select: text; }
.card .name.lead-name { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.card .name.lead-name:hover { color: var(--accent-text); }
.card .meta { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.card .stale-badge { font-size: 11px; font-weight: 700; margin-top: 6px; padding: 3px 8px; border-radius: 20px; display: inline-block; }
.card .stale-badge.stale-warn { background: rgba(245,166,35,0.15); color: var(--orange); }
.card .stale-badge.stale-danger { background: rgba(224,71,62,0.15); color: var(--danger); }
.card .badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  background: var(--yellow);
  color: var(--on-accent);
  padding: 3px 8px;
  border-radius: 20px;
  margin-top: 6px;
}
.card select { width: 100%; font-size: 11px; margin-top: 6px; padding: 5px; padding-right: 22px; border-radius: 8px; border: 1px solid var(--border); background-color: var(--input-bg); color: var(--text); background-position: right 6px center; }
.card .actions { margin-top: 6px; display: flex; gap: 4px; }

/* Table */
table { border-collapse: collapse; width: 100%; background: transparent; }
th, td { border-bottom: 1px solid var(--border); padding: 11px 13px; text-align: left; font-size: 13px; }
th { color: var(--accent-text); font-weight: 700; font-family: "Sora", sans-serif; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--wash-weak); }
tr.row-flagged td { background: rgba(245,166,35,0.08); }
tr.row-flagged:hover td { background: rgba(245,166,35,0.14); }
.btn-flag {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 8px; cursor: pointer; opacity: 0.4; filter: grayscale(1); font-size: 14px;
}
.btn-flag.active { opacity: 1; filter: none; border-color: var(--orange); background: rgba(245,166,35,0.15); }

@keyframes row-flash-anim {
  0%, 100% { background: transparent; }
  30% { background: rgba(255,204,0,0.22); }
}
tr.row-flash td { animation: row-flash-anim 1.5s ease; }

/* Diagrama de Gantt (Lista de Instalação) */
.gantt { overflow-x: auto; padding-bottom: 6px; }
.gantt-header, .gantt-lane { display: flex; width: max-content; }
.gantt-header { border-bottom: 1px solid var(--border); }
.gantt-row-label {
  width: 130px; flex-shrink: 0; padding: 8px 10px; font-size: 12px; font-weight: 700;
  font-family: "Sora", sans-serif; color: var(--text); display: flex; align-items: center;
  border-right: 1px solid var(--border); position: sticky; left: 0; background: var(--bg-secondary); z-index: 1;
}
.gantt-days { display: flex; }
.gantt-day {
  width: 46px; flex-shrink: 0; text-align: center; font-size: 10px; line-height: 1.4;
  color: var(--text-muted); padding: 6px 0; border-right: 1px solid var(--border-soft);
}
.gantt-day.weekend { background: var(--wash-weak); }
.gantt-day.today { color: var(--accent-text); font-weight: 700; }
.gantt-lane { border-top: 1px solid var(--border-soft); min-height: 44px; }
.gantt-lane-body { position: relative; }
.gantt-bar {
  position: absolute; top: 7px; height: 30px; border-radius: 8px; font-size: 11px; font-weight: 700;
  color: #04101f; display: flex; align-items: center; padding: 0 8px; overflow: hidden; white-space: nowrap;
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.3); background: var(--yellow);
}
.gantt-bar:hover { filter: brightness(1.1); }
.gantt-bar.gantt-aguardando_agendamento { background: #9aa3af; }
.gantt-bar.gantt-agendada { background: var(--yellow); }
.gantt-bar.gantt-em_execucao { background: var(--orange); }
.gantt-bar.gantt-concluida { background: var(--green); }

/* Calendario (Tarefas / Lembretes) */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-hd { font-size: 11px; font-weight: 700; color: var(--text-muted); text-align: center; padding: 4px 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.cal-day {
  min-height: 76px; border: 1px solid var(--border); border-radius: 10px; padding: 6px 8px;
  cursor: pointer; background: var(--wash-weak); transition: background 0.12s, border-color 0.12s;
}
.cal-day:hover { background: var(--wash-mid); }
.cal-day.other { opacity: 0.4; }
.cal-day.today { border-color: var(--accent-text); }
.cal-day.today .cal-daynum { color: var(--accent-text); font-weight: 800; }
.cal-day.selected { border-color: var(--focus-color); box-shadow: 0 0 0 2px var(--focus-shadow); }
.cal-daynum { font-family: "Sora", sans-serif; font-size: 12.5px; font-weight: 700; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; align-items: center; }
.cal-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.cal-more { font-size: 9.5px; color: var(--text-muted); font-weight: 700; }

/* Sininho de notificacoes */
.notif-wrap { position: absolute; top: 14px; right: 24px; }
.notif-bell {
  position: relative; background: var(--wash-strong); border: 1px solid var(--border); border-radius: 10px;
  width: 38px; height: 38px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.notif-bell:hover { filter: brightness(1.15); }
.notif-badge {
  position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 800; font-family: "Sora", sans-serif; min-width: 17px; height: 17px;
  border-radius: 20px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid var(--bg-main);
}
.notif-panel {
  position: absolute; top: 46px; right: 0; width: 340px; max-width: 90vw; max-height: 420px; overflow-y: auto;
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  z-index: 60;
}
.notif-panel-hd {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-secondary);
}
.notif-list { display: flex; flex-direction: column; }
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:hover { background: var(--wash-weak); }
.notif-item.unread { background: rgba(12,136,250,0.07); }
.notif-item.unread .notif-msg { font-weight: 700; }
.notif-msg { font-size: 13px; line-height: 1.4; }
.notif-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

@media (max-width: 700px) {
  .cal-hd:nth-child(n) { font-size: 9px; }
  .cal-day { min-height: 50px; padding: 4px 5px; }
}

select, input[type="text"], input[type="number"], input[type="email"], input[type="tel"], input[type="date"], input[type="password"], textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  font-size: 13px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%23F2F6FC'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
:root[data-theme="light"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%230b1220'/></svg>");
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--focus-color);
  box-shadow: 0 0 0 3px var(--focus-shadow);
}
::placeholder { color: var(--text-muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2,9,26,0.7);
  display: none; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px;
  width: 420px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin-top: 0; font-size: 17px; }
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-size: 12px; font-weight: 700; color: var(--text-muted); font-family: "Sora", sans-serif; }
.form-row select, .form-row input, .form-row textarea { width: 100%; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Busca com autocompletar (ex: seletor de produto em Gerar Proposta) */
.product-search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 10px;
  margin-top: 4px; max-height: 260px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.product-search-item { padding: 8px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); background: var(--bg-secondary); }
.product-search-item:last-child { border-bottom: none; }
.product-search-item[data-id]:hover { background: var(--card-bg-hover); }

.badge-stage {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 4px 11px; border-radius: 20px;
  background: var(--wash-strong); color: var(--text);
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    padding: 10px 14px; overflow-x: auto; overflow-y: visible;
  }
  .sidebar .logo { padding: 0 10px 0 0; }
  .sidebar .logo img { max-width: 110px; }
  .sidebar nav { flex: none; flex-direction: row; margin-top: 0; overflow-y: visible; }
  .sidebar nav a { padding: 8px 12px; white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .sidebar nav a.active { border-left: none; border-bottom-color: var(--accent-text); }
  .theme-toggle { width: auto; margin: 0 0 0 8px; }
}
