/*
 * AutoDent app-specific styles layered on top of Oat UI.
 * Oat handles the base semantics; this file keeps the product theme and
 * specialized widgets such as audio recording and autocomplete.
 */

:root {
  --background: #f5f7f9;
  --foreground: #16202a;
  --card: #ffffff;
  --card-foreground: #16202a;
  --primary: #0e7490;
  --primary-foreground: #f8fafc;
  --secondary: #e6f1f5;
  --secondary-foreground: #134154;
  --muted: #eef3f6;
  --muted-foreground: #5b6b78;
  --faint: #f8fbfc;
  --faint-foreground: #7d8b96;
  --accent: #dff1f7;
  --accent-foreground: #134154;
  --danger: #be3d2a;
  --danger-foreground: #fff8f6;
  --success: #237a55;
  --success-foreground: #f5fffa;
  --warning: #b7791f;
  --warning-foreground: #1f1608;
  --border: #d7e0e6;
  --input: #c9d5dd;
  --ring: #0e7490;
  --recording-red: #cf3f3f;
  --page-width: 54rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
}

a {
  text-underline-offset: 0.15em;
}

.page-shell {
  width: min(100% - 2rem, var(--page-width));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.app-header {
  margin-bottom: 1.5rem;
}

.app-header__bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.app-title-link {
  color: inherit;
  text-decoration: none;
}

.app-title-link:hover {
  text-decoration: none;
}

.app-branding h1 {
  margin-bottom: 0.25rem;
}

.app-subtitle,
.meta-row,
.updated-at-timestamp,
.drop-zone-hint,
.empty-state span,
.section-intro,
.billing-progress {
  color: var(--muted-foreground);
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-nav form {
  margin: 0;
}

.main-content {
  display: grid;
  gap: 1rem;
}

.stack {
  display: grid;
  gap: 1rem;
}

.card {
  overflow: hidden;
}

.card > header p:last-child,
.card > footer p:last-child,
.card > div p:last-child,
.card > section p:last-child {
  margin-bottom: 0;
}

.screen-header {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.screen-header h2,
.screen-header h3 {
  margin-bottom: 0;
}

.audit-patient-heading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.audit-billing-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.audit-billing-badge--gkv {
  background: color-mix(in srgb, var(--primary) 12%, white);
  color: var(--primary);
}

.audit-billing-badge--pkv {
  background: color-mix(in srgb, var(--warning) 14%, white);
  color: var(--warning-foreground);
}

.audit-billing-badge--other {
  background: var(--muted);
  color: var(--muted-foreground);
}

.audit-calendar-card,
.audit-empty-state,
.audit-patient-list,
.audit-detail-card {
  padding: 1rem;
}

.audit-calendar-shell {
  width: fit-content;
}

.audit-patient-list__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.audit-model-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.audit-day-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.audit-report-suggestions__amount {
  font-weight: 700;
  white-space: nowrap;
  justify-self: end;
  text-align: right;
}

.audit-patient-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.audit-patient-row__suggestions {
  white-space: nowrap;
  align-self: center;
}

.audit-patient-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
}

.audit-patient-link strong {
  font-size: 1rem;
}

.audit-patient-link__identity {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.audit-patient-link span,
.audit-entry-table__muted,
.audit-entry-table__meta {
  color: var(--muted-foreground);
}

.audit-detail-card__header {
  margin-bottom: 1rem;
}

.audit-detail-card__header h3 {
  margin: 0;
}

.audit-entry-table {
  width: 100%;
  border-collapse: collapse;
}

.audit-entry-table th,
.audit-entry-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.audit-entry-table thead th {
  border-top: 0;
  color: var(--muted-foreground);
  font-weight: 600;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.audit-entry-table__cell--nowrap {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.audit-history-table th:nth-child(1),
.audit-history-table td:nth-child(1) {
  width: 4.5rem;
}

.audit-history-table th:nth-child(2),
.audit-history-table td:nth-child(2) {
  width: 5.5rem;
}

.audit-history-table th:nth-child(3),
.audit-history-table td:nth-child(3) {
  width: 5rem;
}

.audit-history-table__group th {
  background: var(--faint);
  color: var(--foreground);
  font-weight: 700;
}

.admin-suggestions-table__updated-at {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.admin-suggestions-table {
  table-layout: auto;
}

.admin-suggestions-table th {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.admin-suggestions-table__model {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.admin-suggestions-table th:nth-child(4),
.admin-suggestions-table td:nth-child(4) {
  min-width: 18rem;
}

.audit-accordion {
  display: grid;
  gap: 0.75rem;
}

.audit-accordion__item {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--faint);
  overflow: hidden;
}

.audit-accordion__summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.5rem 1rem;
  padding: 0.9rem 1rem;
  cursor: pointer;
}

.audit-suggestion-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.audit-model-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--accent);
  color: var(--accent-foreground);
}

.audit-accordion__body {
  padding: 0 1rem 1rem;
  background: var(--card);
  border-top: 1px solid var(--border);
}

.audit-accordion__body p:first-child {
  margin-top: 1rem;
}

.audit-suggestion-feedback {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.75rem;
}

.audit-suggestion-feedback__actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.audit-suggestion-feedback__action {
  margin: 0;
}

.audit-suggestion-feedback__button {
  min-width: 3.2rem;
}

.audit-suggestion-feedback__button.is-active {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  color: var(--accent-foreground);
}

.audit-suggestion-feedback__status,
.audit-suggestion-feedback__saved {
  margin: 0;
}

.audit-suggestion-feedback__form {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
}

.audit-suggestion-feedback__label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.audit-suggestion-feedback__input {
  min-width: min(100%, 24rem);
}

.audit-report-output {
  margin: 0;
  padding: 1rem;
  border-radius: 0.85rem;
  background: var(--faint);
  overflow-x: auto;
}

.audit-markdown > :first-child {
  margin-top: 1rem;
}

.audit-markdown table {
  width: 100%;
  border-collapse: collapse;
}

.audit-markdown th,
.audit-markdown td {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

@media (max-width: 720px) {
  .audit-patient-link {
    flex-direction: column;
    align-items: flex-start;
  }

  .audit-patient-row {
    flex-direction: column;
  }

  .audit-patient-row__suggestions {
    align-self: flex-start;
  }

  .audit-entry-table,
  .audit-entry-table thead,
  .audit-entry-table tbody,
  .audit-entry-table tr,
  .audit-entry-table th,
  .audit-entry-table td {
    display: block;
  }

  .audit-entry-table thead {
    display: none;
  }

  .audit-entry-table tr {
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
  }

  .audit-entry-table td {
    border-top: 0;
    padding: 0.35rem 0;
  }

  .audit-accordion__summary {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .audit-suggestion-feedback__form {
    align-items: stretch;
  }
}

.entry-form-card,
.entry-list-card,
.entry-detail-card,
.auth-card,
.entry-link {
  display: grid;
  gap: 1rem;
}

.entry-form {
  display: grid;
  gap: 1rem;
}

.field-grid {
  display: grid;
  gap: 1rem;
}

.field-grid--two {
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

.patient-summary {
  display: grid;
  gap: 0.25rem;
}

.patient-summary strong {
  font-size: 1.05rem;
}

.entry-actions,
.entry-toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.entry-toolbar form,
.entry-actions form,
.delete-section form,
.billing-actions form {
  margin: 0;
}

.button-success {
  background: var(--success);
  border-color: var(--success);
  color: var(--success-foreground);
}

.button-success:hover {
  filter: brightness(0.97);
}

.button-danger-outline {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 72%, white);
}

.button-danger-outline:hover {
  background: color-mix(in srgb, var(--danger) 10%, white);
}

.button-full {
  width: 100%;
  justify-content: center;
}

.drop-zone {
  position: relative;
  border: 1px dashed transparent;
  border-radius: var(--radius);
  padding: 0.25rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--accent) 50%, white);
}

.recording-panel {
  display: grid;
  gap: 0.5rem;
  padding: 0.85rem 0;
}

.recording-section-compact {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
}

.record-btn-compact {
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--input);
  background: var(--card);
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.record-btn-compact:hover {
  background: var(--faint);
  border-color: var(--primary);
}

.record-btn-compact:active {
  transform: scale(0.96);
}

.record-btn-compact.recording {
  border-color: var(--recording-red);
  background: color-mix(in srgb, var(--recording-red) 10%, white);
}

.mic-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.record-btn-compact.recording .mic-icon {
  display: none;
}

.stop-icon {
  display: none;
  width: 0.8rem;
  height: 0.8rem;
  background: var(--recording-red);
  border-radius: 0.2rem;
  animation: pulse-recording 1.35s infinite;
}

.record-btn-compact.recording .stop-icon {
  display: block;
}

@keyframes pulse-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.waveform-compact {
  display: flex;
  align-items: center;
  gap: 0.18rem;
  min-width: 0;
  height: 2rem;
}

.waveform-bar-compact {
  flex: 1;
  min-width: 0.22rem;
  height: 0.25rem;
  border-radius: 999px;
  background: var(--border);
  transition: height 0.1s ease, background-color 0.2s ease;
}

.waveform-compact.active .waveform-bar-compact {
  background: var(--recording-red);
}

.timer-compact {
  min-width: 3rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--faint-foreground);
}

.timer-compact.active {
  color: var(--recording-red);
}

.status-message-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--muted-foreground);
}

html[aria-busy="true"]::before,
body[aria-busy="true"]::before {
  content: none !important;
  display: none !important;
}

.status-message-inline[aria-busy="true"]::before {
  content: "";
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.autocomplete-shell {
  position: relative;
}

.autocomplete-results {
  position: absolute;
  z-index: 10;
  inset: calc(100% + 0.35rem) 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 0.15rem);
  box-shadow: 0 18px 40px rgb(15 23 42 / 0.12);
  max-height: 16rem;
  overflow: auto;
}

.autocomplete-item {
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.autocomplete-item + .autocomplete-item {
  border-top: 1px solid var(--border);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--accent);
}

.hidden {
  display: none !important;
}

.recordings-list,
.date-group {
  display: grid;
  gap: 0.85rem;
}

.date-group + .date-group {
  margin-top: 1rem;
}

.date-header {
  margin: 0.5rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.entry-link {
  color: inherit;
  text-decoration: none;
}

.entry-link:hover {
  text-decoration: none;
}

.entry-link article.card {
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.entry-link:hover article.card {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

.entry-card-header,
.meta-row,
.billing-card header,
.billing-summary {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: baseline;
}

.patient-line {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.entry-summary {
  color: var(--muted-foreground);
}

.processing-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.processing-inline [aria-busy="true"] {
  flex: 0 0 auto;
}

.empty-state {
  display: grid;
  gap: 0.5rem;
  place-items: center;
  text-align: center;
  padding: 2.5rem 1rem;
  background: linear-gradient(180deg, color-mix(in srgb, var(--faint) 85%, white), var(--card));
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-icon {
  width: 2.25rem;
  height: 2.25rem;
  color: var(--faint-foreground);
}

.billing-card {
  display: grid;
  gap: 1rem;
}

.billing-status {
  display: grid;
  gap: 0.75rem;
}

.billing-content {
  display: grid;
  gap: 0.85rem;
}

.billing-content table {
  width: 100%;
}

.error-content {
  display: grid;
  gap: 0.75rem;
}

.error-message {
  color: var(--danger);
}

.updated-at-timestamp {
  font-size: 0.92rem;
}

.auth-shell {
  width: min(100% - 2rem, 30rem);
  margin: 4rem auto;
}

.audit-dashboard {
  grid-template-columns: 1fr;
  align-items: start;
}

.audit-calendar-card,
.audit-create-card,
.audit-report-card,
.audit-run-detail,
.audit-create-form {
  display: grid;
  gap: 1rem;
}

.audit-calendar__header,
.audit-report-card__header,
.audit-run-detail__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.audit-run-detail__header div:first-child {
  flex-grow: 1;
}

.audit-dashboard > section:first-child {
  max-width: 58rem;
}

.audit-reports-section {
  width: 100%;
}

.audit-calendar {
  display: flex;
  justify-content: center;
}

.air-datepicker-cell.-day-.audit-calendar__day--has-report {
  background: color-mix(in srgb, #9ad9a8 28%, white);
  color: inherit;
  font-weight: 600;
}

.air-datepicker-cell.-day-.audit-calendar__day--has-report.-focus- {
  background: color-mix(in srgb, #8fd39f 38%, white);
}

.air-datepicker-cell.-day-.audit-calendar__day--has-report.-selected-,
.air-datepicker-cell.-day-.audit-calendar__day--has-report.-selected-.-focus- {
  color: #fff;
  background: var(--adp-cell-background-color-selected);
}

.air-datepicker-cell.-day-.audit-calendar__day--has-report.-selected-.-focus- {
  background: var(--adp-cell-background-color-selected-hover);
}

.audit-date-fallback {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
}

.audit-run-tabs {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.audit-run-tab {
  display: inline-grid;
  gap: 0.1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--faint);
  color: inherit;
  text-decoration: none;
}

.audit-run-tab:hover {
  text-decoration: none;
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

.audit-run-tab.is-active {
  background: color-mix(in srgb, var(--accent) 55%, white);
  border-color: var(--primary);
}

.audit-run-tab__emoji {
  display: inline-block;
  margin-right: 0.3rem;
}

.audit-run-status {
  display: grid;
  gap: 0.75rem;
  padding: 0.25rem 0;
}

.audit-report-content {
  width: 100%;
}

.audit-report-content > :first-child {
  margin-top: 0;
}

.audit-report-content > :last-child {
  margin-bottom: 0;
}

.audit-structured-report,
.audit-kpi-grid,
.audit-finding-section {
  display: grid;
  gap: 1rem;
}

.audit-kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}

.audit-kpi-card {
  gap: 0.5rem;
}

.audit-finding {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  padding: 0.25rem 0.9rem;
}

.audit-finding__summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.audit-finding__summary-text {
  font-weight: 600;
}

.audit-finding__summary-meta {
  display: inline-flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.audit-finding__body {
  display: grid;
  gap: 0.85rem;
  padding: 0.25rem 0 0.75rem;
}

.audit-finding__body p {
  margin: 0;
}

.audit-finding__body ul {
  margin-top: -0.35rem;
}

.audit-empty-state {
  min-height: 16rem;
}

@media (max-width: 640px) {
  .audit-dashboard {
    grid-template-columns: 1fr;
  }

  .page-shell {
    width: min(100% - 2rem, var(--page-width));
    padding-top: 1rem;
    padding-bottom: 2rem;
  }

  .app-header {
    margin-bottom: 1rem;
  }

  .app-header__bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .app-branding h1 {
    font-size: 1.4rem;
    margin-bottom: 0.15rem;
  }

  .app-nav {
    gap: 0.5rem;
    width: 100%;
  }

  .app-nav .button,
  .app-nav button,
  .app-nav input[type="submit"] {
    font-size: 0.875rem;
    padding: 0.4rem 0.75rem;
  }

  .recording-section-compact {
    grid-template-columns: auto 1fr;
  }

  .timer-compact {
    grid-column: 2;
    text-align: left;
  }

  .entry-card-header {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .billing-content {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

}
