:root {
  --bg: #f4f7fb;
  --bg-soft: #edf2f7;
  --white: #ffffff;
  --text: #152033;
  --text-soft: #6b7688;
  --border: #b2bfd2;
  --border-soft: #d8e0ec;
  --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: 20px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --transition: 0.25s ease;
  --sidebar-width: 250px;
}

* {
  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);
  font-size: 13px;
}

button,
input,
select,
textarea {
  font: inherit;
}

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,
.page-btn {
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.82rem;
  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,
.page-btn {
  background: #f5f7fb;
  color: var(--text);
  border: 1px solid #ced7e4;
}

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

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

.page-btn.active {
  background: #2f6fed;
  color: #fff;
  border-color: #2f6fed;
}

button:disabled,
.primary-btn:disabled,
.secondary-btn:disabled,
.danger-btn:disabled,
.ghost-btn:disabled,
.warning-btn:disabled,
.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.15);
}

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

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

.field input,
.field select,
.field textarea,
.schedule-inputs input,
.schedule-inputs select,
.schedule-row input,
.schedule-row select,
.section-box-field input,
.section-box-field select,
.section-box-field textarea,
.section-box-block textarea,
.saved-record-edit-grid input,
.saved-record-edit-grid select,
.saved-record-edit-grid textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  outline: none;
  transition: var(--transition);
  color: var(--text);
  font-size: 0.82rem;
  box-shadow: none;
}

.field textarea,
.schedule-inputs textarea,
.section-box-block textarea,
.saved-record-edit-grid textarea {
  resize: none;
  overflow: hidden;
  min-height: 42px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.schedule-inputs input:focus,
.schedule-inputs select:focus,
.schedule-row input:focus,
.schedule-row select:focus,
.section-box-field input:focus,
.section-box-field select:focus,
.section-box-field textarea:focus,
.section-box-block textarea:focus,
.saved-record-edit-grid input:focus,
.saved-record-edit-grid select:focus,
.saved-record-edit-grid textarea:focus {
  border-color: rgba(47, 111, 237, 0.7);
  box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.10);
}

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

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

.checkbox-inline input {
  width: auto;
}

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

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

.auth-card {
  width: min(960px, 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: 24px;
  overflow: hidden;
}

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

.auth-copy {
  padding: 34px;
  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.5rem, 4vw, 2.2rem);
  line-height: 1.15;
}

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

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

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

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

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

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

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

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

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

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

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

.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: 18px;
  position: relative;
  z-index: 1;
}

.content-section {
  display: none;
}

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

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

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

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

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

.compact-panel {
  padding: 12px;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.stat-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(205, 214, 226, 0.95);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-xs);
}

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

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

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

.records-list {
  display: grid;
  gap: 10px;
}

.record-card {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(205, 214, 226, 0.98);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-record-card {
  width: 100%;
}

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

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

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

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

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

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

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

.record-details-wrap {
  display: none;
  gap: 10px;
  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: 5px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.67rem;
  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-none { background: #f3f4f6; color: #4b5563; }

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

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

.entry-top-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.entry-toolbar-grid {
  grid-template-columns: minmax(200px, 300px) auto;
  align-items: end;
}

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

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

.patient-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  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: 8px;
  margin-bottom: 10px;
  padding-top: 4px;
}

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

.card-status {
  font-size: 0.74rem;
  color: var(--text-soft);
  margin-top: 3px;
  line-height: 1.4;
}

.patient-entry-topline {
  display: grid;
  gap: 10px;
}

.patient-entry-card.collapsed .patient-entry-body {
  display: none;
}

.patient-entry-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

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

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

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

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

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

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

.templates-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.exercise-row,
.section-box-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px;
  padding: 8px;
  background: #ffffff;
  border: 1px solid #d5dfec;
  border-radius: 10px;
}

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

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

.section-box-field {
  background: #ffffff;
  border: 1px solid #d5dfec;
  border-radius: 10px;
  padding: 8px;
}

.section-box-block textarea,
.section-box-field textarea,
.section-box-field input,
.section-box-field select {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.saved-record-edit-grid {
  gap: 8px;
}

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

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

.generated-copy-box {
  background: #ffffff;
  border: 1px solid #d5dfec;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

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

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

.filter-grid {
  display: grid;
  gap: 8px;
}

.filter-grid.six {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.pagination-wrap {
  margin-top: 14px;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.pagination-summary {
  color: var(--text-soft);
  font-size: 0.78rem;
}

.pagination-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.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: 20px;
  box-shadow: 0 26px 50px rgba(0, 0, 0, 0.18);
  padding: 22px 18px 18px;
  position: relative;
}

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

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

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

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

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

.detail-grid > div {
  background: #f8fbff;
  border: 1px solid #d7e1ee;
  border-radius: 10px;
  padding: 9px 10px;
  line-height: 1.45;
}

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

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

.detail-block p {
  color: var(--text-soft);
  line-height: 1.6;
  font-size: 0.8rem;
  background: #fbfdff;
  border: 1px solid #dbe5f1;
  border-radius: 10px;
  padding: 10px;
}

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

.detail-list li {
  background: #f8fbff;
  border: 1px solid #d7e1ee;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text-soft);
  line-height: 1.5;
  font-size: 0.78rem;
}

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

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

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

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

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

.role-hidden-note {
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-top: 3px;
}

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

@media (max-width: 1100px) {
  .login-only-card,
  .patient-layout-grid,
  .form-grid.four,
  .exercise-row,
  .section-box-row,
  .detail-grid,
  .management-grid,
  .saved-record-edit-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,
  .entry-toolbar-grid {
    grid-template-columns: 1fr;
  }
}

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

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

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

  .inline-action,
  .templates-grid,
  .filter-grid.six,
  .form-grid.six {
    grid-template-columns: 1fr;
  }

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

  .pagination-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}