/* turn-crm — The Turn AI brand */
:root {
  /* Surfaces (The Turn AI brand) */
  --bg:           #0a0a0a;
  --surface-1:    #141414;
  --surface-2:    #1a1a1a;
  --surface-3:    #222;
  --surface-hover: #1f1f1f;

  /* Borders */
  --border:       #222;
  --border-strong: #333;

  /* Text */
  --text:         #e5e5e5;
  --text-muted:   #888;
  --text-dim:     #555;

  /* Brand — laranja → vermelho */
  --orange:       #f97316;
  --red:          #ef4444;
  --grad:         linear-gradient(135deg, #f97316, #ef4444);
  --accent:       #f97316;
  --accent-hover: #fb923c;
  --accent-soft:  rgba(249, 115, 22, 0.12);
  --accent-ring:  rgba(249, 115, 22, 0.35);

  /* Semantic */
  --green:        #22c55e;
  --yellow:       #eab308;
  --gold:         #eab308;
  --pink:         #ec4899;
  --violet:       #a855f7;
  --blue:         #3b82f6;

  /* Layout */
  --radius-sm:    6px;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow-sm:    0 1px 2px rgba(0,0,0,0.6);
  --shadow:       0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:    0 12px 48px rgba(0,0,0,0.6);
  --shadow-orange: 0 4px 18px rgba(249, 115, 22, 0.35);
}

/* =============== RESET =============== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* =============== BUTTONS =============== */
button {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover {
  background: var(--surface-hover);
  border-color: var(--orange);
  color: var(--orange);
}
button:active { transform: translateY(1px); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--grad);
  border-color: transparent;
  color: white;
  font-weight: 600;
}
button.primary:hover {
  opacity: 0.92;
  border-color: transparent;
  color: white;
  box-shadow: var(--shadow-orange);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: transparent;
}

button.danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
button.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

/* =============== INPUTS =============== */
input, select, textarea {
  font: inherit;
  background: #111;
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 11px 14px;
  border-radius: var(--radius);
  width: 100%;
  transition: all 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
label > input, label > select, label > textarea {
  margin-top: 6px;
  font-weight: 400;
  color: var(--text);
}

/* =============== LOGO =============== */
.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-logo .turny {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(249, 115, 22, 0.3));
}
.brand-name {
  font-size: 18px;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}
.brand-tag {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* =============== LOGIN =============== */
.auth-bg {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, rgba(249, 115, 22, 0.18), transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 100%, rgba(239, 68, 68, 0.12), transparent 60%),
    var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  padding: 48px 40px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card .brand-logo {
  justify-content: center;
  margin-bottom: 32px;
}
.login-card .brand-logo .turny { width: 56px; height: 56px; }
.login-card .brand-name { font-size: 22px; }
.login-card form > * { text-align: left; }
.login-card button[type=submit] {
  width: 100%;
  background: var(--grad);
  border-color: transparent;
  color: white;
  padding: 13px;
  margin-top: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
}
.login-card button[type=submit]:hover {
  opacity: 0.92;
  box-shadow: var(--shadow-orange);
}
.error {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: var(--radius);
  font-size: 13px;
}
.footer-hint {
  margin-top: 28px;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* =============== APP SHELL =============== */
.app-bg { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand-logo { min-width: 220px; }
.topbar .brand-logo .turny { width: 32px; height: 32px; }
.topbar .brand-name { font-size: 16px; }

.tabs { display: flex; gap: 2px; flex: 1; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.tab:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: transparent;
}
.tab.active {
  background: var(--accent-soft);
  color: var(--orange);
  border-color: rgba(249, 115, 22, 0.2);
}

.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.userbox .avatar { width: 32px; height: 32px; font-size: 11px; }

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--grad);
  color: white;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.avatar.gray  { background: linear-gradient(135deg, #6b7280, #4b5563); }
.avatar.green { background: linear-gradient(135deg, #22c55e, #16a34a); }
.avatar.pink  { background: linear-gradient(135deg, #ec4899, #be185d); }
.avatar.amber { background: linear-gradient(135deg, #eab308, #b45309); }
.avatar.cyan  { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.avatar.blue  { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }

/* =============== FILTER BAR =============== */
.filterbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.filterbar input { max-width: 280px; }
.filterbar select { width: auto; min-width: 170px; }
.filterbar #newDealBtn { margin-left: auto; }

#mainView {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
  background: var(--bg);
}
.view { display: none; }
.view.active { display: block; }

/* =============== KANBAN =============== */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 16px;
  height: calc(100vh - 64px - 70px - 40px);
  align-items: stretch;
}
.column {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  overflow: hidden;
}
.column-header {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.column-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.5);
}
.column-title {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
  letter-spacing: -0.01em;
}
.column-count {
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  min-width: 24px;
  text-align: center;
}
.column-body {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
}

/* =============== CARD =============== */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: grab;
  transition: all 0.15s ease;
}
.card:hover {
  border-color: rgba(249, 115, 22, 0.45);
  background: var(--surface-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.5; transform: rotate(2deg); }
.card.sortable-ghost { opacity: 0.4; background: var(--surface-3); }

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.card-head .avatar { width: 30px; height: 30px; font-size: 11px; }
.card-name {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.card-value {
  font-size: 12px;
  color: var(--green);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-meta-row { display: flex; align-items: center; gap: 6px; }
.card-meta-row svg, .card-meta-row .icon {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  opacity: 0.7;
}

.card-tags {
  margin-top: 10px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* =============== TAG CHIPS =============== */
.tag-chip {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  color: white;
  letter-spacing: 0.01em;
  background: var(--orange);
  white-space: nowrap;
}
.tag-chip.stage {
  font-size: 11px;
  padding: 4px 10px;
}

/* =============== DRAWER =============== */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: calc(100vw - 40px);
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.drawer header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.drawer header h2 {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  letter-spacing: -0.01em;
}
.drawer header button {
  font-size: 22px;
  padding: 4px 10px;
  line-height: 1;
}
#drawerContent {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* =============== PANELS =============== */
.panel-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}
.panel-section h3 {
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.panel-section p { color: var(--text-muted); font-size: 13px; }
.panel-section code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--orange);
}

/* =============== TABLE =============== */
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr[data-deal] { cursor: pointer; }

.list-empty {
  text-align: center;
  padding: 80px 40px;
  color: var(--text-dim);
  font-size: 14px;
  background: var(--surface-1);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.list-empty::before {
  content: '∅';
  display: block;
  font-size: 32px;
  margin-bottom: 8px;
  color: var(--text-dim);
}

/* =============== TIMELINE =============== */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: var(--radius);
  border-left: 3px solid var(--orange);
  font-size: 13px;
}
.timeline-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: capitalize;
  font-weight: 500;
}
.timeline-item-body { color: var(--text); line-height: 1.4; }
.timeline-item-meta { margin-top: 4px; color: var(--text-muted); font-size: 12px; }

.timeline-item.stage_change   { border-left-color: var(--orange); }
.timeline-item.deal_created   { border-left-color: var(--green); }
.timeline-item.deal_won       { border-left-color: var(--green); background: rgba(34, 197, 94, 0.06); }
.timeline-item.deal_lost      { border-left-color: var(--red); background: rgba(239, 68, 68, 0.05); }
.timeline-item.comment        { border-left-color: var(--gold); }
.timeline-item.meta_event     { border-left-color: var(--violet); }
.timeline-item.task           { border-left-color: var(--orange); }
.timeline-item.task_done      { border-left-color: var(--green); }
.timeline-item.tag_added,
.timeline-item.tag_removed    { border-left-color: var(--pink); }
.timeline-item.whatsapp_in    { border-left-color: #25D366; }
.timeline-item.whatsapp_out   { border-left-color: #128C7E; }
.timeline-item.system         { border-left-color: var(--text-dim); }

/* =============== FORM HELPERS =============== */
.form-row { display: flex; gap: 10px; align-items: flex-end; }
.form-row label { flex: 1; margin-bottom: 0; }

textarea { resize: vertical; min-height: 80px; font-family: inherit; }

/* =============== UTILITY =============== */
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; }
.text-orange { color: var(--orange); }
.text-grad { background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; font-weight: 700; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-grow { flex: 1; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.kpi-row {
  display: flex;
  gap: 14px;
  margin-bottom: 16px;
}
.kpi {
  flex: 1;
  background: var(--surface-1);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius-lg);
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi.win .kpi-value { color: var(--green); }
.kpi.loss .kpi-value { color: var(--red); }
.kpi.brand .kpi-value { background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

pre {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}
