/* Insta CRM styles */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1c2b33;
  --muted: #6b7c8a;
  --primary: #2f6df6;
  --primary-dark: #1f55cf;
  --accent: #c13584;        /* instagram-ish */
  --ok: #1f9d57;
  --warn: #c9820a;
  --danger: #d23b3b;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

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

/* --- Centered auth pages --- */
body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.auth-card { width: 380px; }
.auth-card h1 { font-size: 20px; margin-bottom: 16px; }
.auth-card p { color: var(--muted); margin-bottom: 16px; }

/* --- Forms --- */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password],
select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font: inherit;
  font-weight: 400;
  background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,109,246,.12);
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f5f6f8; text-decoration: none; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: #e8b4b4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Alerts & badges --- */
.alert { padding: 10px 12px; border-radius: 7px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #fdeaea; color: var(--danger); }
.alert-ok { background: #e8f6ee; color: var(--ok); }
.alert-warn { background: #fdf3e0; color: var(--warn); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
}
.badge-role { background: #eef1f5; color: var(--muted); }
.badge-open { background: #e8f6ee; color: var(--ok); }
.badge-pending { background: #fdf3e0; color: var(--warn); }
.badge-closed { background: #eef1f5; color: var(--muted); }

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar-brand a { font-weight: 800; color: var(--accent); font-size: 16px; }
.topbar-nav { display: flex; gap: 4px; margin-left: 26px; }
.topbar-nav a {
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 600;
}
.topbar-nav a:hover { background: #f5f6f8; text-decoration: none; }
.topbar-nav a.is-active { background: #eef3ff; color: var(--primary); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-name { font-weight: 600; }

/* --- Generic page --- */
.page-main { max-width: 960px; margin: 24px auto; padding: 0 18px; }
.page-main h1 { font-size: 20px; margin-bottom: 16px; }
.page-main h2 { font-size: 15px; margin: 22px 0 10px; }

table { width: 100%; border-collapse: collapse; background: #fff; }
table th, table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
table th { font-size: 12px; color: var(--muted); text-transform: uppercase; }

/* --- Inbox 3-column layout --- */
body.inbox { height: 100vh; overflow: hidden; }
.inbox-main { height: calc(100vh - 52px); }
.inbox-layout { display: flex; height: 100%; }

.conv-list {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
}
.conv-filters { display: flex; border-bottom: 1px solid var(--border); }
.conv-filters a {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.conv-filters a:hover { text-decoration: none; background: #f5f6f8; }
.conv-filters a.is-active { color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); }
.conv-items { overflow-y: auto; flex: 1; }

.conv-item {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: #f7f8fa; text-decoration: none; }
.conv-item.is-active { background: #eef3ff; }
.conv-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #d8dee5;
  flex-shrink: 0;
  object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff;
}
.conv-meta { min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: 6px; }
.conv-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.conv-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-tags { margin-top: 3px; }
.conv-unread {
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
}
.conv-assignee { font-size: 11px; color: var(--muted); }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); }

/* --- Thread --- */
.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.thread-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.thread-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.thread-header .conv-avatar { width: 36px; height: 36px; }
.thread-title { font-weight: 700; }
.thread-sub { font-size: 12px; color: var(--muted); }
.thread-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.thread-actions select { width: auto; margin-top: 0; padding: 6px 8px; }

.window-banner {
  padding: 7px 16px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.window-ok { background: #e8f6ee; color: var(--ok); }
.window-closed { background: #fdeaea; color: var(--danger); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 64%; }
.msg-in { align-self: flex-start; }
.msg-out { align-self: flex-end; }
.msg-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-in .msg-bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-out .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-failed .msg-bubble { background: #fdeaea; color: var(--danger); border: 1px solid #e8b4b4; }
.msg-att img { max-width: 240px; border-radius: 10px; display: block; }
.msg-info { font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg-out .msg-info { text-align: right; }

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 14px;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { margin-top: 0; height: 42px; max-height: 140px; }
.composer .btn-primary { flex-shrink: 0; }
.composer-note { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* --- Side panel --- */
.side-panel {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  padding: 16px;
}
.side-panel h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }
.side-panel h3:first-child { margin-top: 0; }
.side-contact { text-align: center; }
.side-contact .conv-avatar { width: 64px; height: 64px; margin: 0 auto 8px; font-size: 22px; }
.side-contact .side-name { font-weight: 700; font-size: 15px; }
.side-contact .side-username { color: var(--muted); }
.side-field { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.side-field span { color: var(--muted); }

.tag {
  display: inline-block;
  background: #eef1f5;
  color: var(--muted);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  margin: 0 4px 4px 0;
}
.tag a { color: var(--muted); margin-left: 4px; }

.note {
  background: #fdf8e7;
  border: 1px solid #efe4b8;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.note-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }

.inline-form { display: flex; gap: 6px; margin-top: 6px; }
.inline-form input { margin-top: 0; }

/* --- Sub-navigation (settings, tasks scopes) --- */
.subnav {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.subnav a {
  padding: 8px 14px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subnav a:hover { text-decoration: none; }
.subnav a.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- Status pills --- */
.status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.badge-conv {
  background: #e8f6ee; color: var(--ok);
  padding: 1px 7px; border-radius: 20px;
  font-size: 10px; font-weight: 700;
}

/* --- Statuses management page --- */
.status-card { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 14px 18px; }
.status-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1; }
.status-form input[type=text]   { width: 180px; margin-top: 0; }
.status-form input[type=color]  { width: 40px; height: 32px; padding: 0; margin-top: 0; cursor: pointer; }
.status-form input[type=number] { margin-top: 0; }
.cb { font-weight: 400; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; margin-bottom: 0; }
.cb input { margin-top: 0; width: auto; }

/* --- Stack form (label-on-top vertical pattern) --- */
.stack-form > label { display: block; margin-bottom: 10px; }
.stack-form > input,
.stack-form > select,
.stack-form > textarea { margin-bottom: 10px; }

/* --- Composer saved-reply select --- */
.composer-tools { padding: 0 0 6px; }
.composer-tools select {
  width: auto; max-width: 240px; margin-top: 0;
  padding: 4px 8px; font-size: 12px;
}

/* --- Side-panel tasks --- */
.task-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.task-item input { margin-top: 0; width: auto; }
.task-item:hover { background: #f7f8fa; }
.task-item .task-title { flex: 1; }
.task-item .task-due { font-size: 11px; color: var(--muted); }
.task-item.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-item.is-overdue .task-due { color: var(--danger); font-weight: 700; }

/* --- Tasks page rows --- */
.task-list { background: #fff; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; }
.task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.task-row:last-child { border-bottom: none; }
.task-row.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-row.is-overdue { background: #fef5f5; }
.task-check {
  width: 22px; height: 22px;
  border: 2px solid #c4cad1; border-radius: 5px;
  background: #fff; cursor: pointer;
  color: var(--ok); font-size: 14px; line-height: 1;
}
.task-row.is-done .task-check { background: var(--ok); color: #fff; border-color: var(--ok); }
.task-main { flex: 1; }
.task-main .task-title { font-weight: 600; }
.task-main .task-meta  { font-size: 12px; color: var(--muted); }

/* --- KPI cards (reports) --- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.kpi {
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 14px;
}
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 700; letter-spacing: .03em; }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; }

/* --- Kanban pipeline board --- */
body.pipeline { height: 100vh; overflow: hidden; }
.pipeline-main {
  height: calc(100vh - 52px);
  overflow: auto;
  padding: 16px;
  background: var(--bg);
}
.pipeline-board { display: flex; gap: 12px; height: 100%; align-items: stretch; }
.pipeline-col {
  flex: 0 0 280px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex; flex-direction: column;
  max-height: 100%;
}
.pipeline-col-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
  border-radius: 10px 10px 0 0;
}
.pipeline-col-title { font-weight: 700; font-size: 14px; flex: 1; display: flex; align-items: center; gap: 6px; }
.pipeline-col-meta  { font-size: 12px; color: var(--muted); }
.pipeline-col-body  {
  padding: 8px; overflow-y: auto; flex: 1; min-height: 60px;
  transition: background .15s;
}
.pipeline-col-body.drop-over { background: #eef3ff; }
.pipeline-empty { text-align: center; color: var(--muted); padding: 14px 8px; font-size: 12px; }

.pipeline-card {
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 7px;
  color: var(--text);
  cursor: grab;
  box-shadow: 0 1px 1px rgba(0,0,0,0.02);
}
.pipeline-card:hover { text-decoration: none; border-color: #b9c4d0; }
.pipeline-card.dragging { opacity: 0.45; }
.pipeline-card-name { font-weight: 700; font-size: 13px; }
.pipeline-card-user { font-size: 11px; color: var(--muted); }
.pipeline-card-preview {
  font-size: 12px; color: var(--muted); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pipeline-card-foot {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); margin-top: 5px;
}
.pipeline-card-value { font-weight: 700; color: var(--ok); }
