/* ==========================================================================
   R K KNIT FAB - DOCUMENT VAULT STYLESHEET
   "Engineered Knits, Trusted Quality"
   ========================================================================== */

/* --- Custom Properties / Design Tokens --- */
:root {
  /* Brand Colors from Logo */
  --rk-navy: #182276;
  --rk-navy-dark: #0f1652;
  --rk-navy-light: #2635a9;
  --rk-red: #df2029;
  --rk-red-hover: #c41820;
  --rk-red-soft: #fde8e9;
  --rk-navy-soft: #eef2ff;
  
  /* Neutral Grayscale */
  --bg-app: #f4f6fa;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  /* Document Type Badge Colors */
  --badge-aadhaar-bg: #e0f2fe;
  --badge-aadhaar-text: #0369a1;
  --badge-pan-bg: #fef3c7;
  --badge-pan-text: #b45309;
  --badge-gst-bg: #dcfce7;
  --badge-gst-text: #15803d;
  --badge-msme-bg: #fae8ff;
  --badge-msme-text: #86198f;
  --badge-bank-bg: #ffedd5;
  --badge-bank-text: #c2410c;
  --badge-other-bg: #f1f5f9;
  --badge-other-text: #475569;

  /* Elevation & Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 2px 5px rgba(24, 34, 118, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 14px rgba(24, 34, 118, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px -3px rgba(24, 34, 118, 0.12), 0 4px 10px -2px rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 25px 50px -12px rgba(15, 22, 82, 0.25);

  /* Spacing Grid & Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

/* --- Top Header & Brand Bar --- */
.app-header {
  background: var(--rk-navy);
  color: #ffffff;
  padding: 14px 20px;
  box-shadow: 0 4px 16px rgba(15, 22, 82, 0.18);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 3px solid var(--rk-red);
}

.header-container {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo-img {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: #ffffff;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  object-fit: cover;
  flex-shrink: 0;
}

.brand-titles {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #ffffff;
  line-height: 1.15;
}

.brand-slogan {
  font-size: 0.8rem;
  color: #e2e8f0;
  font-weight: 500;
  letter-spacing: 0.3px;
  margin-top: 3px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Sync Status Indicator */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: #ffffff;
  backdrop-filter: blur(4px);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
  animation: pulse-dot 2s infinite;
}

.status-dot.offline {
  background-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.btn-header-icon {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-header-icon:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

/* --- Main Layout --- */
.main-content {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
  flex: 1;
}

/* --- Stats Cards Bar --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}

.stat-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.stat-icon.blue {
  background: var(--rk-navy-soft);
  color: var(--rk-navy);
}

.stat-icon.red {
  background: var(--rk-red-soft);
  color: var(--rk-red);
}

.stat-icon.green {
  background: #dcfce7;
  color: #15803d;
}

.stat-icon.purple {
  background: #f3e8ff;
  color: #7e22ce;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

/* --- Main Controls & Action Toolbar --- */
.toolbar-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.toolbar-primary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* Search Box */
.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 260px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 1rem;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  font-size: 0.95rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-app);
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
  min-height: 44px;
}

.search-input:focus {
  border-color: var(--rk-navy);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(24, 34, 118, 0.12);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  min-height: 44px;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--rk-red);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(223, 32, 41, 0.28);
}

.btn-primary:hover {
  background: var(--rk-red-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(223, 32, 41, 0.38);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--rk-navy);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(24, 34, 118, 0.25);
}

.btn-secondary:hover {
  background: var(--rk-navy-light);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--rk-navy);
  border: 1.5px solid var(--border-color);
}

.btn-outline:hover {
  border-color: var(--rk-navy);
  background: var(--rk-navy-soft);
}

/* Person/Entity Filter Dropdown */
.person-filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.person-select-wrapper {
  position: relative;
  min-width: 220px;
}

.person-select {
  width: 100%;
  padding: 10px 36px 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--rk-navy);
  outline: none;
  cursor: pointer;
  appearance: none;
  min-height: 44px;
  transition: var(--transition);
}

.person-select:focus {
  border-color: var(--rk-navy);
  box-shadow: 0 0 0 3px rgba(24, 34, 118, 0.12);
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
}

/* View Switcher (Grid / Table) */
.view-toggle-group {
  display: inline-flex;
  background: var(--bg-app);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.view-toggle-btn {
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
}

.view-toggle-btn.active {
  background: #ffffff;
  color: var(--rk-navy);
  box-shadow: var(--shadow-xs);
  font-weight: 700;
}

/* Document Type Filter Chips */
.type-chips-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.type-chips-scroll::-webkit-scrollbar {
  height: 4px;
}

.type-chips-scroll::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.filter-chip {
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-color);
  background: #ffffff;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
  min-height: 38px;
}

.filter-chip:hover {
  border-color: var(--rk-navy);
  color: var(--rk-navy);
  background: var(--rk-navy-soft);
}

.filter-chip.active {
  background: var(--rk-navy);
  color: #ffffff;
  border-color: var(--rk-navy);
  box-shadow: 0 2px 8px rgba(24, 34, 118, 0.22);
}

.chip-count {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.08);
}

