:root{
  --bg:#f4f7fb;
  --panel:#ffffff;
  --panel-2:#f8fbff;
  --text:#0f172a;
  --muted:#64748b;
  --line:#e2e8f0;
  --line-soft:#eef2f7;
  --primary:#0f766e;
  --primary-2:#14b8a6;
  --primary-3:#ccfbf1;
  --accent:#2563eb;
  --danger:#dc2626;
  --warning:#d97706;
  --success:#16a34a;
  --shadow:0 10px 30px rgba(15,23,42,.08);
  --shadow-soft:0 6px 18px rgba(15,23,42,.05);
  --radius:18px;
  --radius-sm:12px;
  --sidebar-w:270px;
  --topbar-h:76px;
  --max-content:1600px;
}

*{
  box-sizing:border-box;
}

html{
  scroll-behavior:smooth;
}

body{
  margin:0;
  font-family:Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size:15px;
  line-height:1.5;
  color:var(--text);
  background:
    radial-gradient(circle at top left, rgba(20,184,166,.08), transparent 26%),
    radial-gradient(circle at top right, rgba(37,99,235,.06), transparent 22%),
    var(--bg);
}

img{
  max-width:100%;
  height:auto;
  display:block;
}

a{
  color:var(--accent);
  text-decoration:none;
  transition:.2s ease;
}

a:hover{
  opacity:.86;
}

button,
input,
select,
textarea{
  font:inherit;
}

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

.sidebar{
  position:fixed;
  inset:0 auto 0 0;
  width:var(--sidebar-w);
  background:linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color:#fff;
  border-right:1px solid rgba(255,255,255,.06);
  padding:22px 18px;
  overflow-y:auto;
  z-index:100;
}

.sidebar-brand{
  display:flex;
  align-items:center;
  gap:12px;
  padding:8px 10px 20px;
  margin-bottom:10px;
}

.sidebar-brand-logo{
  width:42px;
  height:42px;
  border-radius:14px;
  background:linear-gradient(135deg, var(--primary-2), var(--accent));
  display:flex;
  align-items:center;
  justify-content:center;
  color:#fff;
  font-weight:800;
  box-shadow:0 10px 25px rgba(20,184,166,.28);
}

.sidebar-brand-text{
  min-width:0;
}

.sidebar-brand-text strong{
  display:block;
  font-size:18px;
  line-height:1.1;
  letter-spacing:-.02em;
}

.sidebar-brand-text span{
  display:block;
  font-size:12px;
  color:rgba(255,255,255,.65);
  margin-top:3px;
}

.sidebar-section-label{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.12em;
  color:rgba(255,255,255,.42);
  padding:14px 12px 8px;
}

