/* ===== Design tokens ===== */
:root {
  --color-primary: #1E6F5C;
  --color-primary-hover: #175A4A;
  --color-primary-light: #E4F2EE;
  --color-secondary: #2D6CDF;
  --color-accent: #F2A93B;
  --color-bg: #F7F8FA;
  --color-surface: #FFFFFF;
  --color-surface-dark: #16221D;
  --color-border: #E2E5E9;
  --color-text: #1B1F23;
  --color-text-muted: #6B7280;
  --color-text-inverse: #F5F7F6;
  --color-success: #1E8E5A;
  --color-warning: #D98A1D;
  --color-danger: #D64545;
  --color-bg-hover: #EEF1F4;

  --shadow-sm: 0 1px 2px rgba(16, 24, 20, 0.06), 0 1px 3px rgba(16, 24, 20, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 20, 0.18), 0 4px 12px rgba(16, 24, 20, 0.12);

  --sidebar-width: 240px;
  --slot-height: 40px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  font-size: 14px;
  line-height: 20px;
}

h1, h2, h3, p { margin: 0; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ===== App layout ===== */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface-dark);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-inverse);
  font-weight: 600;
  font-size: 16px;
  padding: 8px 8px 24px;
  text-decoration: none;
}

.sidebar-logo:hover,
.sidebar-logo:visited,
.sidebar-logo:active {
  color: var(--color-text-inverse);
  text-decoration: none;
}

.sidebar-logo-mark { font-size: 20px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--color-text-inverse);
  opacity: 0.8;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
  background: var(--color-primary);
  color: #fff;
  opacity: 1;
}

.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-label { font-size: 14px; }

.sidebar-overlay {
  display: none;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
}

.topbar-title {
  font-size: 24px;
  font-weight: 600;
  line-height: 32px;
  flex: 1;
}

