:root {
  --md-primary: #6750A4;
  --md-on-primary: #FFFFFF;
  --md-primary-container: #EADDFF;
  --md-on-primary-container: #21005D;
  --md-secondary: #625B71;
  --md-secondary-container: #E8DEF8;
  --md-surface: #FFFBFE;
  --md-surface-variant: #E7E0EC;
  --md-on-surface: #1C1B1F;
  --md-on-surface-variant: #49454F;
  --md-outline: #79747E;
  --md-outline-variant: #CAC4D0;
  --md-background: #FFFBFE;
  --md-error: #B3261E;
  --md-error-container: #F9DEDC;
  --success: #1D6B2F;
  --success-container: #C5EFCA;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 28px;
  --shadow-1: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-2: 0 2px 6px rgba(0,0,0,.14), 0 1px 4px rgba(0,0,0,.10);
  --nav-h: 80px;
  --top-h: 64px;
}

[data-theme="dark"] {
  --md-primary: #D0BCFF;
  --md-on-primary: #381E72;
  --md-primary-container: #4F378B;
  --md-on-primary-container: #EADDFF;
  --md-secondary: #CCC2DC;
  --md-secondary-container: #4A4458;
  --md-surface: #1C1B1F;
  --md-surface-variant: #49454F;
  --md-on-surface: #E6E1E5;
  --md-on-surface-variant: #CAC4D0;
  --md-outline: #938F99;
  --md-outline-variant: #49454F;
  --md-background: #1C1B1F;
  --md-error: #F2B8B5;
  --md-error-container: #8C1D18;
  --success: #6EDA87;
  --success-container: #0A3F19;
}

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

html { font-size: 16px; }

body {
  font-family: 'Roboto', sans-serif;
  background: var(--md-background);
  color: var(--md-on-surface);
  min-height: 100dvh;
}

/* ── Typography ─────────────────────────────────────────── */
.title-large  { font-size: 22px; font-weight: 400; line-height: 28px; }
.title-medium { font-size: 16px; font-weight: 500; line-height: 24px; }
.title-small  { font-size: 14px; font-weight: 500; line-height: 20px; }
.body-large   { font-size: 16px; font-weight: 400; line-height: 24px; }
.body-medium  { font-size: 14px; font-weight: 400; line-height: 20px; }
.body-small   { font-size: 12px; font-weight: 400; line-height: 16px; }
.label-large  { font-size: 14px; font-weight: 500; line-height: 20px; }

/* ── Surface & Card ─────────────────────────────────────── */
.surface {
  background: var(--md-surface);
  border-radius: var(--radius-md);
}
.card {
  background: var(--md-surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-1);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-xl);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  padding: 10px 24px;
  transition: box-shadow .2s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { opacity: .85; }
.btn-filled {
  background: var(--md-primary);
  color: var(--md-on-primary);
}
.btn-filled:hover { box-shadow: var(--shadow-1); }
.btn-tonal {
  background: var(--md-secondary-container);
  color: var(--md-on-surface);
}
.btn-outlined {
  background: transparent;
  border: 1px solid var(--md-outline);
  color: var(--md-primary);
}
.btn-text {
  background: transparent;
  color: var(--md-primary);
  padding: 10px 12px;
}
.btn-icon {
  padding: 8px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--md-on-surface-variant);
  font-size: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-icon:hover { background: var(--md-surface-variant); }
.btn-danger {
  background: var(--md-error-container);
  color: var(--md-error);
}
.btn-sm { padding: 6px 16px; font-size: 13px; }

/* ── FAB ─────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: var(--shadow-2);
  z-index: 10;
  transition: box-shadow .2s;
}
.fab:hover { box-shadow: 0 4px 12px rgba(0,0,0,.2); }

/* ── Top App Bar ─────────────────────────────────────────── */
.top-bar {
  height: var(--top-h);
  background: var(--md-surface);
  display: flex;
  align-items: center;
  padding: 0 8px 0 16px;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-1);
}
.top-bar-title {
  flex: 1;
  font-size: 22px;
  font-weight: 400;
}

/* ── Bottom Navigation ───────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--md-surface);
  display: flex;
  align-items: center;
  border-top: 1px solid var(--md-outline-variant);
  z-index: 20;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0 16px;
  cursor: pointer;
  color: var(--md-on-surface-variant);
  text-decoration: none;
  font-size: 12px;
  border: none;
  background: none;
  font-family: inherit;
  transition: color .15s;
}
.nav-item .nav-icon {
  width: 64px;
  height: 32px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: background .15s;
}
.nav-item.active { color: var(--md-on-surface); }
.nav-item.active .nav-icon { background: var(--md-secondary-container); }

/* ── Page content ────────────────────────────────────────── */
.page-content {
  padding: 16px 16px calc(var(--nav-h) + 16px);
  max-width: 900px;
  margin: 0 auto;
}