.sidebar-nav{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.sidebar-nav a{
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  border-radius:14px;
  color:rgba(255,255,255,.82);
  font-weight:600;
  font-size:14px;
}

.sidebar-nav a:hover{
  background:rgba(255,255,255,.07);
  color:#fff;
  opacity:1;
}

.sidebar-nav a.active{
  background:linear-gradient(135deg, rgba(20,184,166,.22), rgba(37,99,235,.18));
  color:#fff;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.06);
}

.sidebar-logout{
  margin-top:18px;
  padding-top:18px;
  border-top:1px solid rgba(255,255,255,.08);
}

.main{
  margin-left:var(--sidebar-w);
  min-height:100vh;
}

.topbar{
  position:sticky;
  top:0;
  z-index:80;
  height:var(--topbar-h);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:16px 28px;
  background:rgba(244,247,251,.8);
  backdrop-filter:blur(10px);
  border-bottom:1px solid rgba(226,232,240,.85);
}

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

.topbar-search{
  position:relative;
  width:min(460px, 45vw);
}

.topbar-search input{
  width:100%;
  height:46px;
  border:1px solid var(--line);
  background:#fff;
  border-radius:14px;
  padding:0 16px;
  color:var(--text);
  outline:none;
  box-shadow:var(--shadow-soft);
}

.topbar-search input:focus{
  border-color:#99f6e4;
  box-shadow:0 0 0 4px rgba(20,184,166,.12);
}

.topbar-user{
  display:flex;
  align-items:center;
  gap:12px;
  background:#fff;
  border:1px solid var(--line-soft);
  border-radius:16px;
  padding:10px 14px;
  box-shadow:var(--shadow-soft);
}

.topbar-avatar{
  width:42px;
  height:42px;
  border-radius:50%;
  background:linear-gradient(135deg, var(--primary-2), var(--accent));
  color:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:800;
  font-size:14px;
}

.topbar-user-text{
  line-height:1.2;
}

.topbar-user-text strong{
  display:block;
  font-size:14px;
}

.topbar-user-text span{
  display:block;
  font-size:12px;
  color:var(--muted);
  margin-top:3px;
}

.content{
  width:100%;
  max-width:var(--max-content);
  padding:30px 28px 42px;
}

.page-header{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:20px;
  margin-bottom:24px;
}

.page-title{
  margin:0;
  font-size:34px;
  line-height:1.1;
  letter-spacing:-.03em;
  color:#0b1324;
}

.page-subtitle{
  margin:10px 0 0;
  color:var(--muted);
  font-size:15px;
  max-width:760px;
}

.page-actions{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  min-height:44px;
  padding:0 16px;
  border-radius:13px;
  border:1px solid transparent;
  font-weight:700;
  cursor:pointer;
  transition:.2s ease;
  text-decoration:none;
}

.btn:hover{
  transform:translateY(-1px);
  opacity:1;
}

.btn-primary{
  background:linear-gradient(135deg, var(--primary), var(--primary-2));
  color:#fff;
  box-shadow:0 12px 28px rgba(15,118,110,.18);
}

.btn-secondary{
  background:#fff;
  border-color:var(--line);
  color:var(--text);
  box-shadow:var(--shadow-soft);
}

.btn-danger{
  background:#fff;
  border:1px solid #fecaca;
  color:#b91c1c;
  box-shadow:var(--shadow-soft);
}

.btn-danger:hover{
  background:#fef2f2;
}

.btn-success{
  background:#ecfdf3;
  border:1px solid #bbf7d0;
  color:#166534;
  box-shadow:var(--shadow-soft);
}

.btn-success:hover{
  background:#dcfce7;
}

.grid{
  display:grid;
  gap:20px;
}

.grid-metrics{
  grid-template-columns:repeat(4, minmax(0,1fr));
  margin-bottom:22px;
}

.card{
  background:var(--panel);
  border:1px solid rgba(226,232,240,.95);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}

.card-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  padding:22px 24px 0;
}

.card-title{
  margin:0;
  font-size:20px;
  line-height:1.2;
  letter-spacing:-.02em;
}

.card-subtitle{
  margin:8px 0 0;
  color:var(--muted);
  font-size:14px;
}

.card-body{
  padding:22px 24px 24px;
}

.metric-card{
  padding:22px;
  position:relative;
  overflow:hidden;
}

.metric-card::after{
  content:"";
  position:absolute;
  right:-20px;
  top:-20px;
  width:90px;
  height:90px;
  border-radius:50%;
  background:rgba(20,184,166,.08);
}

.metric-label{
  position:relative;
  z-index:1;
  color:var(--muted);
  font-weight:600;
  font-size:14px;
}

.metric-value{
  position:relative;
  z-index:1;
  margin-top:8px;
  font-size:34px;
  line-height:1;
  letter-spacing:-.04em;
  font-weight:800;
  color:#0b1324;
}

.metric-meta{
  position:relative;
  z-index:1;
  margin-top:10px;
  font-size:13px;
  color:var(--success);
  font-weight:700;
}

.two-col{
  display:grid;
  grid-template-columns:minmax(0,1.4fr) minmax(320px,.8fr);
  gap:20px;
}

.table-wrap{
  width:100%;
  overflow:auto;
}

.table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
}

.table thead th{
  text-align:left;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--muted);
  padding:0 16px 14px;
  border-bottom:1px solid var(--line);
}

.table tbody td{
  padding:16px;
  border-bottom:1px solid var(--line-soft);
  vertical-align:middle;
}

