/* ====================================================================
   ندای امداد — پنل وب مدیریت
   توکن‌های طراحی عمداً همان پالت اپ اندروید را تکرار می‌کنند (نگاه کنید
   به mobile/lib/core/theme/app_theme.dart) تا هویت بصری «ندای امداد»
   بین وب و موبایل یکسان بماند، نه دو برند جدا.
   ==================================================================== */

:root {
  /* --- رنگ برند (منطبق بر AppTheme.dart) --- */
  --color-red: #D32F2F;
  --color-red-dark: #B71C1C;
  --color-blue: #0D47A1;
  --color-blue-light: #1565C0;
  --color-green: #2E7D32;
  --color-amber: #F9A825;
  --color-orange: #EF6C00;

  /* --- خنثی --- */
  --color-bg: #F3F5F9;
  --color-surface: #FFFFFF;
  --color-sidebar: #0B1E33;
  --color-sidebar-hover: #142E4C;
  --color-text: #1B2430;
  --color-text-muted: #6B7686;
  --color-text-soft: #93A0B4;
  --color-border: #E4E9F1;

  /* --- سطوح رنگ وضعیت (پاسخ/آماده‌به‌کار) --- */
  --status-ready-bg: #E7F5EA;
  --status-ready-fg: #2E7D32;
  --status-pending-bg: #FFF6E0;
  --status-pending-fg: #B8860B;
  --status-inactive-bg: #F1F2F5;
  --status-inactive-fg: #6B7686;
  --status-urgent-bg: #FDEAEA;
  --status-urgent-fg: #D32F2F;

  /* --- هندسه --- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 248px;
  --header-height: 72px;

  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-pop: 0 8px 24px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

/* اندازه پیش‌فرض آیکون‌های SVG — بدون این، بعضی مرورگرهای ویندوز
   (به‌خصوص Edge/Chrome) SVG بدون width/height را خیلی بزرگ رندر می‌کنند */
svg.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* اعداد فارسی هم از همین فونت رندر می‌شوند تا با متن هم‌وزن باشند */
.num { font-variant-numeric: tabular-nums; }

/* ==================== Layout ==================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.main-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page-content {
  padding: 24px 28px 40px;
  flex: 1;
}

/* ==================== Sidebar ==================== */

.sidebar {
  background: var(--color-sidebar);
  color: #C9D3E0;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-org {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 16px;
}

.sidebar-org img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}

.sidebar-org .placeholder-logo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-red);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: none;
}