.filter-chip.active .chip-count {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* --- Section Heading & Results Summary --- */
.section-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 4px;
  flex-wrap: wrap;
  gap: 8px;
}

.results-heading {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--rk-navy);
  display: flex;
  align-items: center;
  gap: 8px;
}

.results-count-tag {
  font-size: 0.82rem;
  background: var(--border-color);
  color: var(--text-main);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.clear-filters-btn {
  background: none;
  border: none;
  color: var(--rk-red);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 8px;
}

.clear-filters-btn:hover {
  color: var(--rk-red-hover);
}

/* --- Documents Grid View --- */
.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 20px;
}

/* Document Card */
.doc-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
  position: relative;
}

.doc-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

/* Card Header */
.doc-card-header {
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.doc-badge-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-aadhaar { background: var(--badge-aadhaar-bg); color: var(--badge-aadhaar-text); }
.badge-pan { background: var(--badge-pan-bg); color: var(--badge-pan-text); }
.badge-gst { background: var(--badge-gst-bg); color: var(--badge-gst-text); }
.badge-msme { background: var(--badge-msme-bg); color: var(--badge-msme-text); }
.badge-bank { background: var(--badge-bank-bg); color: var(--badge-bank-text); }
.badge-other { background: var(--badge-other-bg); color: var(--badge-other-text); }

.doc-format-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.doc-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover {
  background: var(--bg-app);
  color: var(--rk-navy);
  border-color: var(--border-color);
}

.icon-btn.delete:hover {
  background: var(--rk-red-soft);
  color: var(--rk-red);
  border-color: #fecaca;
}

/* Card Body */
.doc-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.doc-person-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.person-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--rk-navy);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.person-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.person-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-reg-number {
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--rk-navy-light);
  font-weight: 600;
}

/* File Info Box */
.file-info-box {
  background: var(--bg-app);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #edf2f7;
}

.file-format-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.file-names-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.file-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size-date {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.doc-notes-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: #fff;
  border-left: 3px solid var(--border-color);
  padding: 4px 8px;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card Footer / Action Buttons */
.doc-card-footer {
  padding: 12px 16px;
  background: #fafbfc;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-btn {
  flex: 1;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--rk-navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  min-height: 38px;
}

.card-btn:hover {
  border-color: var(--rk-navy);
  background: var(--rk-navy-soft);
  color: var(--rk-navy);
}

.card-btn.download-btn {
  background: var(--rk-navy);
  color: #ffffff;
  border-color: var(--rk-navy);
}

.card-btn.download-btn:hover {
  background: var(--rk-navy-light);
}

/* --- Table View Alternative --- */
.table-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.docs-table th {
  background: var(--rk-navy-soft);
  color: var(--rk-navy);
  padding: 12px 16px;
  font-weight: 700;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.docs-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.docs-table tr:hover td {
  background-color: #fafbfc;
}

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

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border-color);
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  opacity: 0.7;
}

.empty-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--rk-navy);
  margin-bottom: 8px;
}

.empty-description {
  color: var(--text-muted);
  max-width: 420px;
  margin: 0 auto 24px;
  font-size: 0.92rem;
}

/* --- Modals (Upload, Preview, Settings) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 82, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 600px;
  max-height: min(90vh, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  margin: auto; /* Prevents top clipping in flex centering when taller than screen */
  overflow: hidden;
  position: relative;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0) scale(1);
}

/* Crucial: ensure forms within modals adopt flex-column constraints */
.modal-card > form,
#uploadForm {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  background: var(--rk-navy);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--rk-red);
  flex-shrink: 0; /* Header must never shrink or clip */
  gap: 12px;
  z-index: 2;
}