.table tbody tr:last-child td{
  border-bottom:none;
}

.table tbody tr:hover{
  background:#fafcff;
}

.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:28px;
  padding:4px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:800;
  letter-spacing:.01em;
}

.badge-success{
  background:#ecfdf3;
  color:#15803d;
}

.badge-warning{
  background:#fff7ed;
  color:#c2410c;
}

.badge-info{
  background:#eff6ff;
  color:#1d4ed8;
}

.badge-neutral{
  background:#f1f5f9;
  color:#475569;
}

.list-clean{
  display:flex;
  flex-direction:column;
  gap:14px;
}

.list-item{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:14px;
  padding:14px 0;
  border-bottom:1px solid var(--line-soft);
}

.list-item:last-child{
  border-bottom:none;
  padding-bottom:0;
}

.list-item:first-child{
  padding-top:0;
}

.list-item-title{
  margin:0;
  font-size:15px;
  font-weight:700;
}

.list-item-meta{
  margin-top:4px;
  color:var(--muted);
  font-size:13px;
}

.status-list{
  margin:0;
  padding-left:18px;
}

.status-list li{
  margin:8px 0;
  color:var(--text);
}

.status-list strong{
  margin-left:6px;
}

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
select,
textarea{
  width:100%;
  border:1px solid var(--line);
  background:#fff;
  border-radius:14px;
  padding:12px 14px;
  color:var(--text);
  outline:none;
  box-shadow:none;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus{
  border-color:#99f6e4;
  box-shadow:0 0 0 4px rgba(20,184,166,.12);
}

textarea{
  min-height:120px;
  resize:vertical;
}

.form-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0,1fr));
  gap:16px;
}

.form-grid .full{
  grid-column:1 / -1;
}

.section-stack{
  display:flex;
  flex-direction:column;
  gap:20px;
}

.empty-state{
  padding:34px 24px;
  text-align:center;
  color:var(--muted);
}

.auth-shell{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:32px;
  background:
    radial-gradient(circle at top left, rgba(20,184,166,.14), transparent 25%),
    radial-gradient(circle at bottom right, rgba(37,99,235,.12), transparent 25%),
    #f8fbff;
}

.auth-card{
  width:100%;
  max-width:460px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:26px;
  box-shadow:0 30px 70px rgba(15,23,42,.12);
  padding:30px;
}

.auth-title{
  margin:0;
  font-size:30px;
  line-height:1.1;
  letter-spacing:-.03em;
}

.auth-subtitle{
  margin:10px 0 24px;
  color:var(--muted);
}

.flash{
  padding:14px 16px;
  border-radius:14px;
  margin-bottom:16px;
  font-size:14px;
  font-weight:600;
}

.flash-error{
  background:#fef2f2;
  color:#b91c1c;
  border:1px solid #fecaca;
}

.flash-success{
  background:#ecfdf3;
  color:#166534;
  border:1px solid #bbf7d0;
}

.module-placeholder{
  padding:34px 24px;
}

.module-placeholder h2{
  margin:0 0 8px;
  font-size:24px;
  letter-spacing:-.02em;
}

.module-placeholder p{
  margin:0;
  color:var(--muted);
}

.kpi-row{
  display:grid;
  grid-template-columns:repeat(3, minmax(0,1fr));
  gap:16px;
}

.kpi-box{
  background:var(--panel-2);
  border:1px solid var(--line-soft);
  border-radius:16px;
  padding:16px;
}

.kpi-box strong{
  display:block;
  font-size:24px;
  letter-spacing:-.03em;
  margin-top:8px;
}

.muted{
  color:var(--muted);
}

/* ==========================================================================
   PIPELINE BOARD
   ========================================================================== */

.pipeline-board{
  display:flex;
  gap:20px;
  align-items:flex-start;
  overflow-x:auto;
  padding-bottom:10px;
  scrollbar-width:thin;
  scrollbar-color:#cbd5e1 transparent;
}

.pipeline-board::-webkit-scrollbar{
  height:8px;
}

