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

:root {
  /* Refined neutral-first palette */
  --primary: #5b6dcd;
  --primary-dark: #4956b8;
  --primary-light: #eef0fb;
  --primary-soft: #f7f8fc;
  --accent: #8b7fd8;

  --bg: #fafbfd;
  --surface: #ffffff;
  --surface-soft: #f7f8fc;
  --border: #e8ebf2;
  --border-strong: #d4d9e4;

  --text: #1f2433;
  --text-muted: #6b7488;
  --text-light: #8a92a8;

  --success: #10a774;
  --success-soft: #e6f7f1;
  --warning: #d97a06;
  --warning-soft: #fff5e8;
  --danger: #d6463f;
  --danger-soft: #fdecec;

  --shadow-sm: 0 1px 2px rgba(20, 25, 50, 0.04);
  --shadow: 0 2px 8px rgba(20, 25, 50, 0.05), 0 1px 3px rgba(20, 25, 50, 0.04);
  --shadow-lg: 0 8px 24px rgba(20, 25, 50, 0.08);
  --shadow-xl: 0 16px 48px rgba(20, 25, 50, 0.12);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --sidebar-w: 248px;
}

html, body {
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { direction: rtl; }

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary-dark); }

button { font-family: inherit; cursor: pointer; }

/* ========== Layout: Sidebar + Main ========== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  padding: 4px 10px 16px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.sidebar-logo img {
  max-width: 100%;
  max-height: 60px;
  object-fit: contain;
}
.sidebar-logo .default-mark {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}
.sidebar-logo .default-mark .icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.customer-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.3;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}
.nav-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s;
}
.nav-item:hover {
  background: var(--surface-soft);
  color: var(--text);
  text-decoration: none;
}
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}
.nav-item .icon { font-size: 16px; opacity: 0.85; }

.sidebar-footer {
  padding: 12px 4px 4px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.user-info {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-info:hover { background: var(--surface-soft); }
.user-info .name { font-weight: 600; color: var(--text); font-size: 13px; }
.user-info .email { font-size: 11px; color: var(--text-light); }
.user-info .edit-hint { font-size: 11px; color: var(--primary); margin-top: 4px; opacity: 0.8; }

.logout-btn {
  margin-top: 6px;
  width: 100%;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s;
}
.logout-btn:hover { background: var(--danger-soft); border-color: var(--danger); }

.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* ========== Headings ========== */
.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.3px;
  color: var(--text);
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

/* ========== Cards ========== */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow); }
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text);
  letter-spacing: -0.2px;
}

/* ========== Forms ========== */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: #b8c0d4; }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 109, 205, 0.1);
}
.form-input:disabled { background: var(--surface-soft); color: var(--text-light); cursor: not-allowed; }
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ========== Buttons ========== */
.btn {
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  letter-spacing: -0.1px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(91, 109, 205, 0.3); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-soft); border-color: #b8c0d4; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #0d966b; }

.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-soft); color: var(--text); }

.btn-block { width: 100%; }
.btn-lg { padding: 12px 22px; font-size: 14.5px; }
.btn-sm { padding: 6px 10px; font-size: 12px; gap: 4px; }

/* Mobile menu toggle */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ========== Login page ========== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f0f2fa 0%, #e8e9f4 100%);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 40px 36px 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border);
}
.login-logo {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
  letter-spacing: -0.4px;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}
.login-customer-logo {
  text-align: center;
  margin-bottom: 18px;
}
.login-customer-logo img { max-width: 200px; max-height: 80px; object-fit: contain; }
.login-customer-name {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 14px;
  text-align: center;
  font-weight: 600;
}

/* ========== Tables ========== */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  background: var(--surface-soft);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.4px;
}
.table tr:hover td { background: var(--surface-soft); }

/* ========== Badges ========== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-user { background: #dbeafe; color: #1e40af; }
.badge-active { background: var(--success-soft); color: #065f46; }
.badge-inactive { background: var(--danger-soft); color: #991b1b; }
.badge-couple { background: #fce7f3; color: #9f1239; }

/* ========== Result fields ========== */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.result-field {
  background: var(--surface);
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}
.result-field:hover { border-color: var(--border-strong); }
.result-field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.result-label {
  font-size: 10.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.4px;
}
.copy-icon-btn {
  background: none; border: none; cursor: pointer; padding: 4px;
  border-radius: 5px; color: var(--text-light);
  display: inline-flex; align-items: center; transition: all 0.15s;
}
.copy-icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.copy-icon-btn.copied { color: var(--success); background: var(--success-soft); }
.copy-icon-btn svg { width: 14px; height: 14px; }
.copy-icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.result-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}
.result-value.empty { color: var(--text-light); font-style: italic; font-weight: 400; }