.modal-title {
  font-size: 1.12rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.modal-body {
  padding: 20px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Custom smooth scrollbar for modal-body */
.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Form Groups & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-label .required {
  color: var(--rk-red);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  color: var(--text-main);
  background: #ffffff;
  outline: none;
  transition: var(--transition);
  min-height: 44px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--rk-navy);
  box-shadow: 0 0 0 3px rgba(24, 34, 118, 0.12);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-help {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Drag and Drop Zone */
.dropzone-area {
  border: 2px dashed var(--rk-navy);
  border-radius: var(--radius-lg);
  background: var(--rk-navy-soft);
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.dropzone-area:hover, .dropzone-area.dragover {
  background: #e0e7ff;
  border-color: var(--rk-red);
}

.dropzone-icon {
  font-size: 2.2rem;
  color: var(--rk-navy);
}

.dropzone-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--rk-navy);
}

.dropzone-subtext {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Selected File Preview Box */
.selected-file-badge {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #ffffff;
  border: 1.5px solid #22c55e;
  border-radius: var(--radius-md);
  margin-top: 8px;
}

.file-preview-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.file-remove-btn {
  background: none;
  border: none;
  color: var(--rk-red);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
}

/* Modal Footer */
.modal-footer {
  padding: 14px 20px;
  background: #fafbfc;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0; /* Footer must never shrink or clip */
  z-index: 2;
}

/* --- Document Preview Modal --- */
.preview-modal-card {
  max-width: 860px;
  height: 85vh;
  max-height: min(88vh, calc(100dvh - 32px));
}

.preview-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  overflow: hidden;
  position: relative;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.preview-fallback {
  text-align: center;
  color: #ffffff;
  padding: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--rk-navy);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-main);
  font-size: 0.9rem;
  min-width: 280px;
  max-width: 380px;
  pointer-events: auto;
  animation: slideInToast 0.3s ease-out;
}

.toast.success {
  border-left-color: #22c55e;
}

.toast.error {
  border-left-color: var(--rk-red);
}

@keyframes slideInToast {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Footer --- */
.app-footer {
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 16px 20px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: auto;
}

.footer-highlight {
  color: var(--rk-navy);
  font-weight: 700;
}

/* --- Responsive Adjustments & Smartphone Optimization --- */
@media (max-width: 768px) {
  .app-header {
    padding: 10px 16px;
  }

  .header-container {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .brand-logo-img {
    width: 42px;
    height: 42px;
  }

  .brand-name {
    font-size: 1.18rem;
  }

  .brand-slogan {
    font-size: 0.75rem;
  }

  .btn-header-icon {
    width: 36px;
    height: 36px;
  }

  .sync-status {
    padding: 5px 10px;
    font-size: 0.76rem;
  }

  .main-content {
    padding: 16px 14px 40px;
  }

  /* Prevent automatic iOS Safari zoom on input focus */
  .form-input, .form-select, .form-textarea, .search-input, .person-select {
    font-size: 16px !important;
  }

  /* 2x2 Clean Dashboard Stats Grid */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 18px;
  }

  .stat-card {
    padding: 12px 14px;
    gap: 12px;
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }

  .stat-value {
    font-size: 1.28rem;
  }

  .stat-label {
    font-size: 0.74rem;
    line-height: 1.2;
  }

  /* Toolbar layout */
  .toolbar-card {
    padding: 16px 14px;
    gap: 12px;
  }

  .toolbar-primary {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .search-wrapper {
    width: 100%;
    min-width: 100%;
  }

  .toolbar-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    width: 100%;
  }

  .person-select-wrapper {
    flex: 1;
    min-width: 160px;
  }

  .view-toggle-group {
    flex-shrink: 0;
  }

  .btn-primary#btnOpenUpload {
    width: 100%;
    min-height: 46px;
  }

  /* Touch-friendly horizontal chips bar */
  .type-chips-scroll {
    padding: 2px 2px 6px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .type-chips-scroll::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    padding: 7px 12px;
    font-size: 0.8rem;
    min-height: 36px;
  }

  .documents-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .modal-card {
    max-height: min(92vh, calc(100dvh - 24px));
  }

  .modal-body {
    padding: 18px 16px;
  }

  .modal-footer {
    padding: 12px 16px;
  }

  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .toast {
    max-width: 100%;
  }
}

/* --- Dedicated Smartphone Size (<= 540px) --- */
@media (max-width: 540px) {
  .app-header {
    padding: 8px 12px;
  }

  .header-container {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .brand-section {
    gap: 8px;
  }

  .brand-logo-img {
    width: 36px;
    height: 36px;
  }

  .brand-name {
    font-size: 1.1rem;
  }

  .brand-slogan {
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .main-content {
    padding: 12px 10px 32px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .stat-card {
    padding: 10px 10px;
    gap: 8px;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .stat-label {
    font-size: 0.68rem;
    line-height: 1.15;
  }

  .toolbar-card {
    padding: 12px 10px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
  }

  .section-meta-bar {
    margin-bottom: 10px;
  }

  .results-heading {
    font-size: 0.98rem;
  }

  .results-count-tag {
    font-size: 0.74rem;
  }

  /* Bottom-sheet Presentation for Modals on Mobile Phones */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    max-width: 100%;
    width: 100%;
    max-height: calc(100dvh - 12px);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    margin: 0;
    transform: translateY(100%);
    box-shadow: 0 -10px 35px rgba(15, 22, 82, 0.3);
  }

  .modal-overlay.active .modal-card {
    transform: translateY(0);
  }

  .modal-header {
    padding: 14px 16px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
  }

  .modal-title {
    font-size: 1.02rem;
  }

  .modal-body {
    padding: 16px 14px;
    gap: 14px;
  }

  .modal-footer {
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-footer .btn {
    width: 100%;
    min-height: 46px;
    font-size: 0.92rem;
  }

  .dropzone-area {
    padding: 16px 12px;
    gap: 6px;
  }

  .dropzone-icon {
    font-size: 1.8rem;
  }

  .dropzone-text {
    font-size: 0.88rem;
  }

  .dropzone-subtext {
    font-size: 0.72rem;
  }

  .preview-modal-card {
    height: calc(100dvh - 12px);
    max-height: calc(100dvh - 12px);
  }

  .preview-modal-card .modal-header {
    gap: 8px;
  }

  .preview-modal-card .modal-title {
    font-size: 0.9rem;
  }

  .toast-container {
    left: 10px;
    right: 10px;
    bottom: 12px;
  }

  .toast {
    min-width: unset;
    width: 100%;
    font-size: 0.84rem;
    padding: 10px 14px;
  }
}