.pipeline-board::-webkit-scrollbar-thumb{
  background:#cbd5e1;
  border-radius:20px;
}

.pipeline-board::-webkit-scrollbar-track{
  background:transparent;
}

.pipeline-column{
  flex:0 0 320px;
  background:linear-gradient(180deg,#f8fbff 0%, #f3f7fb 100%);
  border:1px solid var(--line);
  border-radius:20px;
  min-height:420px;
  box-shadow:var(--shadow-soft);
  display:flex;
  flex-direction:column;
}

.pipeline-column-head{
  padding:18px 18px 14px;
  border-bottom:1px solid var(--line-soft);
  background:rgba(255,255,255,.7);
  backdrop-filter:blur(8px);
}

.pipeline-column-title{
  margin:0;
  font-size:18px;
  line-height:1.2;
  letter-spacing:-.02em;
  color:#0f172a;
}

.pipeline-column-meta{
  margin-top:6px;
  font-size:13px;
  color:var(--muted);
}

.pipeline-dropzone{
  flex:1;
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:14px;
  min-height:340px;
  transition:background .18s ease, border-color .18s ease;
}

.pipeline-dropzone.drag-over{
  background:rgba(20,184,166,.06);
}

.pipeline-card{
  background:#fff;
  border:1px solid var(--line-soft);
  border-radius:16px;
  padding:14px;
  box-shadow:var(--shadow-soft);
  cursor:grab;
  transition:transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.pipeline-card:hover{
  transform:translateY(-2px);
  box-shadow:0 12px 28px rgba(15,23,42,.08);
  border-color:#cbd5e1;
}

.pipeline-card.dragging{
  opacity:.55;
  transform:rotate(1deg);
}

.pipeline-card-name{
  font-weight:800;
  font-size:15px;
  color:#0f172a;
}

.pipeline-card-name a{
  color:inherit;
  text-decoration:none;
}

.pipeline-card-job{
  margin-top:6px;
  color:var(--muted);
  font-size:13px;
}

.pipeline-card-contact{
  margin-top:10px;
  display:grid;
  gap:4px;
  font-size:13px;
  color:#334155;
}

.pipeline-card-footer{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-top:12px;
}

.pipeline-empty{
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:90px;
  padding:16px;
  border:1px dashed #cbd5e1;
  border-radius:16px;
  color:var(--muted);
  font-size:13px;
  background:rgba(255,255,255,.5);
}

.modal-open{
  overflow:hidden;
}

.modal-overlay{
  position:fixed;
  inset:0;
  background:rgba(15,23,42,.5);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:20px;
  z-index:9999;
}

.modal-overlay[hidden]{
  display:none !important;
}

.modal-card{
  width:min(720px, 96vw);
  max-height:90vh;
  overflow:auto;
  background:#fff;
  border-radius:24px;
  box-shadow:0 40px 90px rgba(15,23,42,.22);
  border:1px solid rgba(255,255,255,.6);
}

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:20px 22px;
  border-bottom:1px solid var(--line-soft);
}

.modal-title{
  margin:0;
  font-size:22px;
  letter-spacing:-.02em;
}

.modal-close{
  width:40px;
  height:40px;
  border:none;
  border-radius:50%;
  background:#f8fafc;
  color:#475569;
  cursor:pointer;
  font-size:22px;
}

.modal-body{
  padding:22px;
}

.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:12px;
  padding-top:18px;
}

@media (max-width: 1180px){
  .grid-metrics{
    grid-template-columns:repeat(2, minmax(0,1fr));
  }

  .two-col{
    grid-template-columns:1fr;
  }

  .kpi-row{
    grid-template-columns:repeat(2, minmax(0,1fr));
  }
}

@media (max-width: 980px){
  .sidebar{
    position:static;
    width:100%;
    height:auto;
  }

  .main{
    margin-left:0;
  }

  .topbar{
    position:static;
    height:auto;
    flex-direction:column;
    align-items:stretch;
  }

  .topbar-left,
  .topbar-right{
    width:100%;
    justify-content:space-between;
  }

  .topbar-search{
    width:100%;
  }

  .content{
    padding:22px 18px 34px;
  }
}

