/* ========================================================
   Сэрдог-Арур v2 — Global Styles
   ======================================================== */

/* Base reset */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: #1c1917;
  background: #fafaf9;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: "Georgia", "Times New Roman", serif; font-weight: 600; margin: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: #0f766e; text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, select { font-family: inherit; font-size: 14px; color: inherit; }

/* ========== TOP BAR ========== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e7e5e4;
}
.topbar-inner {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; }
.brand-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
  color: white;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-text h1 { font-size: 16px; line-height: 1.1; color: #1c1917; }
.brand-text p { font-size: 11px; color: #78716c; margin: 2px 0 0; }
@media (max-width: 720px) { .brand-text p { display: none; } }

.topnav { display: flex; gap: 2px; flex: 1; margin-left: 16px; }
.topnav-link {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 8px;
  color: #57534e; font-size: 13px; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.topnav-link:hover { background: #f5f5f4; color: #115e59; text-decoration: none; }
.topnav-link.active { background: #f0fdfa; color: #115e59; }
@media (max-width: 720px) { .topnav-link span { display: none; } }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  background: transparent; border: 1px solid transparent; color: #44403c;
  transition: background 0.15s;
}
.icon-btn:hover { background: #f5f5f4; }
.icon-btn.danger:hover { background: #fef2f2; color: #dc2626; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #115e59; color: white;
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-menu { position: relative; }
.dropdown {
  position: absolute; top: calc(100% + 4px); right: 0;
  min-width: 180px; background: white;
  border: 1px solid #e7e5e4; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  overflow: hidden; z-index: 40;
}
.dropdown-header {
  padding: 10px 14px; font-size: 13px; color: #1c1917; font-weight: 500;
  border-bottom: 1px solid #e7e5e4;
}
.dropdown-item {
  display: block; padding: 10px 14px; color: #1c1917; font-size: 13px;
}
.dropdown-item:hover { background: #f5f5f4; text-decoration: none; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 6px; border: 1px solid transparent;
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: #115e59; color: white; border-color: #115e59; }
.btn-primary:hover { background: #134e4a; border-color: #134e4a; text-decoration: none; color: white; }
.btn-secondary { background: white; color: #44403c; border-color: #d6d3d1; }
.btn-secondary:hover { background: #fafaf9; text-decoration: none; color: #44403c; }
.btn-danger { background: #dc2626; color: white; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: #44403c; border-color: transparent; }
.btn-ghost:hover { background: #f5f5f4; }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ========== DASHBOARD ========== */
.dashboard-inner, .admin-inner { max-width: 1200px; margin: 0 auto; padding: 24px 20px 40px; }
@media (max-width: 640px) { .dashboard-inner, .admin-inner { padding: 16px 12px 40px; } }

