/* ─── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green: #1a7a3a;
  --green-dark: #156830;
  --green-light: #e8f5ec;
  --green-header-text: #1a7a3a;
  --text-primary: #1a1a1a;
  --text-secondary: #5c6670;
  --border: #e2e8f0;
  --page-bg: #f0f2f5;
  --card-bg: #fff;
}

body {
  font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--page-bg);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── App header ───────────────────────────────────────── */
.app-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.app-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-avatar {
  position: relative;
  flex-shrink: 0;
}

.user-avatar-icon {
  width: 44px;
  height: 44px;
  display: block;
  border-radius: 50%;
  border: 2px solid var(--border);
}

.user-avatar-status {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 10px;
  height: 10px;
  background: var(--green);
  border: 2px solid var(--card-bg);
  border-radius: 50%;
}

/* ─── Layout ───────────────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px 48px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* ─── Toolbar / Search ─────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-field {
  position: relative;
  flex: 1 1 320px;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: #9aa5b1;
  pointer-events: none;
}

.search-field input[type="search"] {
  width: 100%;
  font: inherit;
  font-size: 0.9375rem;
  padding: 11px 14px 11px 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-field input[type="search"]:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(26, 122, 58, 0.12);
}

.search-field input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-status {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  min-height: 1.25em;
}

/* ─── Form ─────────────────────────────────────────────── */
.add-form {
  margin-top: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px 16px;
  margin-bottom: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #333;
}

input[type="text"],
input[type="date"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #b8c4ce;
  border-radius: 6px;
  background: #fff;
  transition: border-color 0.15s;
  width: 100%;
  box-sizing: border-box;
  min-height: 38px;
}

input[type="date"] {
  cursor: pointer;
}

input[type="text"]:focus,
input[type="date"]:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(26, 122, 58, 0.15);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-message {
  font-size: 0.875rem;
}

.form-message.success {
  color: #1a7f37;
}

.form-message.error {
  color: #b42318;
}

/* ─── Buttons ──────────────────────────────────────────── */
.btn {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green-dark);
}

.btn-primary:hover:not(:disabled) {
  background: var(--green-dark);
}

.btn-outline {
  background: var(--card-bg);
  color: var(--green);
  border-color: var(--green);
}

.btn-outline:hover:not(:disabled) {
  background: var(--green-light);
}

.btn-secondary {
  background: #f4f6f8;
  color: #333;
  border-color: #b8c4ce;
}

.btn-secondary:hover:not(:disabled) {
  background: #e8ecef;
}

/* ─── Tables ───────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: calc(100vh - 280px);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  background: var(--green-light);
  color: var(--green-header-text);
  text-align: left;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid #cfe8d6;
}

.data-table th.checkbox-col {
  text-align: center;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-secondary);
}

.data-table tbody tr {
  background: var(--card-bg);
}

.data-table tbody tr:hover {
  background: #f8fbf9;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.name-cell-col {
  min-width: 180px;
}

.name-edit-fields {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.contact-cell {
  min-width: 110px;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.patient-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green);
}

.patient-icon svg {
  width: 16px;
  height: 16px;
}

.patient-name {
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.empty-cell {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px 12px !important;
}

.data-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--green);
}

.checkbox-col {
  text-align: center;
}

.checkbox-cell {
  text-align: center;
}

.actions-col {
  width: 48px;
}

.actions-cell {
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}

.btn-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #9aa5b1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.btn-delete svg {
  width: 18px;
  height: 18px;
}

.btn-delete:hover:not(:disabled) {
  color: #c53030;
  background: #fff5f5;
}

.btn-delete:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.date-cell {
  white-space: nowrap;
}

.pin-cell {
  min-width: 90px;
}

.note-cell {
  min-width: 160px;
  max-width: 360px;
  vertical-align: top;
}

.note-text {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
  color: var(--text-primary);
}

.note-text.is-empty {
  color: var(--text-secondary);
}

.data-table input[type="date"].date-input,
.data-table input.table-text-input {
  width: 100%;
  min-width: 90px;
  max-width: 150px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  color: var(--text-primary);
  background: var(--card-bg);
  box-sizing: border-box;
}

.data-table input.table-text-input.name-part-input {
  min-width: 140px;
  max-width: 220px;
}

.data-table input.table-text-input.contact-input {
  min-width: 100px;
  max-width: 160px;
}

.data-table input.table-text-input.pin-input {
  min-width: 90px;
  max-width: 150px;
}

.data-table textarea.note-input {
  width: 100%;
  min-width: 160px;
  min-height: 2.5em;
  max-width: none;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  color: var(--text-primary);
  background: var(--card-bg);
  box-sizing: border-box;
  resize: vertical;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

.data-table input[type="date"].date-input {
  min-width: 130px;
  cursor: pointer;
}

.data-table input[type="date"].date-input:focus,
.data-table input.table-text-input:focus,
.data-table textarea.note-input:focus {
  outline: 2px solid var(--green-light);
  border-color: var(--green);
}

.note-field {
  display: block;
  margin-top: 12px;
}

.note-field textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #b8c4ce;
  border-radius: 6px;
  background: #fff;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 38px;
  line-height: 1.4;
}

.note-field textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(26, 122, 58, 0.15);
}

.service-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.service-checkboxes legend {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #333;
  padding: 0 6px;
}

.checkbox-label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #333;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
  cursor: pointer;
}

/* ─── Search highlight ─────────────────────────────────── */
mark.search-hit {
  background: #ffe066;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

/* ─── Pagination ───────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

#page-info {
  font-size: 0.875rem;
  color: #444;
}

/* ─── Alerts & Setup ───────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}

.alert-success {
  background: #e6f4ea;
  color: #1a7f37;
  border: 1px solid #a8dab5;
}

.alert-error {
  background: #fce8e8;
  color: #b42318;
  border: 1px solid #f5b8b8;
}

.setup-page {
  max-width: 560px;
}

.setup-page .card p {
  margin-bottom: 16px;
  color: #444;
}

.setup-page .btn {
  text-decoration: none;
  display: inline-block;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
}

.page-header p {
  margin-top: 4px;
  color: #555;
}

/* ─── Modal ────────────────────────────────────────────── */
body.modal-open {
  overflow: hidden;
}

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

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--green);
}