.hamburger-btn {
  display: none;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 6px;
  color: var(--color-text);
}
.hamburger-btn svg { width: 22px; height: 22px; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.section { max-width: 1200px; margin: 0 auto; }
.section[hidden] { display: none; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn:focus-visible {
  outline: 2px solid var(--color-secondary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  background: #A9C9C0;
  color: rgba(255,255,255,0.7);
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg-hover); }
.btn-secondary:disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.btn-danger:hover { background: #FBEAEA; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--color-bg-hover); }
.icon-btn svg { width: 16px; height: 16px; }

/* ===== View controls ===== */
.view-controls {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--color-bg-hover);
  border-radius: 8px;
  padding: 2px;
}

.segment {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.segment:hover { color: var(--color-text); }
.segment.active {
  background: #fff;
  color: var(--color-text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-label {
  font-size: 14px;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
}

/* ===== Calendar ===== */
.calendar-wrapper {
  margin-top: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.calendar-grid {
  display: grid;
  min-width: 100%;
}

.calendar-header-row {
  display: grid;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.grid-corner {
  background: var(--color-surface);
  position: sticky;
  left: 0;
  z-index: 4;
}

.col-header {
  padding: 12px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  border-left: 1px solid var(--color-border);
}

.col-header .col-header-num {
  font-size: 16px;
  color: var(--color-text);
  margin-top: 2px;
}

.col-header.is-today {
  color: var(--color-primary);
  background: var(--color-primary-light);
}
.col-header.is-today .col-header-num { color: var(--color-primary); }

.calendar-body-row {
  display: grid;
}

.time-gutter {
  position: sticky;
  left: 0;
  background: var(--color-surface);
  z-index: 2;
  border-right: 1px solid var(--color-border);
}

.gutter-slot {
  height: var(--slot-height);
  position: relative;
  font-size: 11px;
  color: var(--color-text-muted);
}

.gutter-slot .gutter-label {
  position: absolute;
  top: -7px;
  right: 8px;
  background: var(--color-surface);
  padding-left: 4px;
}

.day-col {
  position: relative;
  border-left: 1px solid var(--color-border);
}

.slot {
  height: var(--slot-height);
  border-bottom: 1px dashed var(--color-border);
  cursor: pointer;
  position: relative;
}
.slot:nth-child(2n) { border-bottom-style: solid; }

.slot:hover::after {
  content: '+';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  opacity: 0.6;
  font-size: 16px;
}
.slot:hover { background: var(--color-bg-hover); }

.booking-block {
  position: absolute;
  left: 4px;
  right: 4px;
  border-radius: 6px;
  padding: 4px 8px;
  overflow: hidden;
  cursor: pointer;
  border-left: 3px solid var(--color-primary);
  background: var(--color-primary-light);
  z-index: 1;
}
.booking-block:hover {
  filter: brightness(0.96);
  box-shadow: var(--shadow-sm);
}
.booking-block.selected {
  outline: 2px solid var(--color-secondary);
  outline-offset: -2px;
}

.booking-block.status-pending {
  background: #FDF1DC;
  border-left-color: var(--color-warning);
}
.booking-block.status-cancelled {
  background: #F5F5F5;
  border-left-color: var(--color-border);
  color: var(--color-text-muted);
}
.booking-block.status-cancelled .booking-time {
  text-decoration: line-through;
}

.booking-time {
  font-size: 12px;
  font-weight: 700;
  line-height: 14px;
}
.booking-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.booking-price {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 14px;
}

/* ===== Stub sections ===== */
.stub-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.stub {
  text-align: center;
  max-width: 360px;
}
.stub-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.stub-caption { font-size: 14px; color: var(--color-text-muted); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 18, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }

.modal {
  width: 480px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-title { font-size: 20px; font-weight: 600; line-height: 28px; }

.modal-close {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
}
.modal-close svg { width: 18px; height: 18px; }

.modal-badge-row { padding: 8px 24px 0; }
.modal-badge-row[hidden] { display: none; }

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-row {
  display: flex;
  gap: 16px;
}
.field-row .field { flex: 1; min-width: 0; }

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

.field label {
  font-size: 14px;
  color: var(--color-text);
}

.field input,
.field select,
.field textarea {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--color-surface);
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.15);
}

.field.has-error input,
.field.has-error select {
  border-color: var(--color-danger);
}

.field-error {
  font-size: 12px;
  color: var(--color-danger);
  min-height: 16px;
  display: none;
}
.field.has-error .field-error,
.field-error.visible { display: block; }

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

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 24px;
  gap: 12px;
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
}
.modal-footer-right {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

.modal-confirm .modal-body { padding-top: 4px; }

/* ===== Badge ===== */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  line-height: 14px;
  padding: 2px 8px;
  border-radius: 4px;
}
.badge-success { background: #DFF3E8; color: var(--color-success); }
.badge-warning { background: #FDF1DC; color: var(--color-warning); }
.badge-muted { background: #EEEEEE; color: var(--color-text-muted); }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--color-success);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.2s ease-out;
}
.toast.toast-danger { background: var(--color-danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Clients section ===== */
.clients-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.search-bar {
  position: relative;
  flex: 1;
  max-width: 360px;
}
.search-bar svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  pointer-events: none;
}
.search-bar input {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 12px 8px 36px;
  background: var(--color-surface);
}
.search-bar input:focus {
  outline: none;
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.15);
}

.client-count {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.client-list {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.client-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}
.client-row:last-child { border-bottom: none; }
.client-row:hover { background: var(--color-bg-hover); }

.client-row-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.client-name { font-size: 14px; font-weight: 600; }
.client-phone { font-size: 12px; color: var(--color-text-muted); }

.client-row-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.client-row-actions .icon-btn.danger { color: var(--color-danger); border-color: var(--color-danger); }
.client-row-actions .icon-btn.danger:hover { background: #FBEAEA; }

.empty-state {
  padding: 48px 16px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 14px;
}

/* Client detail modal */
.detail-section { margin-top: 4px; }
.detail-section + .detail-section { margin-top: 20px; }
.detail-section-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

.detail-field { margin-bottom: 12px; }
.detail-field:last-child { margin-bottom: 0; }
.detail-field-label { font-size: 12px; color: var(--color-text-muted); margin-bottom: 2px; }
.detail-field-value { font-size: 14px; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}
.history-item-main { flex: 1; min-width: 0; }
.history-item-date { font-size: 14px; font-weight: 600; }
.history-item-meta { font-size: 12px; color: var(--color-text-muted); }
.history-item-price { font-size: 14px; font-weight: 600; white-space: nowrap; }
.history-empty { font-size: 13px; color: var(--color-text-muted); }

/* ===== Payments / Tariffs section ===== */
.section-block { margin-bottom: 32px; }
.section-block:last-child { margin-bottom: 0; }

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading { font-size: 20px; font-weight: 600; line-height: 28px; }
.section-count { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; }

.panel-list {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--color-bg-hover); }

.list-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.list-row-title { font-size: 14px; font-weight: 600; }
.list-row-sub { font-size: 12px; color: var(--color-text-muted); }
.list-row-amount { font-size: 14px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }

.list-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.list-row-actions .icon-btn.danger { color: var(--color-danger); border-color: var(--color-danger); }
.list-row-actions .icon-btn.danger:hover { background: #FBEAEA; }

/* ===== Reports section ===== */
.reports-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.reports-period-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.report-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.report-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.report-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.report-card-title { font-size: 16px; font-weight: 600; }

.report-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.report-card-icon.occupancy { background: var(--color-primary-light); color: var(--color-primary); }
.report-card-icon.revenue { background: #EAF1FD; color: var(--color-secondary); }

.report-stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 40px;
  margin: 12px 0 2px;
}

.report-stat-caption {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 20px;
}

.report-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 120px;
  border-top: 1px solid var(--color-border);
  padding-top: 8px;
}

.report-chart-bar-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}

.report-chart-bar {
  width: 100%;
  max-width: 28px;
  border-radius: 4px 4px 0 0;
  background: var(--color-primary);
  min-height: 2px;
}
.report-chart-bar.revenue-bar { background: var(--color-secondary); }

.report-chart-label {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ===== Responsive ===== */
@media (max-width: 1279px) {
  .sidebar {
    width: 72px;
  }
  .sidebar-logo-text { display: none; }
  .nav-label { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .content { padding: 24px; }
  .modal { width: 90vw; }
  .report-cards { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .app { display: block; }
  .hamburger-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    width: 220px;
    z-index: 101;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar.open ~ .sidebar-overlay,
  .sidebar-overlay.visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15,20,18,0.4);
    z-index: 100;
  }
  .sidebar.open .sidebar-logo-text,
  .sidebar.open .nav-label { display: inline; }
  .sidebar.open .nav-item { justify-content: flex-start; padding: 0 12px; }

  .topbar { padding: 0 16px; gap: 12px; }
  .topbar-title { font-size: 18px; }
  .btn-primary span { display: none; }
  .content { padding: 16px; }

  .modal-overlay { align-items: flex-end; }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
  }

  .date-label { min-width: 0; }

  .clients-toolbar { flex-direction: column; align-items: stretch; }
  .search-bar { max-width: none; }

  .section-toolbar { flex-wrap: wrap; }
  .list-row { flex-wrap: wrap; }
  .list-row-actions { width: 100%; justify-content: flex-end; }
}
