:root {
  --bg: #eef3ff;
  --surface: #ffffff;
  --surface-2: #f6f9ff;
  --line: #d7e2fb;
  --text: #17213f;
  --muted: #627096;
  --primary: #4467ff;
  --primary-2: #6f4dff;
  --ok: #158a52;
  --warn: #c33258;
  --shadow: 0 20px 50px rgba(26, 49, 109, 0.12);
  --shadow-soft: 0 10px 24px rgba(26, 49, 109, 0.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 5% 10%, #dce7ff 0%, transparent 32%),
    radial-gradient(circle at 95% 0%, #e9e1ff 0%, transparent 28%),
    var(--bg);
}
body.modal-open { overflow: hidden; }
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at 0% 0%, rgba(107, 130, 255, 0.46) 0%, transparent 42%),
    radial-gradient(circle at 100% 0%, rgba(179, 112, 255, 0.35) 0%, transparent 38%),
    linear-gradient(140deg, #e8eeff 0%, #f5f9ff 48%, #eaf3ff 100%);
}
.login-card {
  width: min(760px, 100%);
  padding: 1.8rem;
  border: 1px solid #cfddff;
  border-radius: 24px;
  box-shadow: 0 30px 70px rgba(24, 48, 114, 0.18);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(248, 252, 255, 0.93) 100%);
}
.login-card h2 {
  margin: .35rem 0 .2rem 0;
  font-size: 1.5rem;
}
.login-card > .muted {
  margin: 0 0 .9rem 0;
}
.login-brand h1 {
  margin: 0;
  font-size: 1.9rem;
  letter-spacing: .02em;
}
.login-brand .muted {
  display: block;
  margin-top: .15rem;
}
.login-logo {
  width: min(560px, 100%);
  max-height: 180px;
  object-fit: contain;
  display: block;
  margin: 0 auto .8rem auto;
}
#loginView .login-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .8rem;
  align-items: end;
}
#loginView .login-fields label {
  font-size: .9rem;
}
#loginView .login-fields input {
  min-height: 42px;
  border-radius: 12px;
  border-color: #c1d3f4;
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8);
}
#loginView .login-submit {
  min-height: 42px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: .01em;
}
@media (max-width: 700px) {
  #loginView .login-fields {
    grid-template-columns: 1fr;
  }
  .login-card {
    padding: 1.15rem;
  }
}
.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #111a35 0%, #17285c 56%, #1d3777 100%);
  color: #fff;
  padding: 1.25rem 1rem;
  border-right: 1px solid #2a3f7f;
  box-shadow: inset -1px 0 0 rgba(255,255,255,.06);
}
.sidebar h1 { margin: 0; font-size: 1.35rem; }
.sidebar .muted { color: #bdcaf2; }
nav { margin-top: 1rem; display: grid; gap: .45rem; }
.nav-btn {
  text-align: left;
  border: 1px solid #2f4380;
  background: rgba(255,255,255,.04);
  color: #e2e8ff;
  border-radius: 12px;
  padding: .58rem .7rem;
  cursor: pointer;
  transition: .2s ease;
}
.nav-btn:hover { transform: translateX(2px); border-color: #5b77c7; }
.nav-btn.active { background: linear-gradient(120deg, var(--primary), var(--primary-2)); border-color: transparent; color: #fff; }
.content { padding: 1rem; display: grid; gap: 1rem; }
.card {
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: var(--shadow-soft);
}
.topbar { display: flex; justify-content: space-between; align-items: center; gap: .8rem; }
.row { display: flex; gap: .55rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
label { display: grid; gap: .25rem; font-size: .87rem; color: #4b5a81; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  border: 1px solid #cdd8ee;
  border-radius: 9px;
  padding: .45rem .55rem;
  min-width: 120px;
  background: #fff;
}
textarea { min-height: 90px; }
button {
  border: 1px solid var(--primary);
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  color: #fff;
  border-radius: 12px;
  padding: .46rem .75rem;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(68, 103, 255, .22);
  transition: transform .12s ease, box-shadow .2s ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 11px 22px rgba(68, 103, 255, .28); }
button.ghost {
  background: #fff;
  color: var(--primary);
  box-shadow: none;
}
button.danger {
  background: #fff1f4;
  color: #b4234d;
  border-color: #e8a5ba;
  box-shadow: none;
}
.tab { display: none; }
.tab.active { display: block; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .7rem; }
.metric {
  background: linear-gradient(180deg, #f8faff 0%, #edf3ff 100%);
  border: 1px solid #d7e2ff;
  border-radius: 14px;
  padding: .75rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
}
.metric .v { font-size: 1.25rem; font-weight: 700; }
.metric .k { color: var(--muted); font-size: .82rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
th, td { text-align: left; padding: .56rem; border-bottom: 1px solid #edf1f9; font-size: .9rem; }
th { color: #4f5f89; }
.status.ok { color: var(--ok); font-weight: 600; }
.status.warn { color: var(--warn); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .7rem; }
.calendar-grid {
  display: grid;
  gap: .6rem;
}
.calendar-grid.day { grid-template-columns: 1fr; }
.calendar-grid.week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-grid.month { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-grid[data-view="day"] .cal-day { min-height: 220px; }
.calendar-grid[data-view="week"] .cal-day { min-height: 170px; }
.calendar-grid[data-view="month"] .cal-day { min-height: 110px; }
.cal-weekday {
  text-align: center;
  font-size: .8rem;
  color: #5a6892;
  font-weight: 700;
}
.cal-day {
  background: var(--surface-2);
  border: 1px solid #d5e0f8;
  border-radius: 12px;
  padding: .55rem;
  min-height: 150px;
}
.month-cell { min-height: 120px; }
.cal-day h4 {
  margin: 0 0 .35rem;
  font-size: .85rem;
  color: #3f4f7b;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.date-pill { font-size: .7rem; color: #6f7da6; }
.date-number {
  background: #e5ecff;
  border: 1px solid #cad8ff;
  border-radius: 999px;
  min-width: 56px;
  text-align: center;
  padding: 0 .45rem;
  font-size: .75rem;
  color: #304b9a;
}
.cal-session {
  background: #fff;
  border: 1px solid #dce6fb;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: .35rem .45rem;
  margin-bottom: .35rem;
  font-size: .78rem;
}
.cal-session.done { border-left-color: var(--ok); }
.cal-session.pending { border-left-color: var(--warn); }
pre {
  background: #0f1a35;
  color: #e7ecff;
  padding: .75rem;
  border-radius: 10px;
  min-height: 180px;
  overflow: auto;
}
.muted { color: var(--muted); }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 24, 54, 0.48);
  backdrop-filter: blur(3px);
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-card {
  width: min(960px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.signature-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .8rem;
  width: 100%;
}
.signature-preview-grid > div {
  min-width: 0;
  overflow: hidden;
}
.signature-preview-shell {
  width: 100%;
  max-width: 100%;
  height: 160px;
  max-height: 160px;
  border: 1px solid #d6e1fb;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}
.signature-preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
}
#signatureCanvas {
  width: 100%;
  max-width: 700px;
  height: 260px;
  border: 1px dashed #9fb2e8;
  border-radius: 12px;
  background: #fff;
  touch-action: none;
  display: block;
  margin-bottom: .75rem;
}
#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #182753;
  color: #fff;
  border: 1px solid #344e93;
  border-radius: 12px;
  padding: .62rem .74rem;
  box-shadow: var(--shadow);
  display: none;
  z-index: 1200;
}
.session-note-template {
  border: 1px solid #d4def7;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.note-section {
  padding: .75rem .9rem .85rem;
  border-top: 1px solid #e5ecff;
}
.note-section:first-child { border-top: 0; }
.note-section h4 {
  margin: 0 0 .55rem;
  padding: .34rem .55rem;
  background: #c83a2b;
  color: #fff;
  font-size: 1.04rem;
  border-radius: 6px;
}
.grid4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .6rem;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .32rem .75rem;
  margin-bottom: .45rem;
}
.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .93rem;
}
.session-note-template textarea { min-height: 72px; }
.modifier-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.modifier-pill {
  display: inline-flex;
  align-items: center;
  gap: .28rem;
  border: 1px solid #cbd8fb;
  border-radius: 999px;
  padding: .28rem .56rem;
  background: #f7f9ff;
  cursor: pointer;
}
.modifier-pill input[type='checkbox'] {
  margin: 0;
}
.rendered-note-template {
  display: grid;
  gap: .65rem;
}
.rendered-note-template section {
  border: 1px solid #dce5fb;
  border-left: 4px solid #c83a2b;
  border-radius: 10px;
  padding: .55rem .65rem;
  background: #fbfcff;
}
.rendered-note-template h5 {
  margin: 0 0 .35rem;
  color: #b53628;
  font-size: .95rem;
}
.rendered-note-template p {
  margin: .22rem 0;
  white-space: pre-wrap;
}
.rendered-note-template .mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .25rem .9rem;
}
#rdAdditionalRaw {
  margin-top: .45rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7f9ff;
  border: 1px solid #dce5fb;
  border-radius: 8px;
  padding: .45rem .6rem;
  max-height: 180px;
  overflow: auto;
}
@media (max-width: 1150px) {
  .app-shell { grid-template-columns: 1fr; }
  .metrics, .grid2, .grid4, .checkbox-grid { grid-template-columns: 1fr; }
  .calendar-grid.day { grid-template-columns: 1fr; }
  .calendar-grid.week,
  .calendar-grid.month {
    grid-template-columns: repeat(7, minmax(140px, 1fr));
    overflow-x: auto;
  }
}
@media (max-width: 760px) {
  .signature-preview-grid { grid-template-columns: 1fr; }
  .calendar-grid.week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-grid.month {
    grid-template-columns: repeat(7, minmax(120px, 1fr));
    overflow-x: auto;
  }
}
