:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --border: #475569;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --accent-muted: rgba(20, 184, 166, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #22c55e;
  --urgent: #f97316;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Vazirmatn', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app { min-height: 100vh; min-height: 100dvh; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button { cursor: pointer; border: none; background: none; }

input, select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.625rem 0.875rem;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

textarea { resize: vertical; min-height: 80px; }

select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 0.75rem center; padding-left: 2rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0d9488);
  color: white;
  box-shadow: 0 2px 12px rgba(20, 184, 166, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(20, 184, 166, 0.45); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-ghost {
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-input); border-radius: var(--radius-sm); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Login */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(20, 184, 166, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.08) 0%, transparent 40%),
    var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-logo p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.25rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* Layout */
.app-layout { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}

.header-inner {
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.header-brand h1 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.app-main { flex: 1; padding: 1rem; overflow: hidden; display: flex; flex-direction: column; }

/* Stats bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
}

.stat-card .label { font-size: 0.75rem; color: var(--text-secondary); }
.stat-card .value { font-size: 1.375rem; font-weight: 700; margin-top: 0.125rem; }
.stat-card.urgent .value { color: var(--urgent); }
.stat-card.success .value { color: var(--success); }
.stat-card.accent .value { color: var(--accent); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-box input { padding-right: 2.5rem; }
.search-box svg {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  width: 18px;
  height: 18px;
}

/* Table */
.table-wrapper {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  min-width: 1200px;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #0f766e;
  color: white;
  font-weight: 600;
  padding: 0.75rem 0.625rem;
  text-align: right;
  white-space: nowrap;
  z-index: 2;
  border-left: 1px solid rgba(255,255,255,0.1);
}

.data-table td {
  padding: 0.625rem;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid rgba(71, 85, 105, 0.3);
  vertical-align: middle;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tbody tr { transition: background 0.15s; cursor: pointer; }
.data-table tbody tr:hover { background: rgba(20, 184, 166, 0.08); }
.data-table tbody tr:nth-child(even) { background: rgba(30, 41, 59, 0.5); }
.data-table tbody tr:nth-child(even):hover { background: rgba(20, 184, 166, 0.08); }

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-high { background: rgba(249, 115, 22, 0.2); color: #fb923c; }
.badge-normal { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.badge-yes { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.badge-no { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0;
  flex-wrap: wrap;
}

.pagination span { color: var(--text-secondary); font-size: 0.875rem; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  animation: fadeIn 0.2s;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease-out;
  margin: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal-header h2 { font-size: 1.125rem; font-weight: 600; }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--bg-secondary);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Form sections */
.form-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.form-grid-full { grid-column: 1 / -1; }

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  padding: 0.375rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  user-select: none;
}

.checkbox-item:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.checkbox-item input { width: auto; accent-color: var(--accent); }

.followup-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.followup-item label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  display: block;
}

/* Date picker overrides */
.rmdp-wrapper { direction: rtl; }
.rmdp-container { width: 100%; }
.rmdp-input {
  background: var(--bg-input) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  padding: 0.625rem 0.875rem !important;
  width: 100% !important;
  font-family: var(--font) !important;
}
.rmdp-calendar { background: var(--bg-secondary) !important; border: 1px solid var(--border) !important; }
.rmdp-day rmdp-selected span { background: var(--accent) !important; }
.rmdp-time-picker { direction: ltr; }

.datetime-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

.time-input {
  width: 100px !important;
  text-align: center;
  direction: ltr;
}

.loading-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state svg { width: 64px; height: 64px; margin-bottom: 1rem; opacity: 0.4; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .header-brand h1 { font-size: 1rem; }
  .btn span.hide-mobile { display: none; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-height: calc(100dvh - 1rem); margin: 0.5rem; }
}

@media (display-mode: standalone) {
  .app-header { padding-top: max(0.75rem, env(safe-area-inset-top)); }
}
