/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-light: #EFF6FF;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text: #0F172A;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --success: #059669;
  --danger: #DC2626;
  --warning: #D97706;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --font: 'Vazirmatn', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 1.25rem; }

/* ===== Header ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.75rem 0 1.5rem;
  text-align: center;
}
.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 520px;
  margin: 0 auto;
}

/* ===== Main ===== */
.main { padding: 2rem 0 3rem; }

/* ===== Upload Zone ===== */
.upload-section { max-width: 640px; margin: 0 auto; }
.drop-zone {
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}
.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.drop-zone.dragover .upload-icon { color: var(--primary); }
.upload-icon {
  color: var(--text-muted);
  margin-bottom: 1rem;
  transition: color 0.2s;
}
.drop-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.drop-hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.drop-formats {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Files List (pre-process) ===== */
.files-list {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.file-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: var(--shadow);
}
.file-icon {
  width: 40px;
  height: 40px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-weight: 500;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}
.btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 4px;
  font-size: 1.1rem;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-remove:hover { color: var(--danger); background: #FEF2F2; }

/* ===== Process Area ===== */
.process-area {
  margin-top: 1.5rem;
  text-align: center;
}
.process-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  min-height: 1.4em;
}
.process-status.success { color: var(--success); }
.process-status.error { color: var(--danger); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.65rem 1.35rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary {
  background: #F1F5F9;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #E2E8F0; }
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border-color: #FECACA;
}
.btn-danger-outline:hover:not(:disabled) { background: #FEF2F2; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.82rem; }
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Results Layout ===== */
.results-section { margin-top: 0.5rem; }
.results-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 900px) {
  .results-layout { grid-template-columns: 1fr; }
}

/* ===== Files Panel ===== */
.files-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 1rem;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
}
.processed-files {
  list-style: none;
  max-height: 360px;
  overflow-y: auto;
}
.processed-file {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.processed-file:hover { background: #F8FAFC; }
.processed-file.active {
  background: var(--primary-light);
  border-right: 3px solid var(--primary);
}
.processed-file-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.processed-file-stats {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}
.panel-actions {
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
}

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

/* ===== File Meta ===== */
.file-meta {
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.file-meta h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
  color: var(--text);
}
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.65rem 1.25rem;
}
.meta-item label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.1rem;
}
.meta-item span {
  font-size: 0.9rem;
  font-weight: 500;
  word-break: break-word;
}
.meta-desc {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* ===== Sheet Tabs ===== */
.sheet-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.sheet-tab {
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.sheet-tab:hover { border-color: var(--primary); color: var(--primary); }
.sheet-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
}

/* ===== Table Controls ===== */
.table-controls {
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
}
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}
.search-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 0.5rem 2.4rem 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.search-box input:focus { border-color: var(--primary); background: var(--surface); }
.controls-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.select {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.select:focus { border-color: var(--primary); }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.filter-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
}
.filter-chip select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.8rem;
  max-width: 160px;
}
.selection-info {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ===== Data Table ===== */
.table-wrapper { overflow: hidden; }
.table-scroll {
  overflow-x: auto;
  max-height: 560px;
  overflow-y: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  white-space: nowrap;
}
.data-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #F1F5F9;
}
.data-table th {
  padding: 0.7rem 0.9rem;
  text-align: right;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border-strong);
  background: #F1F5F9;
}
.data-table th.checkbox-col,
.data-table td.checkbox-col {
  width: 42px;
  text-align: center;
  padding: 0.5rem;
}
.data-table td {
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.data-table tbody tr:hover { background: #F8FAFC; }
.data-table tbody tr.selected { background: var(--primary-light); }
.data-table tbody tr.selected:hover { background: #DBEAFE; }
.data-table .num-cell {
  font-variant-numeric: tabular-nums;
  text-align: left;
  direction: ltr;
}
.data-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}
.empty-table {
  padding: 3rem;
  text-align: center;
  color: var(--text-secondary);
}

/* ===== Pagination ===== */
.pagination {
  margin-top: 0.85rem;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.pagination-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.pagination-btns {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}
.page-btn:hover:not(:disabled):not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}
.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 500;
}
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}
.detail-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-label {
  flex: 0 0 120px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.detail-value {
  flex: 1;
  font-size: 0.9rem;
  word-break: break-word;
}
.detail-value.num {
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 0.75rem 1.35rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 200;
  box-shadow: var(--shadow-md);
  max-width: 90%;
  text-align: center;
}
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .header { padding: 1.25rem 0 1rem; }
  .logo { font-size: 1.25rem; }
  .drop-zone { padding: 2rem 1.25rem; }
  .controls-row { flex-direction: column; align-items: stretch; }
  .search-box { max-width: none; }
  .controls-left { justify-content: flex-start; }
  .meta-grid { grid-template-columns: 1fr; }
  .detail-label { flex: 0 0 100px; }
}