@media (max-width: 720px){
  .page-header{
    flex-direction:column;
  }

  .grid-metrics,
  .kpi-row,
  .form-grid{
    grid-template-columns:1fr;
  }

  .sidebar-brand{
    padding-left:4px;
    padding-right:4px;
  }

  .card-header,
  .card-body{
    padding-left:18px;
    padding-right:18px;
  }

  .table thead{
    display:none;
  }

  .table,
  .table tbody,
  .table tr,
  .table td{
    display:block;
    width:100%;
  }

  .table tbody tr{
    padding:12px 0;
    border-bottom:1px solid var(--line-soft);
  }

  .table tbody td{
    border:none;
    padding:8px 0;
  }

  .modal-card{
    border-radius:20px;
  }

  .modal-head,
  .modal-body{
    padding-left:18px;
    padding-right:18px;
  }
}

/* ========================================================================== */
/* EMAIL HISTORY / PREVIEW                                                    */
/* ========================================================================== */

.table-mails tbody tr.mail-row-clickable{
  cursor:pointer;
  transition:background .18s ease;
}

.table-mails tbody tr.mail-row-clickable:hover{
  background:rgba(15,23,42,.03);
}

.modal-card-large{
  width:min(920px, 96vw);
}

.mail-preview-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0,1fr));
  gap:12px 18px;
  margin-bottom:18px;
}

.mail-preview-section{
  margin-top:18px;
}

.mail-preview-section h3{
  margin:0 0 10px;
  font-size:15px;
  font-weight:700;
}

.mail-preview-body{
  background:#f8fafc;
  border:1px solid rgba(15,23,42,.08);
  border-radius:14px;
  padding:16px;
  white-space:normal;
  line-height:1.6;
  min-height:120px;
}

.mail-attachments-list{
  display:grid;
  gap:10px;
}

.mail-attachment-item{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:center;
  padding:12px 14px;
  border:1px solid rgba(15,23,42,.08);
  border-radius:14px;
  background:#fff;
}

.mail-attachment-name{
  font-weight:600;
  word-break:break-word;
}

.mail-attachment-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.mail-history-stack{
  display:flex;
  flex-direction:column;
  gap:14px;
}

.mail-history-item{
  padding:16px;
  border:1px solid var(--line-soft);
  border-radius:16px;
  background:#fff;
  box-shadow:var(--shadow-soft);
  cursor:pointer;
  transition:transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease;
}

.mail-history-item:hover{
  transform:translateY(-1px);
  box-shadow:0 12px 28px rgba(15,23,42,.08);
  border-color:#cbd5e1;
  background:#fcfdff;
}

.mail-history-top{
  display:flex;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
  margin-bottom:10px;
}

@media (max-width: 768px){
  .mail-preview-grid{
    grid-template-columns:1fr;
  }

  .mail-attachment-item{
    flex-direction:column;
    align-items:flex-start;
  }
}

.mail-preview-embed-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:10px;
  flex-wrap:wrap;
}

.mail-preview-embed{
  width:100%;
  height:240px;
  border:1px solid rgba(15,23,42,.08);
  border-radius:16px;
  background:#fff;
}

@media (max-width: 768px){
  .mail-preview-embed{
    height:180px;
  }
}


.mail-row-clickable:focus-visible{
  outline:3px solid rgba(37,99,235,.28);
  outline-offset:-3px;
}

.mail-preview-body{
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  max-height:260px;
  overflow:auto;
}

.mail-preview-embed-wrap{
  background:#f8fafc;
  border:1px solid rgba(15,23,42,.08);
  border-radius:18px;
  padding:16px;
}

.mail-preview-embed{
  display:block;
  width:100%;
  height:clamp(260px, 42vh, 420px);
  border:1px solid rgba(15,23,42,.08);
  border-radius:16px;
  background:#e2e8f0;
}

@media (max-width: 768px){
  .mail-preview-body{
    max-height:none;
  }

  .mail-preview-embed-wrap{
    padding:12px;
  }

  .mail-preview-embed{
    height:300px;
  }
}
