* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1a1a1a;
  background: #fafafa;
}

a {
  color: #0a58ca;
}

header.topbar {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

header.topbar .brand {
  font-weight: 600;
  text-decoration: none;
  color: #1a1a1a;
}

nav.mainnav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

nav.mainnav a {
  text-decoration: none;
  color: #333;
  padding: 4px 0;
}

nav.mainnav a.active {
  color: #0a58ca;
  font-weight: 600;
}

.logout-form {
  display: inline;
  margin: 0;
  padding: 0;
}

.link-button {
  background: none;
  border: none;
  padding: 4px 0;
  margin: 0;
  font: inherit;
  color: #333;
  cursor: pointer;
  text-decoration: none;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 12px 40px;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 16px;
}

h2 {
  font-size: 1.1rem;
  margin: 24px 0 10px;
  border-top: 1px solid #e5e5e5;
  padding-top: 16px;
}

.field {
  margin-bottom: 14px;
}

.field ul {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
}

.field ul li {
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}

.field ul li:last-child {
  border-bottom: none;
}

.field ul label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  font-size: 1rem;
  color: #1a1a1a;
}

.field ul input[type="checkbox"] {
  width: auto;
}

input:disabled {
  background: #f0f0f0;
  color: #666;
}

/* --- Chip select (Google-sharing-style multi/single pick from a list) --- */

.chip-select {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chip-select-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e8f0fe;
  color: #0a58ca;
  border-radius: 14px;
  padding: 6px 8px 6px 12px;
  font-size: 0.85rem;
  border: none;
}

.chip-remove {
  background: none;
  border: none;
  color: inherit;
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.chip-add {
  background: #eee;
  color: #444;
  border: 1px dashed #aaa;
  cursor: pointer;
  padding: 6px 12px;
}

.chip-link {
  text-decoration: none;
  padding: 8px 14px;
}

.chip-select-dropdown {
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  min-width: 200px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.chip-select-option {
  padding: 10px 12px;
  font-size: 0.95rem;
}

.chip-select-option:active {
  background: #e8f0fe;
}

/* --- Photo sections (До/После on operations, photos on visits) --- */

.photo-section {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.photo-group {
  flex: 1;
  min-width: 130px;
}

.photo-group-label {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 6px;
}

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.photo-thumbs:empty {
  margin-bottom: 0;
}

.photo-thumbs img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e5e5e5;
  cursor: pointer;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.photo-upload-btn {
  display: inline-block;
  margin: 0;
  position: relative;
  overflow: hidden;
}

.photo-upload-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  cursor: pointer;
}

label {
  display: block;
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-family: inherit;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

button, .btn {
  display: inline-block;
  padding: 11px 18px;
  font-size: 16px;
  border: none;
  border-radius: 6px;
  background: #0a58ca;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

button:active, .btn:active {
  background: #084298;
}

.btn.secondary {
  background: #eee;
  color: #1a1a1a;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-form input {
  flex: 1;
}

.list-item {
  display: block;
  padding: 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}

.list-item:hover {
  border-color: #0a58ca;
}

.list-item .name {
  font-weight: 600;
}

.list-item .meta {
  font-size: 0.85rem;
  color: #666;
  margin-top: 2px;
}

.card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.card .meta {
  font-size: 0.85rem;
  color: #666;
}

.empty {
  color: #888;
  font-style: italic;
  padding: 8px 0;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.messages li {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #fdecea;
  color: #7a1f14;
  font-size: 0.9rem;
}

.messages li.success {
  background: #e6f4ea;
  color: #1e4620;
}

.patient-header {
  margin-bottom: 4px;
}

.patient-header .iin {
  color: #666;
  font-weight: 400;
}

#calendar {
  background: #fff;
  border-radius: 8px;
  padding: 8px;
}

/* --- Swipe-to-delete + long-press --- */

.swipeable {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 10px;
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 88px;
  display: flex;
}

.swipe-delete-btn {
  flex: 1;
  border-radius: 0;
  background: #d33;
  font-size: 0.85rem;
}

.swipe-content {
  position: relative;
  background: #fff;
  touch-action: pan-y;
  transition: transform 0.15s ease-out;
  margin-bottom: 0;
}

.swipe-content.card {
  margin-bottom: 0;
}

/* --- Long-press action sheet --- */

.action-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.action-sheet {
  background: #fff;
  width: 100%;
  border-radius: 14px 14px 0 0;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
}

.action-sheet-title {
  text-align: center;
  color: #888;
  font-size: 0.8rem;
  padding: 10px 0;
}

.action-sheet-btn {
  display: block;
  width: 100%;
  background: none;
  color: #0a58ca;
  padding: 14px;
  font-size: 1rem;
  border-top: 1px solid #eee;
}

.action-sheet-btn.danger {
  color: #d33;
}

/* --- Bottom tab bar (mobile) --- */

.bottom-nav {
  display: none;
}

.logout-icon-form {
  display: none;
}

@media (max-width: 640px) {
  header.topbar nav.mainnav {
    display: none;
  }

  .logout-icon-form {
    display: inline-block;
  }

  .logout-icon-form .link-button {
    font-size: 1.2rem;
    padding: 0;
  }

  body {
    padding-bottom: 76px;
  }

  body.keyboard-open .bottom-nav {
    display: none;
  }

  body.keyboard-open {
    padding-bottom: 0;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #ddd;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-between;
    align-items: center;
    z-index: 50;
    /* Forces its own GPU compositing layer — without this, iOS Safari
       sometimes fails to paint a `position: fixed` element on initial
       load and only renders it after a tap/scroll triggers a repaint. */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
  }

  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: #666;
    text-decoration: none;
    font-size: 0.7rem;
    flex: 1;
  }

  .bottom-nav a.active {
    color: #0a58ca;
  }

  .bottom-nav .icon {
    font-size: 1.3rem;
    line-height: 1;
  }

  .bottom-nav .add-action {
    flex: 0 0 auto;
    margin-top: -28px;
  }

  .bottom-nav .add-action .icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #0a58ca;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    box-shadow: 0 2px 8px rgba(10, 88, 202, 0.4);
  }

  .bottom-nav .add-action span:last-child {
    color: #666;
  }
}
