/* ============ Tokens ============ */
:root{
  --navy-950: #0F1A24;
  --navy-900: #142633;
  --navy-800: #1B3243;
  --navy-700: #24425A;
  --accent: #E8873A;
  --accent-dark: #C96F27;
  --accent-soft: #FBE6D2;
  --success: #2F9E6E;
  --success-soft: #DDF3E9;
  --danger: #D6524A;
  --danger-soft: #FBE3E1;
  --warn: #D9A32C;
  --warn-soft: #FBF0D6;
  --info: #3E7CB1;
  --info-soft: #DEEBF6;

  --bg: #F3F5F7;
  --card: #FFFFFF;
  --border: #E3E7EB;
  --text: #1C2731;
  --text-muted: #6B7A87;
  --text-faint: #98A5B0;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(15,26,36,.04), 0 8px 24px -12px rgba(15,26,36,.12);
  --shadow-pop: 0 20px 60px -20px rgba(15,26,36,.35);

  --font-ui: 'Vazirmatn', 'Tahoma', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px;
  line-height: 1.6;
}
h1,h2,h3{ font-family: var(--font-ui); margin:0; letter-spacing:-.01em; }
input,select,textarea,button{ font-family: var(--font-ui); font-size: 14px; }
.muted{ color: var(--text-muted); margin:2px 0 0; font-size:13px; }
.hint{ color: var(--text-faint); font-size: 12.5px; margin-top:-6px; }
::selection{ background: var(--accent-soft); }

/* ============ Auth gate ============ */
body .app-shell{ display:none; }
body.is-authed .app-shell{ display:flex; }
body.is-authed .auth-gate{ display:none; }

.auth-gate{
  position:fixed; inset:0; z-index:400;
  display:flex; align-items:center; justify-content:center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 15%, rgba(232,135,58,.16), transparent 45%),
    linear-gradient(160deg, var(--navy-950), var(--navy-900) 65%);
}
.auth-card{
  width:100%; max-width:380px;
  background:#fff; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 30px 28px 26px;
  text-align:center;
}
.auth-mark{
  width:48px; height:48px; border-radius:14px; margin:0 auto 14px;
  background: var(--accent-soft); color: var(--accent-dark);
  display:flex; align-items:center; justify-content:center;
}
.auth-card h1{ font-size:19px; font-weight:800; margin-bottom:4px; }
.auth-card .muted{ font-size:12.8px; margin-bottom:20px; }
.auth-card form{ display:flex; flex-direction:column; gap:12px; text-align:right; }
.auth-error{
  background: var(--danger-soft); color: var(--danger);
  font-size:12.5px; font-weight:600; padding:8px 10px; border-radius: var(--radius-sm);
}
.auth-back{
  display:inline-block; margin-top:16px; font-size:12.5px;
  color: var(--text-muted); text-decoration:none;
}
.auth-back:hover{ color: var(--accent-dark); }

