/* ============================================================
   TIERARZT PWA – Apple Minimalist Design System
   ============================================================ */

/* Design Tokens */
:root {
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --surface-2: #F2F2F7;
  --separator: rgba(60,60,67,0.12);
  --label: #000000;
  --label-2: rgba(60,60,67,0.6);
  --label-3: rgba(60,60,67,0.3);
  --accent: #2D6A4F;
  --accent-dark: #1B4332;
  --accent-red: #FF3B30;
  --accent-green: #34C759;
  --accent-orange: #FF9500;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  --radius: 10px;
  --tab-height: 83px;

  /* Backward-compat aliases */
  --card: var(--surface);
  --text-primary: var(--label);
  --text-secondary: var(--label-2);
  --border: var(--separator);
  --danger: var(--accent-red);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --label: #FFFFFF;
    --separator: rgba(255,255,255,0.12);
  }
}

/* ============================================================
   Reset
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   Body / App Shell
   ============================================================ */
html {
  height: 100%;
  margin: 0;
}

/* body joins the flex chain so #app can fill it exactly */
body, #app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--label);
}

/* Single header: logo left + title centered, one taller row */
#nav-header {
  height: calc(56px + env(safe-area-inset-top, 0px));
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: flex-end;
  padding: 0 16px 8px;
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(242, 242, 247, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--separator);
  z-index: 10;
}

#app-logo {
  height: 26px;
  width: auto;
  display: block;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

#app-logo-fallback {
  display: none;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
}

#nav-title {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--label);
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  #nav-header { background: rgba(0, 0, 0, 0.92); }
  #app-logo   { filter: invert(1); }
}

/* Scrollable content area — min-height:0 prevents flex blowout */
#main-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================
   Tab Panels
   ============================================================ */
.tab-panel {
  display: none;
  min-height: 100%;
}

/* Both class names accepted: new (.active) and legacy (.tab-active) */
.tab-panel.active,
.tab-panel.tab-active {
  display: block !important;
}

/* ============================================================
   Nav Bar (per-tab mini headers rendered by JS modules)
   ============================================================ */
.nav-bar {
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

@media (prefers-color-scheme: dark) {
  .nav-bar { background: rgba(0, 0, 0, 0.85); }
}

.nav-bar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  display: flex;
  align-items: center;
}

.nav-bar h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.4px;
  flex: 1;
  text-align: center;
  margin: 0;
  padding: 4px 0 8px;
  margin-top: 0;
}

/* ============================================================
   Bottom Tab Bar  (#tab-bar — sticky inside flex column)
   ============================================================ */
#tab-bar {
  position: relative;        /* never fixed/absolute — stays in flex flow */
  flex-shrink: 0;
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--separator);
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

@media (prefers-color-scheme: dark) {
  #tab-bar { background: #1C1C1E; }
}

#tab-bar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  font-size: 22px; /* emoji size */
  color: var(--label-3);
  padding: 0;
  cursor: pointer;
  min-height: 44px;
  transition: color 0.2s;
}

#tab-bar button.active {
  color: var(--accent);
}

#tab-bar button span {
  font-size: 10px;
  font-weight: 500;
}

/* SVG icons inside tab bar buttons */
#tab-bar button svg {
  width: 24px;
  height: 24px;
  margin-bottom: 1px;
  display: block;
  flex-shrink: 0;
}

/* ── Legacy aliases (keep so any .tab-bar / .tab-btn classes still work) ── */
.tab-bar {
  display: flex;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px 0 0;
  color: var(--label-3);
  transition: color 0.2s;
  gap: 2px;
}

.tab-btn.active { color: var(--accent); }
.tab-icon       { font-size: 22px; line-height: 1; }
.tab-label      { font-size: 10px; font-weight: 500; }

/* ============================================================
   Scroll Content Area
   ============================================================ */
.tab-content {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 0 24px;
}

/* ============================================================
   Grouped iOS Card Sections
   ============================================================ */
.section-header {
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--label-2);
  padding: 8px 16px 4px;
  margin-top: 16px;
}