/* ── Forms ───────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.field input:not([type="range"]),
.field select,
.field textarea {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-family: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.field input:not([type="range"]):focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--md-primary) 20%, transparent);
}
.field textarea { resize: vertical; min-height: 80px; }

/* ── Chip picker ─────────────────────────────────────────── */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface);
  color: var(--md-on-surface-variant);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  font-family: inherit;
}
.chip.selected {
  background: var(--md-secondary-container);
  border-color: var(--md-primary);
  color: var(--md-on-surface);
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--md-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 24px 16px 32px;
  position: relative;
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius-lg); padding: 24px; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 20px; font-weight: 500; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ── Calendar ────────────────────────────────────────────── */
.cal-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  margin-bottom: 12px;
}
.cal-header-title {
  flex: 1;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  padding: 0 4px;
}
/* Дропдаун выбора периода */
.cal-view-dropdown {
  position: relative;
}
.cal-view-trigger {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 10px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--md-on-surface);
  font-family: inherit;
  white-space: nowrap;
  transition: background .15s;
}
.cal-view-trigger:hover { background: var(--md-surface-variant); }
.cal-view-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 120px;
  background: var(--md-surface);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  z-index: 20;
  overflow: hidden;
}
.cal-view-menu.open { display: block; }
.cal-view-opt {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  color: var(--md-on-surface);
  text-align: left;
  transition: background .12s;
}
.cal-view-opt:hover { background: var(--md-surface-variant); }
.cal-view-opt.active { font-weight: 600; color: var(--md-primary); }
.cal-view-opt.active::after { content: '✓'; margin-left: auto; padding-left: 10px; }
.cal-grid-wrap {
  display: flex;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--md-surface);
}
.cal-time-col {
  width: 44px;
  flex-shrink: 0;
  border-right: 1px solid var(--md-outline-variant);
}
.cal-time-label {
  height: 60px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 4px 6px 0 0;
  font-size: 11px;
  color: var(--md-on-surface-variant);
}
.cal-time-label:first-child { height: 52px; }
.cal-days-wrap {
  flex: 1;
  display: flex;
  min-width: 0;
  overflow-x: auto;
}
.cal-day-col {
  flex: 1;
  min-width: 0;
  border-right: 1px solid var(--md-outline-variant);
  position: relative;
}
.cal-day-col:last-child { border-right: none; }
.cal-day-header {
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-bottom: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface-variant);
  position: sticky;
  top: 0;
  background: var(--md-surface);
  z-index: 2;
}
.cal-day-name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  opacity: .8;
}
.cal-day-num {
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.cal-day-header.is-today { color: var(--md-primary); }
.cal-day-header.is-today .cal-day-num {
  background: var(--md-primary);
  color: var(--md-on-primary);
  font-weight: 700;
}
.cal-day-col.is-today .cal-hour-lines {
  background: color-mix(in srgb, var(--md-primary) 4%, transparent);
}
.cal-hour-lines {
  position: relative;
}
.cal-hour-line {
  height: 60px;
  border-bottom: 1px solid var(--md-outline-variant);
  cursor: pointer;
}
.cal-hour-line:hover { background: color-mix(in srgb, var(--md-primary) 5%, transparent); }
.cal-events-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.cal-event {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
  overflow: hidden;
  cursor: pointer;
  pointer-events: all;
  line-height: 1.3;
}
.cal-event.type-client {
  background: #EEDDFF;
  border-left: 3px solid #6750A4;
  color: #21005D;
}
.cal-event.type-personal {
  background: #C8F5E0;
  border-left: 3px solid #1D6B2F;
  color: #0A3F19;
}
.cal-event.status-cancelled {
  background: var(--md-surface-variant);
  border-left: 3px solid var(--md-outline);
  color: var(--md-on-surface-variant);
  text-decoration: line-through;
}
[data-theme="dark"] .cal-event.type-client {
  background: #4A3566;
  border-left-color: #D0BCFF;
  color: #EADDFF;
}
[data-theme="dark"] .cal-event.type-personal {
  background: #1A3B24;
  border-left-color: #6EDA87;
  color: #C5EFCA;
}
.cal-event { cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; }
.cal-event:active { cursor: grabbing; }
.cal-resize-handle {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  touch-action: none;
  border-radius: 0 0 6px 6px;
  background: rgba(0,0,0,.18);
  opacity: 0;
  transition: opacity .15s;
}
.cal-event:hover .cal-resize-handle { opacity: 1; }
.cal-event.ev-pending { opacity: .75; outline: 2px dashed currentColor; outline-offset: -2px; }
.cal-event.ev-pending::after { content: '⏱'; font-size: 10px; position: absolute; top: 2px; right: 3px; }
.cal-event-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event-svc  { font-size: 11px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event-time { opacity: .8; }
.cal-now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--md-error);
  pointer-events: none;
  z-index: 3;
}
.cal-now-line::before {
  content: '';
  position: absolute;
  left: -4px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--md-error);
}
/* Кнопка «Сегодня» — плавающая таблетка */
.cal-today-float {
  display: none;
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
  padding: 8px 20px;
  border: none;
  border-radius: 20px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  z-index: 30;
  white-space: nowrap;
  transition: opacity .15s;
}
.cal-today-float:hover { opacity: .9; }