.sidebar-org-name {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.sidebar-org-sub {
  font-size: 11px;
  color: var(--color-text-soft);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: #C9D3E0;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s ease;
  position: relative;
}

.sidebar-link .icon { width: 19px; height: 19px; flex: none; opacity: 0.85; }

.sidebar-link:hover { background: var(--color-sidebar-hover); color: #fff; }

.sidebar-link.active {
  background: var(--color-red);
  color: #fff;
}
.sidebar-link.active .icon { opacity: 1; }

.sidebar-badge {
  margin-inline-start: auto;
  background: rgba(255,255,255,0.18);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 700;
}
.sidebar-link.active .sidebar-badge { background: rgba(255,255,255,0.28); }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 14px;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none; /* جلوگیری از کش‌آمدن دکمه خروج روی ارتفاع زیاد صفحه */
}

.sidebar-branch-chip {
  background: var(--color-sidebar-hover);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
}
.sidebar-branch-chip .label { color: var(--color-text-soft); display: block; margin-bottom: 2px; }
.sidebar-branch-chip .value { color: #fff; font-weight: 600; }

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: #F3B9B9;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  background: rgba(211,47,47,0.12);
  border: none;
  width: 100%;
  max-width: 100%;
  flex: none;
  box-sizing: border-box;
  text-align: start;
}
.sidebar-logout .icon {
  width: 18px;
  height: 18px;
  flex: none;
  flex-shrink: 0;
  display: block;
}
.sidebar-logout:hover { background: rgba(211,47,47,0.22); color: #ffd4d4; }

/* ==================== Header ==================== */

.topbar {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-search {
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 9px 16px;
  color: var(--color-text-muted);
  font-size: 13px;
}
.topbar-search input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-family: inherit;
  font-size: 13px;
  color: var(--color-text);
}

.topbar-spacer { flex: 1; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}
.icon-btn:hover { background: var(--color-bg); }
.icon-btn .icon { width: 18px; height: 18px; }

.icon-btn .dot-badge {
  position: absolute;
  top: -3px;
  inset-inline-end: -3px;
  background: var(--color-red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--color-surface);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-inline-start: 12px;
  margin-inline-start: 6px;
  border-inline-start: 1px solid var(--color-border);
}

.topbar-user img, .topbar-user .avatar-fallback {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.topbar-user .avatar-fallback {
  background: var(--color-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.topbar-user-name { font-weight: 700; font-size: 13.5px; }
.topbar-user-role { font-size: 11.5px; color: var(--color-text-muted); }

/* ==================== Cards & grids ==================== */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--color-border);
}
.card-header h3 { font-size: 14.5px; margin: 0; font-weight: 700; }
.card-header .spacer { flex: 1; }
.card-header .count-badge {
  background: var(--status-urgent-bg);
  color: var(--status-urgent-fg);
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 9px;
}
.card-header .link { font-size: 12.5px; color: var(--color-blue); font-weight: 600; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-card);
}

.stat-card .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.stat-card .stat-icon .icon { width: 22px; height: 22px; }

.stat-card .stat-value { font-size: 22px; font-weight: 800; }
.stat-card .stat-label { font-size: 12px; color: var(--color-text-muted); margin-top: 1px; }

.stat-icon.tone-red { background: var(--status-urgent-bg); color: var(--color-red); }
.stat-icon.tone-orange { background: #FFF1E4; color: var(--color-orange); }
.stat-icon.tone-green { background: var(--status-ready-bg); color: var(--color-green); }
.stat-icon.tone-blue { background: #E7EEFA; color: var(--color-blue); }
.stat-icon.tone-purple { background: #F0EAFB; color: #6A3EC4; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.tables-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1fr;
  gap: 16px;
}

/* ==================== Placeholder (فیچرهای هنوز پیاده‌نشده) ==================== */

.coming-soon {
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-md);
  background: #FAFBFD;
  color: var(--color-text-muted);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 28px 16px;
  min-height: 220px;
}
.coming-soon .icon { width: 30px; height: 30px; opacity: 0.5; }
.coming-soon .cs-title { font-weight: 700; color: var(--color-text); font-size: 13px; }
.coming-soon .cs-tag {
  background: #EFF2F7;
  color: var(--color-text-muted);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ==================== Lists ==================== */

.callup-list { list-style: none; margin: 0; padding: 8px; }
.callup-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
}
.callup-row:hover { background: var(--color-bg); }
.callup-row .type-icon {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.callup-row .type-icon .icon { width: 16px; height: 16px; }
.callup-row .body { flex: 1; min-width: 0; }
.callup-row .title { font-size: 13px; font-weight: 700; }
.callup-row .meta { font-size: 11.5px; color: var(--color-text-muted); margin-top: 1px; }
.callup-row .time { font-size: 11px; color: var(--color-text-soft); flex: none; }

.empty-row {
  padding: 24px 12px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 12.5px;
}

/* ==================== Badges / pills ==================== */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.pill-ready { background: var(--status-ready-bg); color: var(--status-ready-fg); }
.pill-pending { background: var(--status-pending-bg); color: var(--status-pending-fg); }
.pill-inactive { background: var(--status-inactive-bg); color: var(--status-inactive-fg); }
.pill-urgent { background: var(--status-urgent-bg); color: var(--status-urgent-fg); }
.pill-blue { background: #E7EEFA; color: var(--color-blue); }

/* ==================== Tables ==================== */

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  text-align: start;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 11.5px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--color-border); }
tbody tr:last-child td { border-bottom: none; }

.person-cell { display: flex; align-items: center; gap: 8px; }
.person-cell img, .person-cell .avatar-fallback {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: none;
}
.person-cell .avatar-fallback {
  background: var(--color-blue); color: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 700;
}

/* ==================== Alert level banner ==================== */

.alert-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  border: 1px solid var(--color-border);
}
.alert-banner .icon-wrap {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex: none;
  background: rgba(255,255,255,0.6);
}
.alert-banner .title { font-weight: 800; font-size: 14px; }
.alert-banner .subtitle { font-size: 12px; opacity: 0.85; }
.alert-banner .manage-btn {
  margin-inline-start: auto;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 700;
}

.alert-white { background: #F4F6F9; color: #4B5768; }
.alert-yellow { background: #FFF8E1; color: #8A6D00; }
.alert-orange { background: #FFF1E4; color: var(--color-orange); }
.alert-red { background: #FDEAEA; color: var(--color-red); }

/* ==================== بنر داشبورد (عکس واقعی سازمان یا جایگزین پیش‌فرض) ==================== */

.dashboard-banner {
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  overflow: hidden;
  height: 150px;
}
.dashboard-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.dashboard-banner .fallback {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  background: linear-gradient(120deg, var(--color-blue) 0%, var(--color-blue-light) 100%);
  color: #fff;
}
.dashboard-banner .fallback .icon { width: 46px; height: 46px; opacity: 0.5; flex: none; }
.dashboard-banner .fallback .headline { font-size: 18px; font-weight: 800; }
.dashboard-banner .fallback .subline { font-size: 12.5px; opacity: 0.85; margin-top: 2px; }

/* ==================== Buttons / forms ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
}
.btn-primary { background: var(--color-red); color: #fff; }
.btn-primary:hover { background: var(--color-red-dark); }
.btn-outline { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-outline:hover { background: var(--color-bg); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }
.small-btn { padding: 5px 10px !important; font-size: 11.5px !important; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--color-text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: inherit;
  font-size: 13.5px;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(13,71,161,0.12);
}

.form-error {
  background: var(--status-urgent-bg);
  color: var(--status-urgent-fg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: 14px;
}
.form-success {
  background: var(--status-ready-bg);
  color: var(--status-ready-fg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ==================== Login page ==================== */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-sidebar) 0%, #16324F 100%);
  padding: 20px;
}
.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  box-shadow: var(--shadow-pop);
}
.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 26px;
}
.login-logo .placeholder-logo {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--color-red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
}
.login-logo h1 { font-size: 17px; margin: 0; }
.login-logo p { font-size: 12px; color: var(--color-text-muted); margin: 0; }

/* ==================== Utility ==================== */

.hidden { display: none !important; }
.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: var(--color-red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-title { font-size: 19px; font-weight: 800; margin: 0 0 2px; }
.page-subtitle { font-size: 12.5px; color: var(--color-text-muted); margin: 0 0 20px; }
.page-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
}

/* ==================== Responsive ==================== */

.sidebar-toggle { display: none; }

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: 1.4fr 1fr; }
  .dashboard-grid .col-chart { grid-column: span 2; }
  .tables-grid { grid-template-columns: 1fr 1fr; }
  .tables-grid .col-news { grid-column: span 2; }
}

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid .col-chart { grid-column: span 1; }
  .tables-grid { grid-template-columns: 1fr; }
  .tables-grid .col-news { grid-column: span 1; }
  .topbar-search { display: none; }
}

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    width: 260px;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }
  html[dir="rtl"] .sidebar.open { transform: translateX(0); }
  .sidebar-toggle {
    display: flex;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    align-items: center; justify-content: center;
    background: var(--color-surface);
  }
  .sidebar-scrim {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 40;
  }
  .sidebar-scrim.open { display: block; }
  .topbar-user-name, .topbar-user-role { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 18px 16px 32px; }
}


/* ==================== Weekly chart (dashboard) ==================== */

.week-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  height: 160px;
  padding: 0 4px;
}
.week-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.week-bar-value {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  height: 14px;
}
.week-bar {
  width: 70%;
  max-width: 28px;
  background: linear-gradient(180deg, #3B82F6 0%, #2563EB 100%);
  border-radius: 6px 6px 2px 2px;
  min-height: 2px;
  transition: height 0.3s ease;
}
.week-bar-label {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}

/* ==================== Live map preview card ==================== */

.live-map-preview {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.live-map-preview-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #EFF6FF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  color: #2563EB;
}
.live-map-preview-icon .icon { width: 20px; height: 20px; }

/* reuse map-stat styles from live-map if not already global */
.map-stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.map-stat-box {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.map-stat-box .num {
  font-size: 16px;
  font-weight: 800;
  color: var(--color-text);
}
.map-stat-box .lbl {
  font-size: 10.5px;
  color: var(--color-text-muted);
  margin-top: 2px;
}
@media (max-width: 640px) {
  .map-stat-row { grid-template-columns: repeat(2, 1fr); }
  .week-chart { height: 130px; }
}
