:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #cbd5df;
  --line-strong: #9aa9b8;
  --text: #1f2933;
  --muted: #5f6f7d;
  --accent: #1565c0;
  --accent-dark: #0d47a1;
  --success: #2f7d32;
  --success-soft: #dff1df;
  --warning: #ad6b00;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.08);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 320px;
}

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

button {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.66;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: 0;
}

.app-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.legal-links {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.legal-links a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.legal-links a:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

.status-message {
  min-height: 32px;
  max-width: 520px;
  padding: 7px 10px;
  color: var(--muted);
  text-align: right;
  overflow-wrap: anywhere;
}

.status-message.error {
  color: var(--danger);
}

.status-message.success {
  color: var(--success);
}

.tabbar {
  display: flex;
  gap: 0;
  padding: 0 14px;
  background: #f6f8fa;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab-button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.tab-button:hover {
  color: var(--text);
}

.tab-button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: #ffffff;
}

.hidden {
  display: none !important;
}

.tab-content {
  padding: 14px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(380px, 0.92fr) minmax(460px, 1.08fr);
  gap: 14px;
  align-items: start;
}

.clients-grid {
  grid-template-columns: minmax(430px, 0.95fr) minmax(420px, 1.05fr);
  align-items: stretch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px;
}

.dashboard-grid {
  display: grid;
  gap: 14px;
}

.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.dashboard-kpi {
  min-height: 128px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.dashboard-kpi-label,
.dashboard-kpi-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dashboard-kpi-value {
  color: var(--text);
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.dashboard-chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 14px;
}

.dashboard-chart-panel {
  min-width: 0;
}

.dashboard-data-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.dashboard-data-panel .panel-heading {
  min-height: 0;
  margin-bottom: 0;
}

.dashboard-data-actions {
  justify-content: flex-end;
}

.dashboard-chart {
  height: 260px;
  display: grid;
  grid-template-columns: repeat(12, minmax(18px, 1fr));
  gap: 7px;
  align-items: stretch;
}

.dashboard-bar-item {
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-rows: 28px 1fr 34px;
  gap: 6px;
}

.dashboard-bar-value,
.dashboard-bar-label {
  display: block;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dashboard-bar-value {
  align-self: end;
}

.dashboard-bar-label {
  color: #405264;
}

.dashboard-bar-track {
  min-height: 170px;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--line);
  background: #edf3f8;
}

.dashboard-bar {
  width: 100%;
  height: 0;
  background: var(--accent);
}

.sessions-chart .dashboard-bar {
  background: var(--warning);
}

.income-chart .dashboard-bar {
  background: var(--success);
}

.session-history-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.session-history-panel textarea {
  flex: 1;
  min-height: 150px;
}

.session-history-preview {
  flex: 1;
  min-height: 150px;
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--text);
  padding: 8px;
  line-height: 1.45;
  font-size: 13px;
}

.session-history-preview-line {
  min-height: 1.45em;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.history-file-link {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  min-height: auto;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
}

.history-file-link:hover {
  color: var(--accent-dark);
}

.panel-heading {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h2,
.panel-heading h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr);
  gap: 9px 12px;
  align-items: center;
}

.client-registration-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.client-identity-fields {
  align-content: start;
}

.client-history-field {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.client-history-field textarea {
  flex: 1;
  min-height: 122px;
}

.mini-button {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 12px;
}

label,
.inline-label {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

.inline-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-row select {
  min-width: 180px;
}

.checkbox-label input {
  width: auto;
  min-height: auto;
}

label span {
  display: block;
  margin-bottom: 4px;
}

.form-grid label {
  margin-bottom: 0;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--text);
  padding: 6px 8px;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

.payload-box {
  margin-top: 12px;
  background: var(--panel-soft);
  color: var(--muted);
}

.button-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.button-row.compact {
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 34px;
  border: 1px solid transparent;
  padding: 6px 12px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line-strong);
}

.danger-button {
  background: var(--danger);
  color: #ffffff;
}

.wide-action {
  width: 100%;
  margin: 12px 0;
}

.schedule-controls,
.appointment-controls {
  display: grid;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.schedule-controls {
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) minmax(150px, 1fr) auto;
}

.appointment-controls {
  grid-template-columns: minmax(190px, 1.2fr) minmax(140px, 0.8fr) minmax(280px, 1fr) minmax(150px, 0.7fr) auto auto;
}

.time-control {
  display: grid;
  grid-template-columns: 76px 92px 112px;
  gap: 8px;
  align-items: end;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line-strong);
  min-height: 34px;
  align-self: end;
}