.modal-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #555;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: #f4f6f8;
  color: #1a1a1a;
}

#toggle-edit-mode.active {
  background-color: #fffbeb;
  color: #b45309;
  border-color: #fcd34d;
}

#toggle-edit-mode.active:hover {
  background-color: #fef3c7;
}

@media (max-width: 768px) {
  .app-header-inner {
    padding: 16px 20px;
    gap: 12px;
  }

  .brand-logo {
    width: 60px;
    height: 60px;
  }

  .brand-text h1 {
    font-size: 1.5rem;
  }

  .container {
    padding: 0 16px 32px;
  }

  .card {
    padding: 16px 20px 20px;
    border-radius: 8px;
    margin-bottom: 16px;
  }

  .table-wrap {
    max-height: calc(100vh - 240px);
  }
}

@media (max-width: 640px) {
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .search-field {
    grid-column: span 2;
  }

  #toggle-edit-mode {
    grid-column: span 2;
  }

  .toolbar .btn {
    width: 100%;
    padding: 10px 12px;
  }
}

@media (max-width: 576px) {
  .app-header-inner {
    padding: 12px 16px;
    gap: 8px;
  }

  .brand {
    gap: 10px;
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  .brand-text h1 {
    font-size: 1.2rem;
  }

  .user-avatar-icon {
    width: 36px;
    height: 36px;
  }

  .user-avatar-status {
    width: 8px;
    height: 8px;
    right: 1px;
    bottom: 1px;
  }

  .container {
    padding: 0 12px 24px;
  }

  .card {
    padding: 12px 16px 16px;
    border-radius: 6px;
    margin-bottom: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 12px;
  }

  .service-checkboxes {
    gap: 10px 14px;
    padding: 10px 12px;
    margin-bottom: 12px;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal {
    padding: 16px 16px;
    border-radius: 8px;
    max-height: calc(100vh - 24px);
  }

  .modal-header {
    margin-bottom: 12px;
  }

  .modal-header h2 {
    font-size: 1.125rem;
  }

  .pagination {
    gap: 8px;
    margin-top: 12px;
  }

  .pagination .btn {
    padding: 8px 12px;
    font-size: 0.8125rem;
  }

  #page-info {
    font-size: 0.8125rem;
  }
}

@media (max-width: 400px) {
  .app-header-inner {
    flex-direction: row;
    align-items: center;
  }
  
  .brand-text h1 {
    font-size: 1.1rem;
  }
  
  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 10px;
  }

  .form-actions .btn {
    width: 100%;
    text-align: center;
  }

  .form-actions .form-message {
    text-align: center;
    margin-bottom: 4px;
  }
}

.table-wrap {
  -webkit-overflow-scrolling: touch;
}

.table-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
