/* Daily Visit Report — mobile-first, system-native feel */

:root {
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.72);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --positive: #34c759;
  --positive-soft: rgba(52, 199, 89, 0.14);
  --warning: #ff9f0a;
  --border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.12);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --nav-height: 72px;
  --header-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-glass: rgba(28, 28, 30, 0.82);
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #636366;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.2);
  --positive: #30d158;
  --positive-soft: rgba(48, 209, 88, 0.18);
  --border: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.47;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: calc(12px + var(--safe-top)) 20px 12px;
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.brand-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Search */
.search-wrap {
  margin-top: 12px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 16px 0 42px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: box-shadow var(--transition);
}

.search-input:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

/* Main content */
.main {
  padding: 16px 20px 24px;
}

.view {
  display: none;
  animation: fadeIn 0.4s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.stat-card.featured {
  grid-column: span 2;
  background: linear-gradient(135deg, var(--accent) 0%, #005bb5 100%);
  color: #fff;
  border: none;
}

.stat-card.featured .stat-label,
.stat-card.featured .stat-sub {
  color: rgba(255, 255, 255, 0.75);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-card:not(.featured) .stat-value {
  font-size: 24px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* Section */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-link {
  font-size: 15px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

/* Date chips */
.date-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 16px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.date-filter::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

[data-theme="dark"] .chip.active {
  background: #f5f5f7;
  color: #000;
}

/* Visit cards */
.visit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.visit-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s, box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.visit-card:active {
  transform: scale(0.98);
}

.visit-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.visit-org {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.visit-contact {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.visit-badge {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--positive-soft);
  color: var(--positive);
  text-transform: capitalize;
}

.visit-purpose {
  font-size: 14px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
}

.visit-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.visit-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.visit-meta svg {
  width: 14px;
  height: 14px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 56px;
  height: 56px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

/* Detail sheet */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.sheet-overlay.open {
  opacity: 1;
  visibility: visible;
}

.detail-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  max-height: 92dvh;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.detail-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 5px;
  background: var(--text-tertiary);
  border-radius: 3px;
  margin: 10px auto 0;
  opacity: 0.4;
}

.sheet-header {
  position: relative;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sheet-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding-right: 40px;
}

.sheet-header p {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.sheet-close {
  position: absolute;
  top: 20px;
  right: 16px;
}

.sheet-body {
  overflow-y: auto;
  padding: 16px 20px calc(24px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.detail-group {
  margin-bottom: 20px;
}

.detail-group-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-row dt {
  color: var(--text-secondary);
  flex-shrink: 0;
  max-width: 42%;
}

.detail-row dd {
  text-align: right;
  font-weight: 500;
  word-break: break-word;
}

.notes-block {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}

/* Report view */
.report-hero {
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.report-hero h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.report-hero .date-range {
  font-size: 15px;
  color: var(--text-secondary);
}

.report-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  margin-bottom: 20px;
}

.report-table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-size: 13px;
}

.report-table th,
.report-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.report-table th {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  background: var(--bg);
  position: sticky;
  top: 0;
}

.report-table tr:last-child td {
  border-bottom: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 50px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s, opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--border);
  margin-top: 10px;
}

/* Form */
.form-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: box-shadow var(--transition);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-color: var(--accent);
}

.form-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
  max-width: calc(100% - 40px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 8px;
  z-index: 150;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 16px;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--transition);
}

.nav-item.active {
  color: var(--accent);
}

.nav-item svg {
  width: 24px;
  height: 24px;
}

/* Print */
@media print {
  .header-actions,
  .bottom-nav,
  .search-wrap,
  .date-filter,
  .sheet-overlay,
  .detail-sheet,
  .icon-btn,
  .section-link {
    display: none !important;
  }

  .app {
    max-width: none;
    padding-bottom: 0;
  }

  .view {
    display: block !important;
  }

  body {
    background: #fff;
    color: #000;
  }
}

@media (min-width: 481px) {
  body {
    background: linear-gradient(180deg, #e8e8ed 0%, var(--bg) 120px);
  }

  [data-theme="dark"] body {
    background: linear-gradient(180deg, #1a1a1c 0%, var(--bg) 120px);
  }

  .app {
    box-shadow: var(--shadow-lg);
    margin-top: 24px;
    margin-bottom: 24px;
    border-radius: var(--radius-xl);
    overflow: hidden;
    min-height: calc(100dvh - 48px);
  }

  .header,
  .bottom-nav {
    border-radius: 0;
  }
}
