:root {
  --bg: #f4f7fb;
  --bg-soft: #edf2f7;
  --white: #ffffff;
  --text: #152033;
  --text-soft: #6b7688;
  --border: #dbe3ef;
  --border-soft: #e8eef7;
  --primary: #2f6fed;
  --sidebar: #0f172a;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #b45309;
  --shadow-xs: 0 4px 10px rgba(15, 23, 42, 0.03);
  --shadow-sm: 0 10px 24px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 18px 36px rgba(15, 23, 42, 0.07);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --transition: 0.25s ease;
  --sidebar-width: 260px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: "Poppins", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(47, 111, 237, 0.08), transparent 30%),
    radial-gradient(circle at bottom right, rgba(22, 163, 74, 0.05), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
  border-color: #8DB0F5;
  box-shadow: 0 0 0 3px rgba(234, 240, 253, 1);
}

button {
  cursor: pointer;
  border: none;
}

.hidden {
  display: none !important;
}

.full-width {
  width: 100%;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.warning-btn,
.restore-btn {
  border-radius: 999px;
  padding: 10px 15px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: var(--transition);
}

.primary-btn {
  background: linear-gradient(180deg, #3e7bfa 0%, #2f6fed 100%);
  color: var(--white);
  box-shadow: 0 10px 20px rgba(47, 111, 237, 0.18);
}

.primary-btn:hover {
  transform: translateY(-1px);
}

.secondary-btn {
  background: #edf3ff;
  color: var(--primary);
}

.danger-btn {
  background: #fff1f1;
  color: var(--danger);
}

.ghost-btn {
  background: #f5f7fb;
  color: var(--text);
}

.warning-btn {
  background: #fff7ed;
  color: var(--warning);
}

.restore-btn {
  background: #eefbf4;
  color: var(--success);
}

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

.field label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  outline: none;
  transition: var(--transition);
  color: var(--text);
  font-size: 0.92rem;
}

.field textarea {
  resize: vertical;
  min-height: 64px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(47, 111, 237, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.10);
}

.compact-field textarea {
  min-height: 58px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.checkbox-inline input {
  width: auto;
}

.inline-action {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.auth-card {
  width: min(980px, 100%);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(219, 227, 239, 0.9);
  box-shadow: var(--shadow-md);
  border-radius: 26px;
  overflow: hidden;
}

.login-only-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-copy {
  padding: 40px;
  background:
    linear-gradient(135deg, rgba(47, 111, 237, 0.05), rgba(22, 163, 74, 0.03)),
    #f8fbff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.auth-copy h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.15;
}

.auth-panel {
  background: var(--white);
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-form {
  display: flex;
  gap: 14px;
  flex-direction: column;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--white);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  z-index: 1000;
  overflow-y: auto;
}

.sidebar h2 {
  font-size: 1.22rem;
  line-height: 1.35;
  word-break: break-word;
}

.user-card-sidebar {
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 16px;
  padding: 14px;
}

.user-card-sidebar h3 {
  font-size: 1rem;
  margin-bottom: 4px;
  word-break: break-word;
}

.user-card-sidebar p {
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.9rem;
  word-break: break-word;
}

.est-clock {
  margin-top: 8px;
  color: #bfdbfe !important;
  font-size: 0.83rem !important;
}

.sidebar-nav {
  display: grid;
  gap: 10px;
}

.nav-link {
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 600;
  width: 100%;
  display: block;
  pointer-events: auto;
  position: relative;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
}

.nav-link.active {
  background: var(--white);
  color: var(--sidebar);
  box-shadow: var(--shadow-xs);
}

.logout-btn {
  margin-top: auto;
  width: 100%;
}

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 22px;
  position: relative;
  z-index: 1;
}

.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

.section-top {
  margin-bottom: 16px;
}

.compact-section-top {
  margin-bottom: 12px;
}

.section-top h1 {
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  line-height: 1.2;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 227, 239, 0.9);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.compact-panel {
  padding: 14px;
}

.management-panel {
  margin-bottom: 12px;
}

.management-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  background: linear-gradient(180deg, #fcfdff 0%, #f6faff 100%);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 14px 16px;
}

.management-toggle-text strong {
  display: block;
  font-size: 0.98rem;
  color: var(--text);
}

.management-toggle-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #edf3ff;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  flex-shrink: 0;
}

.management-collapsible {
  margin-top: 12px;
}

.management-stack {
  display: grid;
  gap: 14px;
}

.management-group {
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 14px;
  background: linear-gradient(180deg, #fcfdff 0%, #f8fbff 100%);
}

.management-group-danger {
  background: linear-gradient(180deg, #fffdfd 0%, #fff7f7 100%);
}

.management-group-header {
  margin-bottom: 10px;
}

.management-group-header h4 {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
}

.management-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.management-checkbox-full {
  grid-column: 1 / -1;
}

.section-headline {
  margin-bottom: 14px;
}

.compact-headline {
  margin-bottom: 10px;
}

.section-headline h3,
.section-headline h4 {
  font-size: 0.98rem;
  margin-bottom: 4px;
  font-weight: 700;
}

.section-headline p {
  color: var(--text-soft);
  line-height: 1.5;
  font-size: 0.86rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(219, 227, 239, 0.9);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow-xs);
}

.stat-card p {
  color: var(--text-soft);
  margin-bottom: 8px;
  font-size: 0.84rem;
  font-weight: 500;
}

.stat-card h3 {
  font-size: 1.32rem;
  line-height: 1.2;
}

.records-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.record-card {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(219, 227, 239, 0.95);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.premium-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(250, 252, 255, 1) 100%);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.06);
}

