:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e2e8e4;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-soft: #ecfdf5;
  --accent: #0f766e;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --sidebar-bg: #064e3b;
  --sidebar-text: #ecfdf5;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

body.dark {
  --bg: #0b1310;
  --surface: #111c18;
  --surface-2: #16241f;
  --border: #22352e;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-soft: rgba(16, 185, 129, 0.14);
  --danger-soft: rgba(220, 38, 38, 0.16);
  --warning-soft: rgba(217, 119, 6, 0.16);
  --info-soft: rgba(37, 99, 235, 0.16);
  --sidebar-bg: #071913;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, #065f46, #022c22 70%);
}
.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border-radius: 22px;
  padding: 34px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.35);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-icon {
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--primary-soft); display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.login-brand h1 { margin: 0; font-size: 22px; color: var(--primary); }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.login-footer {
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted);
}
.login-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

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

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}
.sidebar-header {
  padding: 20px 18px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-badge {
  width: 40px; height: 40px; border-radius: 12px;
  background: rgba(16,185,129,0.2); display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.brand-title { font-weight: 800; font-size: 17px; }
.brand-sub { font-size: 11px; opacity: 0.75; }

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  width: 100%; border: none; background: transparent; color: rgba(236,253,245,0.82);
  padding: 11px 14px; border-radius: 11px; display: flex; align-items: center; gap: 11px;
  cursor: pointer; font-family: inherit; font-size: 13.5px; font-weight: 500; text-align: right;
  transition: all 0.15s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.09); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 700; box-shadow: 0 4px 12px rgba(5,150,105,0.35); }
.nav-icon { font-size: 17px; }

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-card { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff;
}
.user-name { font-size: 13px; font-weight: 700; }
.user-role { font-size: 11px; opacity: 0.75; }

.main-area { flex: 1; margin-right: 260px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-right, .topbar-left { display: flex; align-items: center; gap: 10px; }
.page-title { margin: 0; font-size: 18px; font-weight: 800; }
.page-date { font-size: 12px; color: var(--text-muted); }

.view-container { padding: 22px 24px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 10px; border: 1px solid transparent;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: rgba(255,255,255,0.1); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,0.18); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.icon-btn:hover { border-color: var(--primary); }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-family: inherit; font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
.kpi-top { display: flex; justify-content: space-between; align-items: center; }
.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.kpi-icon { width: 38px; height: 38px; border-radius: 11px; background: var(--primary-soft); display: flex; align-items: center; justify-content: center; font-size: 19px; }
.kpi-value { font-size: 24px; font-weight: 800; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--text-muted); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px;
}
.card-header {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.card-title { margin: 0; font-size: 15px; font-weight: 700; }
.card-body { padding: 16px 18px; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.toolbar-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; }
.toolbar-filters input { max-width: 280px; }
.toolbar-filters select { max-width: 170px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: var(--surface-2); font-weight: 700; color: var(--text-muted); white-space: nowrap; }
tr:hover td { background: var(--surface-2); }
.actions-cell { display: flex; gap: 6px; white-space: nowrap; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.badge-green { background: var(--primary-soft); color: var(--primary); }
.badge-blue { background: var(--info-soft); color: var(--info); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-gray { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* Kanban */
.kanban-board {
  display: grid; grid-template-columns: repeat(6, minmax(240px, 1fr));
  gap: 14px; overflow-x: auto; padding-bottom: 10px;
}
.kanban-col {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 360px;
}
.kanban-col-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.kanban-col-title { font-weight: 800; font-size: 13px; }
.kanban-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); display: flex; flex-direction: column; gap: 6px;
}
.kanban-card-title { font-weight: 700; font-size: 13.5px; }
.kanban-meta { font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; }
.kanban-actions { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.kanban-actions select { padding: 4px 6px; font-size: 11.5px; border-radius: 7px; }

/* Progress bars */
.bar-row { margin-bottom: 12px; }
.bar-head { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.bar-track { height: 9px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #34d399); border-radius: 999px; }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
  padding: 10px 12px; border-radius: 10px; background: var(--surface-2);
  border-right: 3px solid var(--primary);
}
.timeline-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.timeline-title { font-weight: 700; font-size: 13px; }

/* Modal & Drawer */
.modal-overlay, .drawer-overlay {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.55); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  width: 100%; max-width: 640px; max-height: 90vh; background: var(--surface);
  border-radius: 18px; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 25px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }

.drawer-overlay { justify-content: flex-start; padding: 0; }
.drawer-panel {
  width: 100%; max-width: 560px; height: 100vh; background: var(--surface);
  display: flex; flex-direction: column; box-shadow: 10px 0 40px rgba(0,0,0,0.25);
}
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }

/* Toast & Alerts */
.alert-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 12.5px; margin-bottom: 12px; }
.toast-container { position: fixed; bottom: 20px; left: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #064e3b; color: #fff; padding: 11px 16px; border-radius: 11px;
  font-size: 13px; font-weight: 600; box-shadow: 0 10px 25px rgba(0,0,0,0.25);
}
.toast.error { background: var(--danger); }

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

/* Print Invoice */
.invoice-box { border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.invoice-head { display: flex; justify-content: space-between; border-bottom: 2px solid var(--primary); padding-bottom: 12px; margin-bottom: 16px; }
@media print {
  body * { visibility: hidden; }
  #printableInvoice, #printableInvoice * { visibility: visible; }
  #printableInvoice { position: fixed; inset: 0; padding: 24px; background: #fff; color: #000; }
}

.mobile-only { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 960px) {
  .mobile-only { display: inline-flex; }
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 35; }
  .main-area { margin-right: 0; }
  .dash-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