/* ============ Shell / layout ============ */
.app-shell{
  display:flex;
  min-height:100vh;
}
.sidebar{
  width: 250px;
  flex-shrink:0;
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900) 70%);
  color: #E8EDF1;
  display:flex;
  flex-direction:column;
  padding: 20px 16px;
  position: sticky;
  top:0;
  height:100vh;
}
.brand{ display:flex; align-items:center; gap:10px; padding: 4px 6px 22px; }
.brand-mark{
  width:38px; height:38px; border-radius:11px;
  background: rgba(232,135,58,.16);
  color: var(--accent);
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
}
.brand-text{ display:flex; flex-direction:column; line-height:1.3; }
.brand-text strong{ font-size:16px; font-weight:800; }
.brand-text span{ font-size:11.5px; color:#8FA0AE; }

.nav{ display:flex; flex-direction:column; gap:3px; flex:1; overflow-y:auto; }
.nav-item{
  display:flex; align-items:center; gap:11px;
  padding:10px 12px;
  border-radius: var(--radius-sm);
  background:none; border:none; cursor:pointer;
  color:#B9C6D0; text-align:right;
  font-size:13.6px; font-weight:500;
  transition: background .15s, color .15s;
  position:relative;
}
.nav-item svg{ width:18px; height:18px; flex-shrink:0; opacity:.9; }
.nav-item:hover{ background: rgba(255,255,255,.06); color:#fff; }
.nav-item.is-active{ background: var(--accent); color:#1B1206; font-weight:700; }
.nav-item.is-active svg{ opacity:1; }
.nav-badge{
  margin-right:auto;
  background: var(--danger);
  color:#fff; font-size:10.5px; font-weight:700;
  padding: 1px 7px; border-radius: 20px;
}
.nav-item.is-active .nav-badge{ background: rgba(0,0,0,.25); color:#1B1206; }

.sidebar-footer{ display:flex; flex-direction:column; gap:8px; padding-top:14px; border-top:1px solid rgba(255,255,255,.08); margin-top:10px; }

.mobile-nav-toggle{
  display:none; position:fixed; top:14px; left:14px; z-index:60;
  width:42px; height:42px; border-radius:12px; border:none;
  background: var(--navy-950); color:#fff; box-shadow: var(--shadow-pop);
}

.main{ flex:1; min-width:0; padding: 26px 32px 60px; }

.view{ display:none; animation: fade .2s ease; }
.view.is-active{ display:block; }
@keyframes fade{ from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;} }

.view-header{ display:flex; align-items:flex-end; justify-content:space-between; gap:16px; margin-bottom:20px; flex-wrap:wrap; }
.view-header h1{ font-size: 23px; font-weight:800; }
.header-actions{ display:flex; gap:8px; align-items:center; }

/* ============ Buttons / inputs ============ */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight:600; font-size:13.5px;
  border:1px solid transparent; cursor:pointer;
  transition: transform .1s, background .15s, border-color .15s;
  white-space:nowrap;
}
.btn:active{ transform: scale(.98); }
.btn-primary{ background: var(--accent); color:#211405; }
.btn-primary:hover{ background: var(--accent-dark); }
.btn-outline{ background:#fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover{ border-color: var(--accent); color: var(--accent-dark); }
.btn-ghost{ background: rgba(255,255,255,.05); color:#CBD6DE; border:1px solid rgba(255,255,255,.1); font-size:12.5px; padding:8px 12px; cursor:pointer; }
.btn-ghost:hover{ background: rgba(255,255,255,.1); color:#fff; }
.btn-block{ width:100%; text-align:center; display:flex; }
.btn-sm{ padding:5px 10px; font-size:12px; border-radius:7px; }
.btn-danger{ background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover{ background: var(--danger); color:#fff; }
.btn-success{ background: var(--success-soft); color: var(--success); }
.btn-success:hover{ background: var(--success); color:#fff; }

input[type=text], input[type=tel], input[type=number], input[type=search],
input[type=date], input[type=email], input[type=file], select, textarea{
  width:100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background:#fff;
  color: var(--text);
  outline:none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea{ resize: vertical; }

.field{ display:flex; flex-direction:column; gap:5px; font-size:12.8px; font-weight:600; color:var(--text-muted); }
.field input, .field select, .field textarea{ font-weight:500; color:var(--text); }

.form-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .span-2{ grid-column: span 2; }
.form-section-title{
  grid-column: span 2;
  font-size:12px; font-weight:800; text-transform:uppercase; letter-spacing:.04em;
  color: var(--accent-dark); border-bottom:1px dashed var(--border); padding-bottom:6px; margin-top:8px;
}
.form-section-title:first-child{ margin-top:0; }
.form-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top:6px; }

@media (max-width: 640px){
  .form-grid{ grid-template-columns: 1fr; }
  .form-grid .span-2{ grid-column: span 1; }
}

/* ============ Cards / panels ============ */
.panel{
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom:18px;
}
.panel-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.panel-head h2{ font-size:15px; font-weight:700; }
.panel-grid{ display:grid; grid-template-columns:1.3fr 1fr; gap:18px; }
@media (max-width: 900px){ .panel-grid{ grid-template-columns:1fr; } }

.stat-grid{ display:grid; grid-template-columns: repeat(4, 1fr); gap:14px; margin-bottom:20px; }
@media (max-width: 900px){ .stat-grid{ grid-template-columns: repeat(2,1fr); } }
.stat-card{
  background: var(--card); border:1px solid var(--border); border-radius: var(--radius-lg);
  padding:16px 18px; box-shadow: var(--shadow-card);
  display:flex; flex-direction:column; gap:6px;
}
.stat-card .k{ font-size:12.5px; color:var(--text-muted); font-weight:600; }
.stat-card .v{ font-size:24px; font-weight:800; font-family: var(--font-mono); }
.stat-card .d{ font-size:11.5px; color: var(--text-faint); }

/* ============ Table ============ */
.table-wrap{ overflow-x:auto; }
table{ width:100%; border-collapse: collapse; font-size:13.3px; }
thead th{
  text-align:right; color: var(--text-muted); font-weight:700; font-size:11.5px;
  text-transform:uppercase; letter-spacing:.03em;
  padding: 8px 10px; border-bottom: 1.5px solid var(--border); white-space:nowrap;
}
tbody td{ padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align:middle; }
tbody tr:last-child td{ border-bottom:none; }
tbody tr:hover{ background: #FAFBFC; }
.empty-row td{ text-align:center; color: var(--text-faint); padding: 30px; }

.cell-title{ font-weight:700; }
.cell-sub{ color: var(--text-muted); font-size:12px; }
.mono{ font-family: var(--font-mono); }

/* ============ Badges ============ */
.badge{
  display:inline-flex; align-items:center; gap:5px;
  padding: 3px 10px; border-radius: 20px; font-size:11.5px; font-weight:700;
}
.badge-new{ background: var(--info-soft); color: var(--info); }
.badge-assigned{ background: var(--warn-soft); color: var(--warn); }
.badge-in_progress{ background: var(--accent-soft); color: var(--accent-dark); }
.badge-completed{ background: var(--success-soft); color: var(--success); }
.badge-invoiced{ background:#E4E2FB; color:#5B4FCF; }
.badge-cancelled{ background: var(--danger-soft); color: var(--danger); }
.badge-pending{ background: var(--warn-soft); color:var(--warn); }
.badge-approved{ background: var(--success-soft); color: var(--success); }
.badge-rejected{ background: var(--danger-soft); color: var(--danger); }
.badge-urgent{ background: var(--danger-soft); color: var(--danger); }
.badge-normal{ background:#EEF1F4; color:var(--text-muted); }

/* ============ Map ============ */
.map-layout{ display:grid; grid-template-columns: 1.6fr 1fr; gap:18px; align-items:start; }
@media (max-width: 980px){ .map-layout{ grid-template-columns:1fr; } }
.map-panel{ padding:0; overflow:hidden; }
#leafletMap{ width:100%; height: 560px; }
.map-side{ position:sticky; top:20px; }
.legend{ display:flex; flex-wrap:wrap; gap:12px; font-size:12px; color:var(--text-muted); margin: 8px 0 4px; }
.legend span{ display:flex; align-items:center; gap:6px; }
.dot{ width:10px; height:10px; border-radius:50%; display:inline-block; }
.dot-customer{ background:#3E7CB1; }
.dot-tech{ background: var(--success); }
.dot-tech-selected{ background: var(--accent); }

.leaflet-popup-content{ font-family: var(--font-ui); direction: rtl; text-align:right; font-size:12.8px; }
.map-pick-hint{
  position:absolute; z-index:500; top:10px; right:10px; left:10px;
  background: var(--navy-950); color:#fff; padding:9px 14px; border-radius:10px;
  font-size:12.6px; display:flex; align-items:center; justify-content:space-between; gap:10px;
  box-shadow: var(--shadow-pop);
}

/* ============ Modal ============ */
.modal-overlay{
  position:fixed; inset:0; background: rgba(12,18,24,.55);
  display:none; align-items:flex-start; justify-content:center;
  padding: 40px 16px; overflow-y:auto; z-index:200; backdrop-filter: blur(2px);
}
.modal-overlay.is-open{ display:flex; }
.modal{
  background:#fff; border-radius: var(--radius-lg); width:100%; max-width:640px;
  box-shadow: var(--shadow-pop); animation: pop .18s ease;
}
@keyframes pop{ from{opacity:0; transform: translateY(10px) scale(.98);} to{opacity:1; transform:none;} }
.modal-head{ display:flex; align-items:center; justify-content:space-between; padding:18px 22px; border-bottom:1px solid var(--border); }
.modal-head h2{ font-size:16.5px; font-weight:800; }
.modal-close{ background:none; border:none; cursor:pointer; color: var(--text-muted); font-size:20px; line-height:1; padding:4px; }
.modal-body{ padding: 20px 22px; max-height:70vh; overflow-y:auto; }
.modal-foot{ padding: 16px 22px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:10px; }

.doc-thumb{ width:100%; max-width:220px; border-radius:10px; border:1px solid var(--border); margin-top:6px; display:block; }
.rating-stars{ display:flex; gap:4px; font-size:26px; cursor:pointer; }
.rating-stars .star{ color:#D8DEE3; transition: color .1s; }
.rating-stars .star.is-active{ color: var(--accent); }

.summary-box{
  background: var(--bg); border:1px dashed var(--border); border-radius: var(--radius-md);
  padding:14px 16px; font-size:13px; display:flex; flex-direction:column; gap:6px;
}
.summary-row{ display:flex; justify-content:space-between; }
.summary-row.total{ font-weight:800; font-size:15px; padding-top:6px; border-top:1px solid var(--border); }
.summary-row .lbl{ color:var(--text-muted); }

/* ============ Toast ============ */
.toast-stack{ position:fixed; bottom:20px; left:20px; z-index:300; display:flex; flex-direction:column; gap:8px; }
.toast{
  background: var(--navy-950); color:#fff; padding:12px 18px; border-radius:12px;
  font-size:13px; box-shadow: var(--shadow-pop); animation: pop .18s ease;
  display:flex; align-items:center; gap:8px;
}
.toast.success{ background: var(--success); }
.toast.error{ background: var(--danger); }

/* ============ Actions row in tables ============ */
.row-actions{ display:flex; gap:6px; flex-wrap:wrap; }

/* ============ Print ============ */
.print-area{ display:none; }
@media print{
  body *{ visibility:hidden; }
  .print-area, .print-area *{ visibility:visible; }
  .print-area{ display:block; position:absolute; top:0; right:0; left:0; padding:24px; }
}

/* ============ Responsive sidebar ============ */
@media (max-width: 880px){
  .mobile-nav-toggle{ display:flex; align-items:center; justify-content:center; }
  .sidebar{
    position:fixed; z-index:55; height:100vh; transform: translateX(105%);
    transition: transform .22s ease; box-shadow: var(--shadow-pop);
  }
  html[dir=rtl] .sidebar.is-open{ transform: translateX(0); }
  .main{ padding: 74px 16px 50px; }
}