.record-card-topline {
  display: grid;
  gap: 12px;
}

.record-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 0;
}

.record-top h4 {
  font-size: 1.02rem;
  line-height: 1.35;
  margin-bottom: 4px;
}

.record-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.details-toggle-btn {
  align-self: flex-start;
  background: #f5f8ff;
  color: var(--primary);
  border: 1px solid #d9e6ff;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 0.86rem;
}

.details-toggle-btn:hover {
  background: #edf4ff;
}

.record-details-wrap {
  display: none;
  gap: 14px;
  flex-direction: column;
}

.record-details-wrap.open {
  display: flex;
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #edf4ff;
  color: var(--primary);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-completed {
  background: #ecfdf3;
  color: #15803d;
}

.status-missed {
  background: #fff1f2;
  color: #be123c;
}

.status-cancelled {
  background: #fff7ed;
  color: #c2410c;
}

.status-rescheduled {
  background: #eff6ff;
  color: #1d4ed8;
}

.status-incomplete {
  background: #f5f3ff;
  color: #6d28d9;
}

.status-none {
  background: #f3f4f6;
  color: #4b5563;
}

.record-actions,
.patient-card-actions,
.modal-actions,
.history-actions {
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.record-actions button,
.history-actions button {
  flex: 1 1 160px;
}

.entry-top-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.single-top-grid {
  grid-template-columns: minmax(220px, 320px);
}

.compact-top-select {
  margin-bottom: 10px;
}

.download-all-wrap {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.patient-card {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #ffffff;
  padding: 14px;
  position: relative;
  box-shadow: var(--shadow-xs);
}

.patient-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 14px;
  right: 14px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2f6fed 0%, #7da8ff 100%);
}

.patient-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  padding-top: 4px;
}

.patient-card-header h3 {
  font-size: 1.05rem;
}

.card-status {
  font-size: 0.82rem;
  color: var(--text-soft);
  margin-top: 4px;
  line-height: 1.45;
}

.patient-layout-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 12px;
  align-items: start;
}

.patient-main-column,
.patient-side-column {
  display: grid;
  gap: 12px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.form-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.exercise-block,
.schedule-block,
.note-block,
.concerns-block,
.status-block {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(180deg, #fcfdff 0%, #f8fbff 100%);
}

.exercise-list,
.schedule-list {
  display: grid;
  gap: 8px;
}

.exercise-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 8px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid #e6edf7;
  border-radius: 12px;
}

.exercise-row .field textarea {
  min-height: 52px;
}

.schedule-list.two-column-schedule {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.schedule-row.schedule-card {
  display: block;
  padding: 10px;
  background: #ffffff;
  border: 1px solid #e6edf7;
  border-radius: 12px;
}

.schedule-number {
  display: block;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.schedule-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.schedule-inputs select,
.schedule-row select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.92rem;
}

.empty-state {
  background: rgba(255, 255, 255, 0.95);
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 20px;
  color: var(--text-soft);
  line-height: 1.7;
}

.filters-panel {
  margin-bottom: 14px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 2000;
}

.modal-card {
  width: min(1000px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--white);
  border-radius: 22px;
  box-shadow: 0 26px 50px rgba(0, 0, 0, 0.18);
  padding: 26px 20px 20px;
  position: relative;
}

.large-modal-card {
  width: min(1080px, 100%);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #eef2ff;
  color: var(--primary);
  font-size: 1.35rem;
  line-height: 1;
}

.modal-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 8px;
  padding-right: 62px;
}

.details-muted {
  margin-bottom: 14px;
}

.history-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  margin-top: 14px;
  background: #fbfdff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 0;
  font-size: 0.92rem;
}

.detail-grid > div {
  background: #f8fbff;
  border: 1px solid #e4ecf8;
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.5;
}

.detail-block {
  margin-top: 0;
}

.detail-block strong {
  display: block;
  margin-bottom: 7px;
  font-size: 0.92rem;
}

.detail-block p {
  color: var(--text-soft);
  line-height: 1.65;
  font-size: 0.92rem;
  background: #fbfdff;
  border: 1px solid #e7eef8;
  border-radius: 12px;
  padding: 12px;
}

.detail-list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.detail-list li {
  background: #f8fbff;
  border: 1px solid #e4ecf8;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text-soft);
  line-height: 1.6;
  font-size: 0.9rem;
}

.detail-list li span {
  display: block;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}

.detail-list li p {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

.history-meta,
.recycle-meta {
  color: var(--text-soft);
  margin-top: 5px;
  font-size: 0.86rem;
  line-height: 1.5;
}

.recycle-warning {
  color: var(--warning);
  font-weight: 600;
}

.version-badge {
  background: #eefbf4;
  color: var(--success);
}

#recentEntries .record-card {
  min-height: 100%;
}

@media (max-width: 1100px) {
  .login-only-card,
  .patient-layout-grid,
  .form-grid.four,
  .exercise-row,
  .detail-grid,
  .filter-grid,
  .management-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    min-height: auto;
  }

  .main-content {
    margin-left: 0;
  }

  .schedule-list.two-column-schedule,
  .schedule-inputs {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .auth-copy,
  .auth-panel,
  .panel,
  .patient-card,
  .modal-card,
  .record-card {
    padding: 14px;
  }

  .record-actions,
  .patient-card-actions,
  .modal-actions,
  .history-actions {
    flex-direction: column;
  }

  .record-actions button,
  .patient-card-actions button,
  .modal-actions button,
  .history-actions button {
    width: 100%;
    flex: 1 1 100%;
  }

  .inline-action {
    grid-template-columns: 1fr;
  }

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