:root {
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --text: #1F2937;
  --text-muted: #6B7280;
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --accent: #F59E0B;
  --border: #E5E7EB;
  --radius: 12px;
  --radius-btn: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Vazirmatn", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3 { font-weight: 700; margin: 0 0 16px; }
a { color: var(--primary); text-decoration: none; }

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

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.logo { font-weight: 700; font-size: 20px; color: var(--primary); }
.main-nav { display: flex; gap: 16px; flex: 1; }
.main-nav a { color: var(--text); padding: 6px 8px; border-radius: var(--radius-btn); }
.main-nav a:hover { background: var(--bg); }
.user-area { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.user-name { color: var(--text-muted); font-size: 14px; }
.inline-form { display: inline; }
.menu-toggle { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; }

.main-content { flex: 1; padding-top: 32px; padding-bottom: 32px; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 16px 0; color: var(--text-muted); font-size: 14px; }
.site-footer .container { display: flex; justify-content: space-between; }

.btn {
  display: inline-block;
  border: 0;
  border-radius: var(--radius-btn);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-block { display: block; width: 100%; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card { max-width: 400px; margin: 40px auto; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack input { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-btn); font-family: inherit; font-size: 15px; margin-bottom: 12px; }
.stack input:focus { outline: 2px solid var(--primary); border-color: transparent; }

.alert { padding: 12px 16px; border-radius: var(--radius-btn); margin-bottom: 16px; background: var(--surface); box-shadow: var(--shadow); }
.alert-success { border-right: 4px solid #059669; }
.alert-error { border-right: 4px solid #DC2626; }
.field-error { color: #DC2626; font-size: 14px; margin: 0 0 8px; }

@media (max-width: 768px) {
  .menu-toggle { display: block; margin-right: auto; }
  .main-nav { display: none; position: absolute; top: 64px; right: 0; left: 0; flex-direction: column; background: var(--surface); padding: 12px 24px; border-bottom: 1px solid var(--border); }
  .main-nav.open { display: flex; }
  .user-area { display: none; }
}

.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: start; }
.sidebar { position: sticky; top: 88px; }
.filter-form input, .filter-form select { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-btn); font-family: inherit; font-size: 14px; margin-bottom: 10px; background: #fff; }
.filter-form label { font-size: 14px; color: var(--text-muted); }
.cat-title { margin-top: 24px; font-size: 16px; }
.cat-list { list-style: none; padding: 0; margin: 0; }
.cat-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.badge { background: var(--bg); color: var(--text-muted); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.badge-accent { background: #FEF3C7; color: #92400E; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px; }
.doc-card { display: block; color: var(--text); transition: box-shadow 0.2s; }
.doc-card:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); }
.doc-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.doc-plate { font-size: 18px; margin-bottom: 6px; }
.doc-owner { margin: 0 0 12px; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--text-muted); }
.pagination { grid-column: 1 / -1; display: flex; justify-content: center; align-items: center; gap: 16px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

.form-card { max-width: 640px; margin: 0 auto; }
.form-card input[type="text"], .form-card input[type="file"], .form-card select, .form-card textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-family: inherit; font-size: 15px; margin-bottom: 8px; background: #fff;
}
.form-card textarea { min-height: 90px; }
.req { color: #DC2626; }
.form-actions { display: flex; gap: 12px; margin-top: 16px; }

.detail-title { margin-bottom: 4px; }
.action-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn-danger { background: #FEE2E2; color: #B91C1C; }
.btn-danger:hover { background: #FECACA; }
.detail-layout { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.preview-card { padding: 16px; min-height: 400px; }
.pdf-frame { width: 100%; height: 75vh; border: 0; border-radius: var(--radius-btn); }
.thumb { max-width: 100%; border-radius: var(--radius-btn); cursor: zoom-in; display: block; margin: 0 auto; }
.no-preview { text-align: center; color: var(--text-muted); padding: 60px 16px; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.info-list dt { color: var(--text-muted); }
.info-list dd { margin: 0; }
.log-title { margin-top: 28px; font-size: 16px; }
.log-list { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.log-list li { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.log-user { margin: 0 8px; font-weight: 600; }
.lightbox { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.85); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 24px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius-btn); }
@media (max-width: 900px) {
  .detail-layout { grid-template-columns: 1fr; }
  .pdf-frame { height: 60vh; }
}

.table-card { padding: 0; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.data-table th { text-align: right; font-weight: 600; color: var(--text-muted); font-size: 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: var(--bg); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 8px; justify-content: flex-start; align-items: center; }

.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 24px; padding: 16px 20px; }
.filter-bar select { padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-btn); font-family: inherit; font-size: 14px; background: #fff; min-width: 180px; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 400; }

/* ===== ریسپانسیو موبایل و تبلت ===== */
html { -webkit-text-size-adjust: 100%; }
img, iframe, video { max-width: 100%; }

@media (max-width: 1024px) {
  .container { padding: 0 20px; }
  .doc-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .container { padding: 0 16px; }
  body { font-size: 15px; }
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }

  /* هدر و منو */
  .header-inner { height: 56px; gap: 12px; }
  .logo { font-size: 18px; }
  .main-nav {
    top: 56px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  }
  .main-nav a { padding: 12px 8px; }
  .user-area { margin-right: 0; gap: 8px; }
  .user-name { display: none; }
  .btn-ghost { padding: 8px 10px; }
  .menu-toggle { margin-right: 0; padding: 4px 8px; }

  /* صفحه‌ها */
  .main-content { padding-top: 20px; padding-bottom: 24px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; }
  .page-head .btn { width: 100%; text-align: center; }
  .action-row { width: 100%; }
  .action-row .btn, .action-row .inline-form { flex: 1 1 auto; }
  .action-row .inline-form .btn { width: 100%; }

  /* لیست اسناد */
  .layout { grid-template-columns: 1fr; gap: 16px; }
  .sidebar { position: static; padding: 16px; }
  .doc-grid { grid-template-columns: 1fr; gap: 14px; }
  .doc-card { padding: 18px; }
  .filter-bar { padding: 14px; }
  .filter-bar select, .filter-bar .btn { width: 100%; min-width: 0; }

  /* جزئیات سند */
  .detail-layout { grid-template-columns: 1fr; gap: 16px; }
  .preview-card { padding: 10px; min-height: 0; }
  .pdf-frame { height: 65vh; }
  .info-card { padding: 18px; }

  /* فرم‌ها */
  .form-card { padding: 18px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; text-align: center; }
  .stack input, .stack select, .stack textarea,
  .form-card input, .form-card select, .form-card textarea { font-size: 16px; }

  /* جدول‌ها: اسکرول افقی داخل کارت */
  .table-card { margin: 0 -4px; }
  .data-table { font-size: 14px; min-width: 560px; }
  .data-table th, .data-table td { padding: 10px 12px; }
  .row-actions { flex-wrap: wrap; }

  /* صفحه‌بندی و فوتر */
  .pagination { flex-wrap: wrap; gap: 10px; }
  .site-footer .container { flex-direction: column; gap: 6px; align-items: center; text-align: center; }
}

@media (max-width: 380px) {
  .logo { font-size: 16px; }
  .header-inner { gap: 8px; }
  .btn { padding: 9px 12px; font-size: 14px; }
}

/* ===== پس‌زمینه دکمه‌ها ===== */
.btn {
  border: 1px solid transparent;
  font-weight: 600;
  letter-spacing: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: #2563EB;
  color: #FFFFFF;
  border-color: #2563EB;
}
.btn-primary:hover { background: #1D4ED8; border-color: #1D4ED8; box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25); }

.btn-ghost {
  background: #F3F4F6;
  color: #1F2937;
  border-color: #E5E7EB;
}
.btn-ghost:hover { background: #E5E7EB; color: #111827; }

.btn-danger {
  background: #FEE2E2;
  color: #B91C1C;
  border-color: #FECACA;
}
.btn-danger:hover { background: #FECACA; color: #991B1B; }

.btn:focus-visible { outline: 2px solid #2563EB; outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* دکمه ورود و ذخیره: کمی بزرگ‌تر برای تمایز */
.auth-card .btn-primary,
.form-actions .btn-primary { padding: 11px 22px; }

/* ===== پس‌زمینه گزینه‌های منو ===== */
.main-nav a {
  background: #F3F4F6;
  color: #1F2937;
  border: 1px solid #E5E7EB;
  border-radius: var(--radius-btn);
  padding: 7px 14px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.main-nav a:hover {
  background: #E5E7EB;
  color: #111827;
}
.main-nav a.active {
  background: #2563EB;
  border-color: #2563EB;
  color: #FFFFFF;
}
.main-nav a.active:hover {
  background: #1D4ED8;
  border-color: #1D4ED8;
}

@media (max-width: 768px) {
  .main-nav a { display: block; border-radius: var(--radius-btn); margin-bottom: 6px; }
}

/* ===== پس‌زمینه اصلی تیره‌تر ===== */
:root {
  --bg: #E2E8F0;
}
body {
  background: var(--bg);
}
.sidebar, .card, .site-header, .site-footer {
  background: #FFFFFF;
}

.case-summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: var(--bg); border-radius: var(--radius-btn); padding: 12px 14px; margin: 12px 0 20px; }

.add-files-card { margin-top: 24px; }
.add-files-card h2 { font-size: 18px; margin-bottom: 6px; }
.add-files-card input[type="file"] { padding: 10px; border: 1px dashed var(--border); border-radius: var(--radius-btn); background: #fff; font-family: inherit; }

.doc-card.multi { border-right: 4px solid #2563EB; }
.badge-files { background: #DBEAFE; color: #1E40AF; font-size: 12px; margin-right: 6px; vertical-align: middle; }
.current-file { font-weight: 700; color: var(--text); word-break: break-all; }
.log-list li a { word-break: break-all; }

.file-list { list-style: none; padding: 0; margin: 0; }
.file-item { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.file-item a { flex: 1 1 auto; word-break: break-all; }
.btn-link-danger { background: #FEE2E2; color: #B91C1C; border: 0; border-radius: 6px; padding: 4px 10px; font-family: inherit; font-size: 13px; cursor: pointer; }
.btn-link-danger:hover { background: #FECACA; }