.ios-card {
  background: var(--surface);
  border-radius: 10px;
  margin: 0 16px 8px;
  overflow: hidden;
}

.ios-row {
  padding: 11px 16px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.ios-row + .ios-row {
  border-top: 0.5px solid var(--separator);
}

.ios-row-label {
  font-size: 17px;
  color: var(--label);
  flex: 1;
}

.ios-row-value {
  font-size: 17px;
  color: var(--label-2);
}

.ios-row-chevron {
  color: var(--label-3);
  font-size: 13px;
}

.ios-row-action {
  color: var(--accent);
  font-size: 17px;
}

.ios-row-destructive {
  color: var(--accent-red);
}

/* ============================================================
   Backward-compat .card (app.js generated content)
   ============================================================ */
.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 20px;
  margin: 0 16px 8px;
}

/* ============================================================
   Inputs
   ============================================================ */
input[type=text],
input[type=password],
input[type=number],
input[type=date],
input[type=time],
input[type=tel],
input[type=email],
input[type=search],
select,
textarea {
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 17px;
  font-family: var(--font);
  color: var(--label);
  outline: none;
  -webkit-appearance: none;
  width: 100%;
}

input[type=text]:focus,
input[type=password]:focus,
input[type=number]:focus,
input[type=date]:focus,
input[type=time]:focus,
input[type=tel]:focus,
input[type=email]:focus,
input[type=search]:focus,
select:focus,
textarea:focus {
  filter: brightness(0.96);
}

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

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-appearance: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
  display: block;
  text-align: center;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--accent);
}

.btn-full {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
}

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

.btn-destructive {
  background: none;
  color: var(--accent-red);
}

.btn-settings {
  background: var(--surface-2);
  color: var(--accent);
  font-size: 15px;
  padding: 10px 16px;
  border-radius: 10px;
}

/* ============================================================
   Record Button
   ============================================================ */
.btn-record {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-red);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  -webkit-appearance: none;
  transition: all 0.2s;
}

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

.btn-record.recording {
  animation: pulse-record 1.5s ease-in-out infinite;
}

/* Inner mic shape: circle → rounded square when recording */
.record-icon {
  display: block;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: border-radius 0.3s ease;
  pointer-events: none;
}

.btn-record.recording .record-icon {
  border-radius: 5px;
}

@keyframes pulse-record {
  0%   { transform: scale(1);    opacity: 1; }
  50%  { transform: scale(1.05); opacity: 0.85; }
  100% { transform: scale(1);    opacity: 1; }
}

.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 0;
}

.record-status {
  font-size: 15px;
  color: var(--label-2);
  font-weight: 400;
}

.record-status.active {
  color: var(--accent-red);
}

/* ============================================================
   Spinner
   ============================================================ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.spinner-dark {
  border-color: rgba(45, 106, 79, 0.2);
  border-top-color: var(--accent);
}

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

/* ============================================================
   Utility: hidden
   ============================================================ */
.hidden {
  display: none !important;
}

/* ============================================================
   Hints
   ============================================================ */
.hint {
  font-size: 13px;
  color: var(--label-2);
  margin-top: 6px;
}

.hint.success {
  color: var(--accent-green);
}

.hint.error {
  color: var(--accent-red);
}

/* ============================================================
   Pills / Tags
   ============================================================ */
.pill {
  display: inline-flex;
  align-items: center;
  background: rgba(45, 106, 79, 0.1);
  color: var(--accent);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 500;
  margin: 2px;
}

/* ============================================================
   Segmented Control
   ============================================================ */
.seg-control {
  display: flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  padding: 7px 12px;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  color: var(--label-2);
  transition: all 0.2s;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--label);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ============================================================
   Stepper
   ============================================================ */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
}

.stepper-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
}

.stepper-val {
  min-width: 32px;
  text-align: center;
  font-size: 17px;
}

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  gap: 12px;
}

.empty-icon {
  font-size: 56px;
  opacity: 0.3;
}

.empty-title {
  font-size: 17px;
  color: var(--label-2);
}