.page-head { margin-bottom: 24px; }
.page-title { font-size: 26px; color: #1c1917; }
.page-sub { color: #78716c; font-size: 13px; margin-top: 4px; }

.stat-grid {
  display: grid; gap: 12px; grid-template-columns: repeat(5, 1fr);
  margin-bottom: 18px;
}
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: white; border: 1px solid #e7e5e4; border-radius: 10px;
  padding: 16px;
}
.stat-card.loading .stat-value { color: #d6d3d1; }
.stat-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #78716c; font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 700; color: #115e59; font-family: Georgia, serif; margin-top: 6px; }
.stat-note { font-size: 11px; color: #a8a29e; margin-top: 2px; }
.stat-card.clickable { cursor: pointer; transition: all 0.15s; }
.stat-card.clickable:hover { border-color: #0f766e; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(15,118,110,0.08); }

.income-grid {
  display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr);
  margin-bottom: 24px;
}
@media (max-width: 700px) { .income-grid { grid-template-columns: 1fr; } }
.income-card {
  background: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
  color: white; padding: 18px 20px; border-radius: 10px;
}
.income-title { font-size: 12px; opacity: 0.8; font-weight: 500; }
.income-value { font-size: 26px; font-weight: 700; font-family: Georgia, serif; margin-top: 6px; }
.income-breakdown { font-size: 11px; opacity: 0.75; margin-top: 4px; }

.missed-box {
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px;
  padding: 14px 18px; margin-bottom: 18px;
}
.missed-title {
  color: #991b1b; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}
.missed-list { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.missed-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 20px; background: white;
  border: 1px solid #fecaca; font-size: 12px; color: #1c1917;
  cursor: pointer; transition: background 0.12s;
}
.missed-item:hover { background: #fef2f2; }

.card-section { background: white; border: 1px solid #e7e5e4; border-radius: 10px; padding: 20px; }
.section-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-title { font-size: 18px; color: #1c1917; }

.appt-list { display: grid; gap: 8px; margin-top: 10px; }
.appt-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid #e7e5e4; border-radius: 8px;
  background: #fafaf9; cursor: pointer; transition: all 0.12s;
}
.appt-item:hover { background: white; border-color: #0f766e; transform: translateX(2px); }
.appt-time {
  padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
  background: #fef3c7; color: #854d0e;
}
.appt-time.afternoon { background: #dbeafe; color: #1e40af; }
.appt-name { flex: 1; font-weight: 500; }
.appt-meta { font-size: 12px; color: #78716c; }
.appt-type { font-size: 10px; padding: 2px 6px; border-radius: 3px; background: #e7e5e4; color: #57534e; text-transform: uppercase; }
.appt-type.first { background: #dcfce7; color: #166534; }
.appt-type.return { background: #fef3c7; color: #854d0e; }

/* ========== LAYOUT (patients page) ========== */
.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar {
  width: 300px; flex-shrink: 0;
  border-right: 1px solid #e7e5e4; background: white;
  display: flex; flex-direction: column;
  position: sticky; top: 57px; height: calc(100vh - 57px); overflow: hidden;
}
.sidebar-search {
  padding: 12px; border-bottom: 1px solid #e7e5e4; position: relative;
}
.sidebar-search svg { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); color: #a8a29e; }
.sidebar-search input {
  width: 100%; padding: 8px 10px 8px 34px;
  border: 1px solid #d6d3d1; border-radius: 6px; background: white;
}
.sidebar-search input:focus { outline: none; border-color: #0f766e; box-shadow: 0 0 0 3px rgba(15,118,110,0.12); }
.sidebar-meta { padding: 8px 14px; font-size: 11px; color: #78716c; border-bottom: 1px solid #f5f5f4; }
.sidebar-list { flex: 1; overflow-y: auto; }
.sidebar-footer { padding: 12px; border-top: 1px solid #e7e5e4; background: #fafaf9; }

.patient-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; background: none; border: none;
  border-left: 2px solid transparent; text-align: left;
  border-bottom: 1px solid #f5f5f4;
  transition: background 0.12s, border-color 0.12s;
}
.patient-item:hover { background: #fafaf9; }
.patient-item.active { background: #f0fdfa; border-left-color: #0f766e; }
.patient-item-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: #e7e5e4; color: #57534e;
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.patient-item.active .patient-item-avatar { background: #0f766e; color: white; }
.patient-item-info { flex: 1; min-width: 0; }
.patient-item-name { font-size: 13px; font-weight: 500; color: #1c1917; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.patient-item-sub { font-size: 11px; color: #78716c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.patient-item-visits { font-size: 10px; padding: 2px 6px; background: #e7e5e4; border-radius: 10px; color: #57534e; flex-shrink: 0; }
.patient-item.active .patient-item-visits { background: #a7f3d0; color: #065f46; }
.empty-hint { padding: 20px 16px; text-align: center; color: #a8a29e; font-size: 13px; }

.backdrop {
  position: fixed; inset: 0; background: rgba(28,25,23,0.4);
  z-index: 20; display: none;
}
.main { flex: 1; min-width: 0; }

/* ========== EMPTY STATE ========== */
.empty-state {
  min-height: calc(100vh - 57px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; text-align: center;
}
.empty-icon {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, #0f766e 0%, #134e4a 100%);
  color: white;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(17,94,89,0.2);
  margin-bottom: 20px;
}
.empty-state h2 { font-size: 26px; color: #1c1917; }
.empty-state p { color: #78716c; margin: 8px 0 24px; }

/* ========== PATIENT VIEW ========== */
.patient-view { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }

.patient-header {
  background: white; border: 1px solid #e7e5e4; border-radius: 10px;
  padding: 18px 20px; margin-bottom: 20px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.card-no-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: #0f766e; font-weight: 600; }
.card-no { font-family: "SF Mono", Consolas, monospace; font-size: 14px; color: #57534e; margin-top: 2px; }
.patient-name { font-size: 22px; color: #1c1917; margin-top: 6px; }
.patient-meta { font-size: 13px; color: #78716c; margin: 4px 0 0; }

.patient-tabs {
  display: flex; gap: 2px; overflow-x: auto;
  border-bottom: 1px solid #e7e5e4; margin-bottom: 18px;
  scrollbar-width: thin;
}
.patient-tabs::-webkit-scrollbar { height: 3px; }
.patient-tabs::-webkit-scrollbar-thumb { background: #d6d3d1; border-radius: 3px; }
.ptab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; white-space: nowrap;
  background: none; border: none; border-bottom: 2px solid transparent;
  font-size: 13px; font-weight: 500; color: #78716c;
}
.ptab:hover { color: #44403c; }
.ptab.active { color: #115e59; border-bottom-color: #115e59; }

.patient-panel {
  background: white; border: 1px solid #e7e5e4; border-radius: 10px;
  padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  display: none;
}
.patient-panel.active { display: block; }
@media (max-width: 640px) { .patient-panel { padding: 18px; } }

/* ========== VISITS LIST ========== */
.visits-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.visits-list { display: flex; flex-direction: column; gap: 8px; }
.visit-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid #e7e5e4; border-radius: 8px;
  background: #fafaf9; cursor: pointer; transition: all 0.12s;
}
.visit-card:hover { background: white; border-color: #0f766e; }
.visit-date {
  font-size: 13px; font-weight: 600; color: #1c1917; min-width: 100px;
  font-family: "SF Mono", Consolas, monospace;
}
.visit-info { flex: 1; min-width: 0; }
.visit-diag { font-size: 12px; color: #57534e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visit-actions { display: flex; gap: 6px; }

/* ========== VISIT EDITOR ========== */
.visit-editor {
  background: white; border: 2px solid #0f766e; border-radius: 12px;
  padding: 20px; margin-bottom: 18px;
  box-shadow: 0 2px 8px rgba(15,118,110,0.08);
}
.visit-editor-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid #e7e5e4;
}
.visit-editor-head h3 { color: #115e59; font-size: 18px; }
.visit-tabs { display: flex; gap: 1px; overflow-x: auto; margin-bottom: 14px; background: #f5f5f4; padding: 3px; border-radius: 8px; }
.vtab {
  padding: 7px 11px; border: none; background: transparent;
  font-size: 12px; font-weight: 500; color: #57534e; border-radius: 6px;
  white-space: nowrap;
}
.vtab:hover { color: #115e59; }
.vtab.active { background: white; color: #115e59; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.vpanel { display: none; }
.vpanel.active { display: block; }

/* ========== SECTION HEADERS ========== */
.section-head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 10px; margin-bottom: 18px;
  border-bottom: 1px solid #e7e5e4;
}
.section-head-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: #f0fdfa; color: #0f766e;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.section-head h3 { font-size: 17px; color: #1c1917; }
.section-head p { font-size: 11px; color: #78716c; margin: 2px 0 0; }

/* ========== FORM FIELDS ========== */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(3, 1fr); }
.form-grid-full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }

.field { display: block; }
.field > span, .field-label {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; color: #57534e; margin-bottom: 5px;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="time"],
.field input[type="datetime-local"],
.field input[type="email"],
.field textarea,
.field select,
.input-std {
  width: 100%; padding: 8px 10px;
  border: 1px solid #d6d3d1; border-radius: 6px; background: white;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.field textarea { resize: vertical; min-height: 68px; }
.field input:focus, .field textarea:focus, .field select:focus, .input-std:focus {
  outline: none; border-color: #0f766e; box-shadow: 0 0 0 3px rgba(15,118,110,0.12);
}

.radio-group { display: flex; gap: 16px; padding: 6px 0; flex-wrap: wrap; }
.radio-label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.radio-label input[type="radio"] { accent-color: #0f766e; width: 16px; height: 16px; }

/* Segmented control */
.segmented {
  display: flex; gap: 4px; background: #f5f5f4; padding: 3px; border-radius: 8px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  flex: 1; text-align: center; padding: 7px 10px;
  font-size: 13px; font-weight: 500; color: #57534e;
  border-radius: 6px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented input:checked + label {
  background: white; color: #115e59; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Reg input group */
.reg-group { display: flex; gap: 6px; align-items: center; }
.reg-group select { width: 70px; flex-shrink: 0; padding: 8px 6px; }
.reg-group input { flex: 1; font-family: "SF Mono", monospace; letter-spacing: 0.05em; }

/* Checkboxes */
.check-list { display: grid; gap: 2px; }
.check-list-2 { grid-template-columns: repeat(2, 1fr); column-gap: 16px; }
@media (max-width: 640px) { .check-list-2 { grid-template-columns: 1fr; } }
.check-item {
  display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; cursor: pointer;
}
.check-item input { position: absolute; opacity: 0; }
.check-box {
  flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px;
  border: 2px solid #d6d3d1; border-radius: 4px; background: white;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}
.check-item input:checked + .check-box { background: #0f766e; border-color: #0f766e; }
.check-item input:checked + .check-box::after {
  content: ''; width: 4px; height: 8px; border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}
.check-text { font-size: 13.5px; color: #44403c; line-height: 1.4; }

/* Pills */
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid #d6d3d1; background: white; color: #44403c;
  font-size: 13px; font-weight: 500;
  transition: all 0.12s;
}
.pill.active { background: #0f766e; color: white; border-color: #0f766e; }

/* ========== MEDICATION ========== */
.med-searchbox { position: relative; margin-bottom: 10px; }
.med-searchbox input { width: 100%; padding: 9px 14px 9px 34px; border: 1px solid #d6d3d1; border-radius: 8px; }
.med-searchbox svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: #a8a29e; }

.med-list-container {
  border: 1px solid #e7e5e4; border-radius: 8px; background: white;
  max-height: 260px; overflow-y: auto;
}
.med-option {
  display: flex; align-items: center; width: 100%; padding: 8px 12px; background: none; border: none;
  border-bottom: 1px solid #f5f5f4; text-align: left; cursor: pointer; gap: 8px;
}
.med-option:last-child { border-bottom: none; }
.med-option:hover { background: #f5f5f4; }
.med-option.selected { background: #f0fdfa; color: #115e59; }
.med-option-name { flex: 1; font-size: 13px; font-weight: 500; }
.med-option-cn { color: #78716c; font-size: 12px; }
.med-option-price { color: #0f766e; font-size: 12px; font-weight: 600; white-space: nowrap; }

.selected-meds-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
  color: #57534e; margin: 18px 0 8px;
  display: flex; justify-content: space-between; align-items: center;
}
.meds-total-sum { color: #115e59; font-size: 16px; font-weight: 700; text-transform: none; font-family: Georgia, serif; }
.selected-med {
  background: white; border: 1px solid #e7e5e4; border-radius: 8px;
  padding: 12px; margin-bottom: 10px;
}
.selected-med-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  margin-bottom: 8px;
}
.selected-med-name { font-size: 13.5px; font-weight: 500; }
.selected-med-cn { color: #78716c; font-size: 12px; }
.selected-med-remove {
  background: none; border: none; padding: 4px; cursor: pointer;
  color: #a8a29e; border-radius: 4px;
}
.selected-med-remove:hover { background: #fef2f2; color: #dc2626; }
.selected-med-inputs {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1.2fr 1.2fr;
  gap: 6px;
}
@media (max-width: 700px) { .selected-med-inputs { grid-template-columns: 1fr 1fr; } }
.selected-med-amount { font-weight: 600; color: #115e59; align-self: center; text-align: right; font-family: Georgia, serif; }

/* ========== DIAGNOSIS DROPDOWN ========== */
.diag-wrapper { position: relative; }
.diag-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: white; border: 1px solid #e7e5e4; border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
  max-height: 260px; overflow-y: auto; z-index: 20;
}
.diag-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f5f5f4; font-size: 13px; }
.diag-item:last-child { border-bottom: none; }
.diag-item:hover { background: #f0fdfa; }
.diag-item-cn { color: #78716c; font-size: 11px; margin-left: 6px; }
.diag-item-add {
  padding: 8px 12px; background: #fefce8; color: #854d0e;
  font-size: 13px; cursor: pointer; border-top: 1px solid #fef3c7;
}

/* ========== TREATMENT DAYS ========== */
.days-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.days-list { display: flex; flex-direction: column; gap: 10px; }
.day-card { border: 1px solid #e7e5e4; border-radius: 10px; background: white; overflow: hidden; }
.day-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer;
  background: #fafaf9; border-bottom: 1px solid transparent;
  transition: background 0.12s;
}
.day-header:hover { background: #f5f5f4; }
.day-card.expanded .day-header { border-bottom-color: #e7e5e4; }
.day-chevron { color: #78716c; flex-shrink: 0; transition: transform 0.15s; }
.day-card.expanded .day-chevron { transform: rotate(90deg); }
.day-date { font-size: 14px; font-weight: 600; color: #1c1917; margin-right: 8px; }
.day-summary { flex: 1; font-size: 12px; color: #78716c; }
.day-remove { background: none; border: none; padding: 6px; color: #a8a29e; border-radius: 4px; cursor: pointer; }
.day-remove:hover { background: #fef2f2; color: #dc2626; }
.day-body { padding: 16px 18px; display: none; }
.day-card.expanded .day-body { display: block; }
.day-subhead {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; color: #57534e; margin: 16px 0 6px;
  display: flex; justify-content: space-between; align-items: center;
}
.day-subhead:first-child { margin-top: 0; }

/* ========== NEEDLE POINTS TABLE ========== */
.np-table-wrapper { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
.np-table { width: 100%; border-collapse: collapse; min-width: 640px; font-size: 13px; }
.np-table th {
  text-align: left; font-weight: 600; color: #57534e; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 6px; border-bottom: 1px solid #e7e5e4;
}
.np-table td { padding: 4px 4px; border-bottom: 1px solid #f5f5f4; vertical-align: middle; }
.np-table td input, .np-table td select {
  width: 100%; padding: 6px 8px; border: 1px solid transparent; border-radius: 4px; background: transparent;
  font-size: 13px;
}
.np-table td input:hover, .np-table td select:hover { border-color: #e7e5e4; background: white; }
.np-table td input:focus, .np-table td select:focus {
  outline: none; border-color: #0f766e; background: white;
  box-shadow: 0 0 0 2px rgba(15,118,110,0.1);
}
.np-num { color: #a8a29e; text-align: center; width: 34px; font-weight: 600; }
.np-col-date { width: 140px; }
.np-col-dur { width: 90px; }
.np-col-bp { width: 80px; }
.np-col-actions { width: 40px; text-align: center; }
.np-remove-row { background: none; border: none; color: #a8a29e; padding: 4px; border-radius: 4px; cursor: pointer; }
.np-remove-row:hover { color: #dc2626; background: #fef2f2; }

/* ========== EXAM SHEET IMAGES ========== */
.sheet-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px;
  margin-top: 10px;
}
.sheet-thumb {
  position: relative; aspect-ratio: 1; overflow: hidden;
  border: 1px solid #e7e5e4; border-radius: 8px; background: #f5f5f4;
  cursor: pointer;
}
.sheet-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.2s; }
.sheet-thumb:hover img { transform: scale(1.05); }
.sheet-thumb-remove {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255,255,255,0.9); border: none;
  color: #dc2626; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s;
}
.sheet-thumb:hover .sheet-thumb-remove { opacity: 1; }
.sheet-upload {
  aspect-ratio: 1; border: 2px dashed #d6d3d1; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #78716c; cursor: pointer; background: #fafaf9;
  transition: all 0.15s;
}
.sheet-upload:hover { border-color: #0f766e; color: #0f766e; background: #f0fdfa; }
.sheet-upload input { display: none; }
.sheet-upload svg { margin-bottom: 4px; }
.sheet-upload span { font-size: 11px; font-weight: 500; text-align: center; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 200;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  background: transparent; border: none; color: white;
  font-size: 34px; cursor: pointer; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.lightbox-close:hover { background: rgba(255,255,255,0.15); }

/* ========== PAYMENT ========== */
.payment-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.payment-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border: 1px solid #e7e5e4; border-radius: 8px;
  background: #fafaf9;
}
.payment-method {
  padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.payment-method.card { background: #dbeafe; color: #1e40af; }
.payment-method.cash { background: #dcfce7; color: #166534; }
.payment-method.bank { background: #fef3c7; color: #854d0e; }
.payment-category {
  padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.03em;
}
.payment-category.cat-exam     { background: #e0e7ff; color: #3730a3; }
.payment-category.cat-massage  { background: #fce7f3; color: #9f1239; }
.payment-category.cat-medicine { background: #d1fae5; color: #065f46; }
.payment-amount { font-weight: 700; font-size: 14px; color: #115e59; font-family: Georgia, serif; }
.payment-when { flex: 1; font-size: 12px; color: #78716c; }
.payment-note { font-size: 12px; color: #44403c; font-style: italic; }

.payment-totals {
  display: grid; gap: 10px; grid-template-columns: 1fr 1fr;
  padding: 14px; background: #f0fdfa; border-radius: 8px; margin-top: 10px;
}
.ptot-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #115e59; font-weight: 600; }
.ptot-value { font-size: 22px; font-weight: 700; color: #115e59; font-family: Georgia, serif; }

/* ========== CONSENT ========== */
.consent-box { background: #fafaf9; padding: 16px; border-radius: 8px; font-size: 13.5px; color: #44403c; line-height: 1.6; }

/* ========== NOTE BOX ========== */
.note-box {
  border-left: 4px solid #f59e0b; background: #fefce8;
  padding: 10px 14px; border-radius: 6px; font-size: 13px; color: #44403c;
  margin: 14px 0;
}
.note-box strong { color: #92400e; display: block; margin-bottom: 3px; }

/* ========== MODAL ========== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(28,25,23,0.5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  z-index: 100;
}
.modal {
  background: white; border-radius: 12px; max-width: 480px; width: 100%;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  max-height: 90vh; overflow: auto;
}
.modal-body { padding: 24px; }
.modal-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: #fef2f2; color: #dc2626;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.modal-icon.info { background: #dbeafe; color: #1e40af; }
.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal p { color: #57534e; margin: 0 0 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ========== ADMIN ========== */
.admin-tabs {
  display: flex; gap: 4px; margin-bottom: 18px; overflow-x: auto;
  background: white; padding: 4px; border-radius: 10px; border: 1px solid #e7e5e4;
}
.admin-tab {
  padding: 8px 14px; border: none; background: transparent; color: #57534e;
  font-size: 13px; font-weight: 500; border-radius: 6px; white-space: nowrap;
  transition: all 0.12s;
}
.admin-tab:hover { color: #115e59; }
.admin-tab.active { background: #0f766e; color: white; }
.admin-panel { display: none; }
.admin-panel.active { display: block; }

.data-table {
  width: 100%; border-collapse: collapse; background: white;
  border: 1px solid #e7e5e4; border-radius: 10px; overflow: hidden;
}
.data-table th {
  background: #fafaf9; text-align: left; padding: 10px 12px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #57534e; font-weight: 600; border-bottom: 1px solid #e7e5e4;
}
.data-table td {
  padding: 10px 12px; border-bottom: 1px solid #f5f5f4; font-size: 13px; color: #1c1917;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #fafaf9; }
.data-table .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-admin { background: #fef2f2; color: #991b1b; }
.badge-doctor { background: #dbeafe; color: #1e40af; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-off { background: #f5f5f4; color: #78716c; }

/* ========== AUTH ========== */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #fafaf9 0%, #e7e5e4 100%);
  padding: 20px;
}
.auth-card {
  background: white; border-radius: 14px; padding: 32px 28px;
  width: 100%; max-width: 380px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.06);
}
.auth-logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
  color: white; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.auth-title { font-size: 22px; text-align: center; }
.auth-sub { text-align: center; color: #78716c; font-size: 13px; margin: 4px 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .field { display: flex; flex-direction: column; gap: 5px; }
.auth-form .field span { font-size: 11px; color: #57534e; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.auth-form input { padding: 10px 12px; border: 1px solid #d6d3d1; border-radius: 8px; }
.auth-form input:focus { outline: none; border-color: #0f766e; box-shadow: 0 0 0 3px rgba(15,118,110,0.12); }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warn { background: #fefce8; color: #854d0e; border: 1px solid #fde68a; }
.alert-ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.autosave-hint { text-align: center; color: #a8a29e; font-size: 11px; margin-top: 14px; }
.save-status { font-size: 12px; color: #78716c; white-space: nowrap; }
.save-status.saving { color: #0f766e; }
.save-status.saved { color: #047857; }
.save-status.error { color: #dc2626; }

/* ========== SIGNATURE PAD ========== */
.sig-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 10px; }
@media (max-width: 760px) { .sig-wrap { grid-template-columns: 1fr; } }
.sig-box {
  background: #fafaf9; border: 1px solid #e7e5e4; border-radius: 10px;
  padding: 14px;
}
.sig-box h4 {
  margin: 0 0 10px; font-size: 13px; color: #57534e;
  display: flex; align-items: center; justify-content: space-between;
}
.sig-status { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.sig-status.signed { background: #dcfce7; color: #166534; }
.sig-status.empty  { background: #fef3c7; color: #854d0e; }
.sig-canvas-wrap {
  background: white; border: 2px dashed #d6d3d1; border-radius: 8px;
  position: relative; overflow: hidden;
  aspect-ratio: 3/1; min-height: 140px;
  touch-action: none;
}
.sig-canvas-wrap.has-sig { border-style: solid; border-color: #0f766e; }
.sig-canvas-wrap canvas {
  display: block; width: 100%; height: 100%; cursor: crosshair;
  background: transparent;
  touch-action: none; /* Утсан дээр хуудас хөдлөхөөс сэргийлнэ */
  -webkit-user-select: none; user-select: none;
}
.sig-canvas-wrap img.sig-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; padding: 8px;
}
.sig-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #a8a29e; font-size: 13px; pointer-events: none; user-select: none;
}
.sig-buttons {
  display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap;
}
.sig-buttons .btn { flex: 1; min-width: 80px; }

/* Гар утсан дээр signature padаа багасгах */
@media (max-width: 760px) {
  .sig-canvas-wrap { aspect-ratio: 4/1; min-height: 90px; }
  .sig-canvas-wrap img.sig-img { padding: 4px; }
}

.sig-signer { margin-top: 12px; padding-top: 12px; border-top: 1px dashed #e7e5e4; }
.sig-signer-label { font-size: 12px; color: #57534e; margin-bottom: 6px; font-weight: 500; }
.sig-guardian-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px;
}
.sig-guardian-fields input {
  padding: 8px 10px; border: 1px solid #d6d3d1; border-radius: 6px;
  font-size: 13px; background: white;
}
.sig-guardian-fields input:focus {
  outline: none; border-color: #0f766e; box-shadow: 0 0 0 3px rgba(15,118,110,0.12);
}
.sig-guardian-fields[hidden] { display: none; }
@media (max-width: 500px) { .sig-guardian-fields { grid-template-columns: 1fr; } }

/* ========== MONTH CHIPS (next visit browser) ========== */
.month-chips {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px;
}
@media (max-width: 900px) { .month-chips { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 480px) { .month-chips { grid-template-columns: repeat(4, 1fr); } }
.month-chip {
  position: relative;
  padding: 10px 6px; border: 1px solid #e7e5e4; border-radius: 8px;
  background: white; cursor: pointer;
  text-align: center; font-size: 12px; font-weight: 500; color: #57534e;
  transition: all 0.12s;
}
.month-chip:hover { background: #f0fdfa; border-color: #0f766e; color: #0f766e; }
.month-chip.active { background: #0f766e; border-color: #0f766e; color: white; }
.month-chip .chip-count {
  display: block; font-size: 16px; font-weight: 700; margin-top: 2px;
  font-family: Georgia, serif;
}
.month-chip.active .chip-count { color: white; }
.month-chip.has-items { border-color: #fed7aa; background: #fff7ed; color: #c2410c; }
.month-chip.has-items:hover { background: #ffedd5; }
.month-chip.has-items.active { background: #c2410c; border-color: #c2410c; color: white; }

/* ========== MOBILE SIDEBAR TOGGLE ========== */
.mobile-sidebar-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 10px 12px 0;
  background: white;
  border: 1px solid #e7e5e4;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #0f766e;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  width: calc(100% - 24px);
  max-width: 400px;
}
.mobile-sidebar-toggle:hover { background: #f0fdfa; }
.mobile-sidebar-toggle:active { background: #ccfbf1; }

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 57px; left: 0; bottom: 0;
    transform: translateX(-100%); transition: transform 0.2s;
    z-index: 25; height: calc(100vh - 57px);
    width: 85%; max-width: 340px;
    box-shadow: 0 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop.open { display: block; }
  .mobile-sidebar-toggle { display: inline-flex; }
}

/* ========== PRINT ========== */
@page { size: A4 landscape; margin: 1cm; }
.print-only { display: none; }

@media print {
  body { background: white; }
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  .empty-state, .visit-editor, .patient-view { display: none !important; }
  .layout { display: block; min-height: auto; }
  .main { padding: 0; }

  /* A5 prescription */
  .print-rx {
    padding: 10mm; font-size: 11px; line-height: 1.4;
  }
  .print-rx h1 { font-size: 16px; text-align: center; margin-bottom: 4px; }
  .print-rx .rx-sub { text-align: center; font-size: 10px; color: #555; margin-bottom: 8px; }
  .print-rx .rx-kv { margin: 2px 0; }
  .print-rx table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 11px; }
  .print-rx table th, .print-rx table td {
    border: 1px solid #000; padding: 3px 5px; text-align: left;
  }
  .print-rx table th { background: #eee; font-size: 10px; }
  .print-rx .rx-total {
    display: flex; justify-content: flex-end; gap: 10px; align-items: center;
    margin-top: 8px; font-size: 13px; font-weight: 700;
  }

  .print-card-container .print-sheet {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
    page-break-after: always; font-size: 10px; line-height: 1.3;
  }
  .print-card-container .print-sheet:last-child { page-break-after: auto; }
  .print-card-container .print-sheet > div { padding-right: 8px; }
  .print-card-container .print-sheet > div + div { padding-left: 8px; padding-right: 0; border-left: 1px dashed #999; }
  .print-card-container .print-sheet h2 { font-size: 14px; text-align: center; margin: 0 0 6px; }
  .print-card-container .print-sheet h3 { font-size: 11px; background: #e7e5e4; padding: 2px 4px; margin: 6px 0 4px; border-bottom: 1px solid #000; }
  .print-card-container table { width: 100%; border-collapse: collapse; font-size: 9px; }
  .print-card-container table th, .print-card-container table td { border: 1px solid #000; padding: 2px 3px; text-align: left; }
  .print-card-container table th { background: #f5f5f4; }
  .print-card-container .kv { margin: 1px 0; }
}

/* A5 when specifically printing Rx */
body.printing-rx { /* placeholder for JS to toggle */ }
body.printing-rx @page { size: A5; margin: 8mm; }

@media print {
  body.printing-rx .print-card-container { display: none !important; }
  body.printing-card .print-rx-container { display: none !important; }
}