/* ========== Upload area ========== */
.upload-area {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 30px 20px;
  text-align: center;
  background: var(--surface-soft);
  cursor: pointer;
  transition: all 0.2s;
}
.upload-area:hover, .upload-area.drag-over {
  background: var(--primary-light);
  border-color: var(--primary);
}
.upload-area.has-image { padding: 12px; }
.upload-area .upload-icon-big {
  font-size: 36px;
  opacity: 0.7;
  margin-bottom: 8px;
}
.upload-area .upload-text {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}
.upload-area .upload-subtext {
  color: var(--text-muted);
  font-size: 12px;
}
.preview-img {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ========== Loading ========== */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 20px; color: var(--primary); font-weight: 600;
  font-size: 14px;
}

/* ========== Alerts ========== */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: #8b1c1c; border-color: #f5b8b8; }
.alert-success { background: var(--success-soft); color: #065f46; border-color: #a7eed1; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border-color: #c6cdef; }
.alert-warning { background: var(--warning-soft); color: #8a4d05; border-color: #f5d0a3; }

/* ========== Tabs ========== */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover:not(.active) { color: var(--text); }

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 25, 50, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px 30px;
  max-width: 500px; width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.2s;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  letter-spacing: -0.3px;
}
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px;
}

/* ========== Spouse cards ========== */
.spouse-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.spouse-card {
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.spouse-card.has-scan { border-color: var(--success); background: var(--success-soft); }
.spouse-card-title {
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

/* ========== Video ========== */
video {
  width: 100%;
  border-radius: var(--radius);
  max-height: 360px;
  background: #000;
}

/* ========== Footer ========== */
.app-footer {
  margin-top: auto;
  padding: 24px 16px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  background: transparent;
}
.app-footer a { color: var(--primary); font-weight: 600; }
.login-footer {
  text-align: center;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-light);
}
.login-footer a { color: var(--primary); font-weight: 600; }

/* ========== Logo upload area in settings ========== */
.logo-upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  background: var(--surface-soft);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 12px;
}
.logo-upload-zone:hover, .logo-upload-zone.drag-over {
  background: var(--primary-light);
  border-color: var(--primary);
}
.logo-upload-zone .icon { font-size: 32px; margin-bottom: 8px; opacity: 0.6; }
.logo-upload-zone .label { font-weight: 600; font-size: 13px; color: var(--text); }
.logo-upload-zone .hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.logo-preview {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); padding: 18px;
  border-radius: var(--radius); border: 1px solid var(--border);
  margin-bottom: 12px;
}
.logo-preview img { max-height: 80px; max-width: 280px; object-fit: contain; }

/* ========== Responsive: Tablet & Mobile ========== */
@media (max-width: 900px) {
  .main { padding: 24px 20px; }
  .form-row { grid-template-columns: 1fr; }
  .spouse-cards { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  :root { --sidebar-w: 260px; }

  .mobile-menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    z-index: 40;
    box-shadow: var(--shadow-xl);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

  .main {
    padding: 60px 16px 20px;
    max-width: 100%;
  }

  .page-title { font-size: 20px; }
  .page-subtitle { font-size: 13px; margin-bottom: 18px; }

  .card { padding: 18px 16px; border-radius: var(--radius); }

  .table th, .table td { padding: 8px 10px; font-size: 12px; }
  .table th { font-size: 10px; }

  .btn { font-size: 13px; padding: 9px 14px; }
  .btn-lg { font-size: 14px; padding: 11px 18px; }

  .modal { padding: 22px 18px; border-radius: var(--radius); }

  .upload-area { padding: 24px 14px; }
  .upload-area .upload-icon-big { font-size: 30px; }

  .result-grid { grid-template-columns: 1fr; }

  .login-card { padding: 28px 22px; border-radius: var(--radius-lg); }
  .login-logo { font-size: 19px; }
}

@media (max-width: 480px) {
  .main { padding: 56px 12px 16px; }
  .card { padding: 14px 12px; }
  .page-title { font-size: 18px; }
  .modal { padding: 18px 14px; }
  .table { font-size: 12px; }
  /* Make tables horizontally scrollable on tiny screens */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Print friendliness */
@media print {
  .sidebar, .mobile-menu-btn, .app-footer, .btn { display: none !important; }
  .main { padding: 0; }
}