/* ── Lists & Tables ──────────────────────────────────────── */
.list-card {
  background: var(--md-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--md-outline-variant);
}
.list-item:last-child { border-bottom: none; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 500; }
.list-item-sub { font-size: 12px; color: var(--md-on-surface-variant); margin-top: 2px; }
.list-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ── Material symbol icon helper ─────────────────────────── */
.icon {
  font-family: 'Material Symbols Outlined';
  font-size: 24px;
  line-height: 1;
  font-weight: 400;
  font-style: normal;
  display: inline-flex;
  vertical-align: middle;
}

/* ── Badge ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}
.badge-primary {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}
.badge-success {
  background: var(--success-container);
  color: var(--success);
}
.badge-error {
  background: var(--md-error-container);
  color: var(--md-error);
}

/* ── Stats ───────────────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 20px;
}
.month-nav-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  color: var(--md-on-surface);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--md-surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.stat-label { font-size: 12px; color: var(--md-on-surface-variant); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 500; }

/* ── Bar chart ───────────────────────────────────────────── */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding: 0 4px;
  overflow-x: auto;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 28px;
}
.bar-fill {
  width: 100%;
  background: var(--md-primary);
  border-radius: 4px 4px 0 0;
  transition: height .3s;
  min-height: 2px;
}
.bar-label { font-size: 10px; color: var(--md-on-surface-variant); }
.bar-col { position: relative; }
.bar-tooltip {
  position: absolute;
  bottom: calc(100% - 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--md-surface-variant);
  color: var(--md-on-surface-variant);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  text-align: center;
}

/* ── Cost adjustment ─────────────────────────────────────── */
.cost-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.cost-input {
  width: 100px;
  font-size: 22px;
  font-weight: 500;
  text-align: center;
  border: none;
  border-bottom: 2px solid var(--md-outline-variant);
  background: transparent;
  color: var(--md-on-surface);
  font-family: inherit;
  outline: none;
  padding: 4px 2px;
}
.cost-input:focus { border-bottom-color: var(--md-primary); }
.cost-input::-webkit-outer-spin-button,
.cost-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.cost-input[type=number] { -moz-appearance: textfield; }
.cost-currency {
  font-size: 18px;
  color: var(--md-on-surface-variant);
  margin-left: -2px;
}
/* kept for privacy-mode selector below */
.cost-display {
  font-size: 22px;
  font-weight: 500;
  flex: 1;
  text-align: center;
}
.cost-adj-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.cost-adj-btn:hover { background: var(--md-surface-variant); }

/* ── Autocomplete ────────────────────────────────────────── */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--md-surface);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
}
.autocomplete-item:hover { background: var(--md-surface-variant); }

/* ── Responsive ──────────────────────────────────────────── */
@media (min-width: 640px) {
  .page-content { padding: 24px 24px calc(var(--nav-h) + 24px); }
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--md-on-surface-variant);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; display: block; }

/* ── Offline banner ─────────────────────────────────────── */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: #B3261E;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
}

/* ── Duration slider ────────────────────────────────────── */
.duration-slider {
  width: calc(100% - 16px);
  margin: 8px 8px 4px;
  accent-color: var(--md-primary);
  cursor: pointer;
}
.duration-label {
  font-size: 13px;
  color: var(--md-on-surface-variant);
  margin-top: 2px;
}

/* ── Privacy mode ───────────────────────────────────────── */
.stat-value,
.bar-chart,
.list-item-sub,
.cost-display {
  transition: filter .2s;
}
body.privacy-mode .stat-value,
body.privacy-mode .bar-chart,
body.privacy-mode .list-item-sub,
body.privacy-mode .cost-display,
body.privacy-mode .cost-input {
  filter: blur(6px);
  user-select: none;
}

/* ── Snackbar ────────────────────────────────────────────── */
.snackbar {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #313033;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 200;
  white-space: nowrap;
  max-width: 90vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.snackbar.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* ── Divider ─────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--md-outline-variant);
  margin: 12px 0;
}

/* ── Login page ──────────────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--md-surface);
  border-radius: var(--radius-xl);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-2);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .icon { font-size: 48px; color: var(--md-primary); }
.login-logo h1 { font-size: 22px; font-weight: 500; margin-top: 8px; }