/* ============================================================
   Modal / Bottom Sheet
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--separator);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
  margin-top: 0;
}

/* ============================================================
   Search Field
   ============================================================ */
.search-wrap {
  position: relative;
  margin: 8px 16px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--label-3);
  pointer-events: none;
}

.search-input {
  padding-left: 36px !important;
}

/* ============================================================
   iOS Toggle (Checkbox)
   ============================================================ */
.ios-toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.ios-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.ios-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--label-3);
  border-radius: 31px;
  cursor: pointer;
  transition: background 0.2s;
}

.ios-toggle-slider::before {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.ios-toggle input:checked + .ios-toggle-slider {
  background: var(--accent-green);
}

.ios-toggle input:checked + .ios-toggle-slider::before {
  transform: translateX(20px);
}

/* ============================================================
   Status Badge
   ============================================================ */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.green {
  background: var(--accent-green);
}

.status-dot.orange {
  background: var(--accent-orange);
}

/* ============================================================
   Waveform Animation (dictation)
   ============================================================ */
.waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 30px;
}

.waveform-bar {
  width: 3px;
  border-radius: 2px;
  background: var(--accent-red);
  animation: wave 1s ease-in-out infinite;
}

.waveform-bar:nth-child(1) { animation-delay: 0s;    height: 8px; }
.waveform-bar:nth-child(2) { animation-delay: 0.1s;  height: 16px; }
.waveform-bar:nth-child(3) { animation-delay: 0.2s;  height: 24px; }
.waveform-bar:nth-child(4) { animation-delay: 0.3s;  height: 18px; }
.waveform-bar:nth-child(5) { animation-delay: 0.4s;  height: 10px; }
.waveform-bar:nth-child(6) { animation-delay: 0.15s; height: 20px; }
.waveform-bar:nth-child(7) { animation-delay: 0.25s; height: 14px; }

@keyframes wave {
  0%, 100% { transform: scaleY(1);    opacity: 0.8; }
  50%       { transform: scaleY(0.4); opacity: 0.4; }
}

/* ============================================================
   Input Row (backward compat for app.js)
   ============================================================ */
.input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.input-row label {
  font-size: 13px;
  color: var(--label-2);
  font-weight: 400;
}

/* ============================================================
   Folder Row (backward compat for app.js)
   ============================================================ */
.folder-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  cursor: pointer;
}

.folder-row + .folder-row {
  border-top: 0.5px solid var(--separator);
}

.folder-icon {
  font-size: 22px;
  width: 30px;
  text-align: center;
  flex-shrink: 0;
}

.folder-name {
  font-size: 17px;
  color: var(--label);
  flex: 1;
}

/* ============================================================
   Report Meta (backward compat for app.js)
   ============================================================ */
.report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.meta-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 120px;
}

.meta-field label {
  font-size: 12px;
  color: var(--label-2);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta-field span {
  font-size: 15px;
  color: var(--label);
}

/* ============================================================
   Action Row (backward compat for app.js)
   ============================================================ */
.action-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   Settings Group (backward compat for app.js)
   ============================================================ */
.settings-group {
  background: var(--surface);
  border-radius: 10px;
  margin: 0 16px 8px;
  overflow: hidden;
}

.settings-label {
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--label-2);
  padding: 8px 16px 4px;
  margin-top: 16px;
}

/* ============================================================
   Responsive – phone frame on desktop
   ============================================================ */
@media (min-width: 600px) {
  body {
    background: #E5E5EA;
    align-items: center;
    justify-content: center;
  }

  #app {
    width: 390px;
    max-width: 390px;
    height: 100dvh;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
    border-radius: 0;
    overflow: hidden;
  }

  /* Keep modal sheet constrained to phone frame */
  .modal-sheet {
    max-width: 390px;
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(100%);
  }

  .modal-overlay.open .modal-sheet {
    transform: translateX(-50%) translateY(0);
  }
}

@media (min-width: 600px) and (prefers-color-scheme: dark) {
  body { background: #1C1C1E; }
}

/* ============================================================
   Transitions
   ============================================================ */
a, button {
  transition: all 0.2s ease;
}
