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

:root {
  --navy: #1c2b3a;
  --navy-light: #2c4157;
  --bg: #f4f6f8;
  --card: #ffffff;
  --accent: #0f8b8d;
  --accent-dark: #0a6b6d;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #d64545;
  --warning: #d99a2b;
  --success: #2e9e5b;
  --radius: 8px;
  --font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

input, select, textarea {
  font-family: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- صفحه ورود ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
}

.login-box {
  background: var(--card);
  padding: 40px;
  border-radius: 12px;
  width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-box h1 {
  margin: 0 0 24px;
  font-size: 22px;
  text-align: center;
  color: var(--navy);
}

.login-box label {
  display: block;
  font-size: 13px;
  margin: 14px 0 6px;
  color: var(--text-muted);
}

.login-box button {
  width: 100%;
  margin-top: 20px;
  padding: 11px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
}
.login-box button:hover { background: var(--accent-dark); }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}

/* ---------- اسکلت اصلی برنامه ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  background: var(--navy);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header h2 { margin: 0; font-size: 17px; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-btn {
  background: none;
  color: rgba(255,255,255,0.75);
  text-align: right;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 0;
  transition: background 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-btn.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 13px;
}
#current-user-name { color: rgba(255,255,255,0.6); margin-bottom: 10px; }
.sidebar-footer button {
  width: 100%;
  padding: 8px;
  background: rgba(255,255,255,0.1);
  color: white;
}
.sidebar-footer button:hover { background: rgba(255,255,255,0.2); }

.main-content {
  flex: 1;
  padding: 28px 32px;
  overflow-x: auto;
  min-width: 0;
}

/* ---------- عناصر مشترک صفحات ---------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { margin: 0; font-size: 22px; }

.btn-primary {
  background: var(--accent);
  color: white;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: var(--border);
  color: var(--text);
  padding: 9px 16px;
  font-size: 14px;
}
.btn-secondary:hover { background: #d3dae2; }

.btn-danger { background: var(--danger); color: white; padding: 7px 14px; font-size: 13px; }
.btn-small { padding: 6px 12px; font-size: 13px; }

.search-box {
  max-width: 280px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
th, td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th { background: #eef1f4; color: var(--text-muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
.clickable-row { cursor: pointer; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-gray { background: #e2e8f0; color: var(--text-muted); }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: var(--success); }
.badge-red { background: #fee2e2; color: var(--danger); }
.badge-yellow { background: #fef3c7; color: var(--warning); }

/* ---------- کارت‌های داشبورد ---------- */
.dash-hero {
  margin-bottom: 22px;
}
.dash-greeting { font-size: 14px; color: var(--text-muted); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  padding: 18px 20px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border-right: 4px solid var(--accent);
}
.stat-card.modern {
  border-right: 4px solid var(--accent, var(--accent));
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.15s;
}
.stat-card.modern:hover { transform: translateY(-2px); }
.stat-card.clickable { cursor: pointer; user-select: none; }
.stat-card.clickable:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.12); }
.stat-card.clickable:active { transform: translateY(0); }
.stat-card .chevron { margin-right: auto; opacity: 0.35; font-size: 13px; align-self: center; }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 15%, white);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-card .label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .value { font-size: 22px; font-weight: 700; color: var(--navy); }

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.chart-card {
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chart-card h3 { margin: 0 0 16px; font-size: 15px; }

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
}

/* ---------- پایپ‌لاین فروش (کانبان) ---------- */
.pipeline-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 10px;
}
.pipeline-column {
  background: #eaeef1;
  border-radius: var(--radius);
  min-width: 230px;
  max-width: 230px;
  flex-shrink: 0;
  padding: 10px;
}
.pipeline-column-header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 6px 10px;
}
.pipeline-column.drag-over { background: #d7e8e8; }

.deal-card {
  background: var(--card);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: grab;
  font-size: 13px;
}
.deal-card:active { cursor: grabbing; }
.deal-card .deal-title { font-weight: 600; margin-bottom: 4px; }
.deal-card .deal-customer { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }
.deal-card .deal-value { color: var(--accent-dark); font-weight: 600; }

/* ---------- مودال ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-box {
  background: var(--card);
  border-radius: 10px;
  padding: 26px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-box h2 { margin: 0 0 18px; font-size: 18px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

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

.comment-item {
  background: #f4f6f8;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 13px;
}
.comment-item .comment-meta { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }

@media (max-width: 700px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .main-content { padding: 18px; }
  .two-col { grid-template-columns: 1fr; }
}


/* ---------- نامه‌ها و ویرایشگر ---------- */
.editor-toolbar {
  display:flex;
  gap:5px;
  flex-wrap:wrap;
  padding:7px;
  background:#eef1f4;
  border:1px solid var(--border);
  border-bottom:none;
  border-radius:var(--radius) var(--radius) 0 0;
}
.editor-toolbar button {
  background:white;
  border:1px solid var(--border);
  padding:5px 9px;
  font-size:12px;
  color:var(--text);
}
.rich-editor {
  min-height:260px;
  padding:16px;
  border:1px solid var(--border);
  border-radius:0 0 var(--radius) var(--radius);
  background:#fff;
  line-height:2;
  outline:none;
}
.rich-editor:focus { outline:2px solid var(--accent); outline-offset:1px; }
.letterhead-choice {
  display:flex;
  align-items:center;
  gap:7px;
  font-size:14px;
  cursor:pointer;
}
.letterhead-choice input { width:auto; }
.letter-body-preview { line-height:2.2; min-height:180px; }
.letter-body-preview p { margin:0 0 12px; }
.letter-preview { max-width:760px; }