.segment {
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--muted);
  font-weight: 700;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: #ffffff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  border: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.data-table th {
  background: #edf3f8;
  color: #203040;
  font-size: 13px;
  font-weight: 700;
}

.data-table tr.selected-row td {
  background: #e4effa;
}

.data-table td[data-context="client-due"] {
  cursor: pointer;
}

.data-table td[data-context="client-due"]:hover {
  background: #eef7ee;
}

.sub-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.professional-left-column,
.professional-right-column {
  display: grid;
  gap: 14px;
  align-content: start;
}

.compact-heading {
  min-height: 30px;
  margin-bottom: 10px;
}

.compact-heading h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.person-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.compact-table th,
.compact-table td {
  padding: 6px 8px;
}

.compact-table input {
  min-height: 30px;
  padding: 4px 6px;
}

.resource-listbox,
.file-listbox {
  display: grid;
  align-content: start;
  min-height: 220px;
  max-height: 32vh;
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  background: #ffffff;
}

.resource-list-item,
.file-list-item {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.file-list-item {
  display: grid;
  gap: 2px;
}

.resource-list-item:hover,
.resource-list-item.selected,
.file-list-item:hover,
.file-list-item.selected {
  background: #e4effa;
  color: var(--text);
}

.resource-list-item:last-child,
.file-list-item:last-child {
  border-bottom: 0;
}

.file-list-name {
  font-weight: 700;
}

.file-list-meta,
.selected-file-names {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.file-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-picker-row .secondary-button {
  flex: 0 0 auto;
}

.selected-file-names {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.empty-resource,
.empty-file {
  padding: 10px;
  color: var(--muted);
  font-style: italic;
}

.currency-code {
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0;
}

.empty-cell {
  color: var(--muted);
  font-style: italic;
}

.link-button {
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--accent);
  padding: 4px 9px;
  min-height: 28px;
  font-weight: 700;
}

.check-button {
  min-width: 74px;
  min-height: 30px;
  border: 1px solid var(--line-strong);
  padding: 4px 9px;
  font-weight: 800;
}

.check-button.in {
  background: var(--success-soft);
  color: var(--success);
  border-color: #83b982;
}

.check-button.out {
  background: #eeeeee;
  color: var(--muted);
}

.session-panel {
  max-width: 1120px;
}

body.session-active {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.session-active .app-shell {
  min-height: 0;
  height: 100vh;
  height: 100dvh;
}

body.session-active .tab-content {
  min-height: 0;
  overflow: auto;
  padding: 0;
}

body.session-active #sessionTab.active {
  height: 100%;
  min-height: 0;
}

body.session-active .session-panel {
  width: 100%;
  max-width: none;
  height: 100%;
  min-height: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}

.session-complete-action {
  margin: 0 0 14px;
}

.session-context {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.payment-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.payment-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.payment-strip strong {
  display: block;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.payment-toggle {
  min-width: 112px;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  padding: 6px 12px;
  font-weight: 800;
}

.payment-toggle.paid {
  background: var(--success-soft);
  color: var(--success);
  border-color: #83b982;
}

.payment-toggle.unpaid {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f2b8b5;
}

.session-notes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.session-left-column {
  display: grid;
  gap: 14px;
  min-height: 0;
}

.session-note-field {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.session-files-panel {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.session-file-listbox {
  flex: 1;
  min-height: 132px;
  max-height: none;
}

.checkbox-listbox {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  background: #ffffff;
}

.checkbox-listbox label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
}

.checkbox-listbox label:last-child {
  border-bottom: 0;
}

.checkbox-listbox input {
  width: auto;
  min-height: auto;
  margin-top: 2px;
}

body.session-active .session-notes {
  flex: 1;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

body.session-active .session-left-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(180px, 1fr);
}

body.session-active .session-notes label {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.session-active .session-notes textarea {
  flex: 1;
  min-height: 0;
  resize: none;
}

.status-grid {
  --status-large-height: 300px;
  --status-next-height: 150px;
  display: grid;
  grid-template-columns: var(--status-large-height) minmax(280px, 1fr) minmax(240px, 0.78fr);
  grid-template-rows: var(--status-next-height) var(--status-next-height) var(--status-large-height);
  grid-template-areas:
    "session current next"
    "session current ."
    ". waiting waiting-list";
  gap: 14px;
  align-items: start;
}

.status-tile,
.waiting-list-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  align-items: center;
  justify-items: center;
  text-align: center;
}

.session-tile {
  grid-area: session;
  width: var(--status-large-height);
  height: var(--status-large-height);
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.current-coupon-tile {
  grid-area: current;
  min-height: var(--status-large-height);
}

.next-coupon-tile {
  grid-area: next;
  min-height: var(--status-next-height);
}

.waiting-count-tile {
  grid-area: waiting;
  min-height: var(--status-large-height);
}

.waiting-list-panel {
  grid-area: waiting-list;
  min-height: var(--status-large-height);
}

.tile-label {
  align-self: end;
  color: var(--muted);
  font-weight: 800;
  font-size: 19px;
}

.current-coupon-tile strong,
.waiting-count-tile strong {
  align-self: start;
  font-size: clamp(64px, 10vw, 112px);
  line-height: 1;
  letter-spacing: 0;
}

.next-coupon-tile strong {
  align-self: start;
  font-size: clamp(44px, 7vw, 72px);
  line-height: 1;
  letter-spacing: 0;
}

.session-state {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 50%;
  border: 0;
  color: transparent;
  font-size: 0;
}

.session-state.off {
  background: #7b8794;
}

.session-state.on {
  background: var(--success);
}

.waiting-coupon-list {
  color: var(--text);
  font-size: clamp(22px, 3.5vw, 36px);
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 150px;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  box-shadow: 0 8px 24px rgb(16 24 40 / 0.18);
  padding: 6px;
}

.context-menu button {
  width: 100%;
  min-height: 32px;
  border: 0;
  font-weight: 800;
  text-align: left;
  padding: 7px 9px;
}

.context-menu #contextDeleteButton {
  background: var(--danger-soft);
  color: var(--danger);
}

.context-menu #contextPayOffButton {
  background: var(--success-soft);
  color: var(--success);
}

.context-menu #contextEditButton {
  background: #edf3f8;
  color: var(--accent);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(16 24 40 / 0.42);
}

.license-blocker {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(15 23 42 / 0.62);
}

.license-blocker-panel {
  width: min(520px, 100%);
  padding: 24px;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  box-shadow: 0 14px 40px rgb(15 23 42 / 0.24);
}

.license-blocker-panel h2 {
  margin: 0 0 10px;
  color: var(--danger);
  font-size: 22px;
  line-height: 1.25;
}

.license-blocker-panel p {
  margin: 0;
  color: var(--text);
  line-height: 1.5;
}

.modal-panel {
  width: min(520px, 100%);
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgb(16 24 40 / 0.24);
  padding: 16px;
}

.large-text-modal {
  width: min(900px, 100%);
  height: min(760px, calc(100vh - 36px));
  display: flex;
  flex-direction: column;
}

.large-textbox {
  flex: 1;
  min-height: 0;
  resize: none;
  font-size: 18px;
  line-height: 1.55;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

@media (max-width: 980px) {
  .two-column,
  .clients-grid,
  .dashboard-chart-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-kpi-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .appointment-controls,
  .schedule-controls {
    grid-template-columns: 1fr 1fr;
  }

  .time-control {
    grid-column: 1 / -1;
  }

  .status-grid {
    --status-large-height: 220px;
    --status-next-height: 110px;
    grid-template-columns: var(--status-large-height) minmax(180px, 1fr) minmax(130px, 0.65fr);
    grid-template-rows: var(--status-next-height) var(--status-next-height) var(--status-large-height);
  }
}

@media (max-width: 640px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .legal-links {
    flex-wrap: wrap;
  }

  .status-message {
    max-width: none;
    text-align: left;
    padding-left: 0;
  }

  .form-grid,
  .client-registration-grid,
  .dashboard-kpi-grid,
  .appointment-controls,
  .schedule-controls,
  .session-notes,
  .time-control,
  .person-controls {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .payment-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .status-grid {
    --status-large-height: min(72vw, 260px);
    --status-next-height: calc(var(--status-large-height) / 2);
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "session"
      "current"
      "next"
      "waiting"
      "waiting-list";
    justify-items: center;
  }

  .current-coupon-tile,
  .next-coupon-tile,
  .waiting-count-tile,
  .waiting-list-panel {
    width: 100%;
  }

  .dashboard-chart {
    height: 230px;
    gap: 5px;
  }

  .dashboard-bar-item {
    grid-template-rows: 28px 1fr 30px;
  }

  body.session-active .session-notes {
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .inline-label {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .checkbox-label {
    align-items: center;
    flex-direction: row;
  }
}
