:root {
  color-scheme: light dark;
  --bg: #eef1f6;
  --card-bg: #ffffff;
  --header-bg: #ffffff;
  --text: #171b21;
  --muted: #667085;
  --border: #e2e5eb;
  --accent: #1c5fae;
  --accent-hover: #164a89;
  --accent-soft: #eaf2fd;
  --accent-text: #ffffff;
  --danger: #c0362c;
  --danger-soft: #fdecea;
  --success-bg: #e3f6ec;
  --success-text: #0c6b41;
  --warning-bg: #fff4d6;
  --warning-text: #7a5300;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131a;
    --card-bg: #1a1e27;
    --header-bg: #161a22;
    --text: #eceef2;
    --muted: #98a2b3;
    --border: #2a2f3a;
    --accent: #5b9bf5;
    --accent-hover: #7cb0f8;
    --accent-soft: #1c2b42;
    --accent-text: #0b0d10;
    --danger: #f2867d;
    --danger-soft: #3a1f1d;
    --success-bg: #123626;
    --success-text: #6fe0ac;
    --warning-bg: #3d3200;
    --warning-text: #ffe17a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.compliance-banner {
  background: var(--warning-bg);
  color: var(--warning-text);
  padding: 0.55rem 1rem;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.9rem 1rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  height: 40px;
  width: auto;
  display: block;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.topbar .who {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--muted);
}

.topbar nav { display: flex; gap: 1.1rem; align-items: center; }
.topbar a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
}
.topbar a:hover { text-decoration: underline; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.centered-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  gap: 1.5rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem;
  margin-bottom: 1.2rem;
  transition: box-shadow 0.15s ease;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 1rem;
}
h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 0;
  letter-spacing: -0.005em;
}
h3 { font-size: 1rem; font-weight: 650; }

.hint { color: var(--muted); font-size: 0.88rem; }
.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-weight: 600;
  font-size: 0.9rem;
}

label {
  display: block;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  font-weight: 550;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="search"] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-weight: 400;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 4.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 0.8rem;
  padding: 0.8rem 1rem;
}

fieldset legend {
  font-weight: 650;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 0.3rem;
}

fieldset label { margin-bottom: 0.5rem; font-weight: normal; }
fieldset label:last-child { margin-bottom: 0; }

button {
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }
button:active:not(:disabled) { transform: translateY(1px); }

.primary-button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.2rem;
  width: 100%;
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}

.primary-button:hover:not(:disabled) { background: var(--accent-hover); }

.secondary-button {
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  width: 100%;
  font-weight: 600;
}

.secondary-button:hover:not(:disabled) { border-color: var(--accent); }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-weight: 600;
}

.photo-buttons {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.photo-buttons .secondary-button {
  width: auto;
  flex: 1;
}

.custom-code-form {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 0.8rem;
  margin-top: 0.6rem;
}

.custom-code-form input {
  margin-bottom: 0.5rem;
}

.custom-code-toggle {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0.4rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
}

.photo-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.photo-thumb, .photo-preview-item img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.photo-thumb-button {
  background: none;
  border: none;
  padding: 0;
  cursor: zoom-in;
}

.photo-thumb-button .photo-thumb {
  width: 160px;
  height: 160px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.photo-thumb-button:hover .photo-thumb {
  transform: scale(1.03);
  box-shadow: var(--shadow-md);
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.lightbox-img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.6rem;
  line-height: 1;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  font-size: 2rem;
  line-height: 1;
}

.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

.lightbox-original-link {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

.photo-preview-item {
  position: relative;
}

.photo-preview-item button {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}

.visit-block {
  border-top: 1px solid var(--border);
  padding-top: 1.1rem;
  margin-top: 1.1rem;
}

.visit-block:first-child { border-top: none; margin-top: 0; padding-top: 0; }

.icd10-picker { margin-top: 0.6rem; }

.icd10-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

.icd10-chip {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 550;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.icd10-chip button {
  background: none;
  border: none;
  color: inherit;
  font-weight: bold;
  padding: 0;
}

.icd10-results {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 0.4rem;
  background: var(--card-bg);
}

.icd10-result-item {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.icd10-result-item:last-child { border-bottom: none; }
.icd10-result-item:hover, .icd10-result-item:focus { background: var(--accent-soft); }
.icd10-result-item.disabled { opacity: 0.4; cursor: not-allowed; }
.icd10-result-item.disabled:hover { background: none; }

.remove-visit {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

.same-as-visit1 { margin-top: 0.4rem; }

.bill-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.bill-table th {
  text-align: left;
  padding: 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 650;
  border-bottom: 1px solid var(--border);
}

.bill-table td {
  text-align: left;
  padding: 0.65rem 0.55rem;
  border-bottom: 1px solid var(--border);
}

.bill-table tbody tr:hover { background: var(--accent-soft); }
.bill-table a { color: var(--accent); font-weight: 600; text-decoration: none; }
.bill-table a:hover { text-decoration: underline; }

.status-pill {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.status-pending { background: var(--warning-bg); color: var(--warning-text); }
.status-billed { background: var(--success-bg); color: var(--success-text); }
.status-flagged { background: var(--danger-soft); color: var(--danger); }

.icd10-list { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; }

.attention-card {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  margin-bottom: 1.2rem;
}

.attention-card h2 { color: var(--danger); }

.attention-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.attention-list a {
  display: block;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.attention-list a:hover { box-shadow: var(--shadow-md); }
.attention-list .hint { font-weight: 400; }

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.plain-list li {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.plain-list .hint { font-weight: 400; }

.comment-thread {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin: 0.8rem 0;
}

.comment {
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
}

.comment.author-doctor { border-left: 3px solid var(--accent); }
.comment.author-biller { border-left: 3px solid var(--danger); }

.comment-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.comment-body { font-size: 0.92rem; white-space: pre-wrap; }

.comment-form {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}
