:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #0f172a;
  --secondary-hover: #1e293b;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: var(--bg); color: var(--text); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-logo { width: 46px; height: 46px; object-fit: contain; }
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-subtitle { font-size: 13px; color: var(--muted); }
.topbar-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-badge { font-size: 14px; color: var(--muted); }
.page-shell { max-width: 1400px; margin: 0 auto; padding: 28px; }
.page-header { display: flex; justify-content: space-between; align-items: end; margin-bottom: 18px; }
.page-header h1 { margin: 0 0 4px 0; font-size: 28px; }
.page-subtitle { margin: 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.detail-card { max-width: 900px; }
.narrow-card { max-width: 520px; width: 100%; }
.center-panel, .login-page { min-height: calc(100vh - 180px); display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 430px; background: var(--surface); border: 1px solid var(--border); padding: 30px; border-radius: var(--radius); box-shadow: var(--shadow); }
.login-logo-wrap { text-align: center; margin-bottom: 16px; }
.login-logo { max-width: 180px; max-height: 84px; object-fit: contain; }
.login-title { text-align: center; margin: 0 0 6px 0; font-size: 28px; }
.login-subtitle { text-align: center; color: var(--muted); margin: 0 0 20px 0; }
.form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
input, select, button { font: inherit; }
input, select { width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; }
input:focus, select:focus { outline: none; border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.btn { border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-block; text-align: center; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: var(--secondary-hover); }
.btn-full { width: 100%; }
.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }
.alert-error, .error { background: var(--danger-bg); color: var(--danger-text); }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.muted { color: var(--muted); }
.login-help { margin-top: 16px; text-align: center; font-size: 13px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table thead th { text-align: left; padding: 12px 10px; background: var(--surface-2); color: var(--muted); border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tbody td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr:hover { background: #fafcff; }
.stack-form { display: grid; gap: 8px; min-width: 180px; }
.share-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; min-width: 260px; }
.share-field { display: flex; flex-direction: column; gap: 4px; min-width: 92px; }
.share-field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.share-button-wrap { min-width: auto; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 18px; }
.detail-grid strong { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.share-link-block { margin-top: 14px; }
.share-link-block label { margin-bottom: 6px; }
.page-actions { margin-top: 20px; }
.top-gap { margin-top: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-form { display: grid; grid-template-columns: 2fr 1fr auto; gap: 12px; align-items: end; }
.grid-form-button { min-width: 180px; }
.section-title { margin-top: 0; margin-bottom: 16px; font-size: 20px; }
.uid-cell { max-width: 320px; word-break: break-all; font-size: 12px; color: var(--muted); }
.grid-form-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.status-pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status-active { background: #dcfce7; color: #166534; }
.status-inactive { background: #e2e8f0; color: #475569; }
.password-reset-form { display: flex; gap: 8px; align-items: center; min-width: 220px; }
.password-reset-form input { min-width: 140px; }
@media (max-width: 1000px) {
  .grid-2, .grid-form, .grid-form-2 { grid-template-columns: 1fr; }
  .grid-form-button { min-width: auto; }
  }

/* Admin study table layout */
.admin-study-table {
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
}

.admin-study-table th,
.admin-study-table td {
  border-right: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: middle;
  padding: 12px 14px;
  white-space: nowrap;
}

.admin-study-table th:last-child,
.admin-study-table td:last-child {
  border-right: none;
}

.admin-study-table tbody tr:last-child td {
  border-bottom: none;
}

.admin-study-table td:nth-child(3),
.admin-study-table td:nth-child(6) {
  white-space: normal;
}

/* Assign doctor cell */
.assign-cell {
  min-width: 300px;
}

.assign-inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.assign-inline-form select {
  width: 200px;
  min-width: 200px;
}

.assign-inline-form .btn {
  min-width: 90px;
}

/* Small numeric cells */
.mini-input-cell {
  width: 90px;
  min-width: 90px;
}

.mini-input-cell input {
  width: 70px;
  min-width: 70px;
  padding: 8px 8px;
  text-align: center;
}

/* Share button cell */
.share-button-cell {
  width: 150px;
  min-width: 150px;
}

.share-button-cell .btn {
  min-width: 120px;
}

/* Filter bar */
.filter-form {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

@media (max-width: 1400px) {
  .admin-study-table {
    table-layout: fixed;
  }

  .admin-study-table th,
  .admin-study-table td {
    white-space: normal;
  }

  .assign-inline-form {
    flex-wrap: wrap;
  }
}

@media (max-width: 1000px) {
  .filter-form {
    grid-template-columns: 1fr;
  }
}

/* Assign section stays on one line */
.assign-cell {
  min-width: 270px;
}

.assign-inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.assign-inline-form select {
  width: 190px;
  min-width: 190px;
}

.assign-inline-form .btn {
  min-width: 90px;
}

/* Share section stays on one line */
.share-cell {
  min-width: 320px;
}

.share-inline-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: nowrap;
}

.mini-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.mini-field input {
  width: 70px;
  min-width: 70px;
  padding: 8px 10px;
}

.share-inline-form .btn {
  min-width: 120px;
}

/* Filter bar */
.filter-form {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

@media (max-width: 1400px) {
  .admin-study-table {
    table-layout: fixed;
  }

  .admin-study-table td,
  .admin-study-table th {
    white-space: normal;
  }

  .assign-inline-form,
  .share-inline-form {
    flex-wrap: wrap;
  }
}

@media (max-width: 1000px) {
  .filter-form {
    grid-template-columns: 1fr;
  }
}

.share-link-box {
  display: flex;
  gap: 12px;
  align-items: center;
}

.share-link-box input {
  flex: 1;
  padding: 10px 12px;
  font-family: monospace;
}

.copy-status {
  margin-top: 10px;
  color: #16a34a;
  font-weight: 600;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.pagination-info {
  color: #64748b;
  font-size: 0.875rem;
}

.pagination-controls {
  display: flex;
  gap: 0.4rem;
}

.pagination-controls .btn {
  padding: 6px 12px;
  font-size: 0.85rem;
}