/* The Diamond Reports PWA v2.7 — iOS app shell.
   UI-only layer. PDF generation and V10.3 report markup are untouched. */
:root {
  --app-bg: #f4f4f6;
  --app-surface: #ffffff;
  --app-surface-soft: #f8f8fa;
  --app-label: #171719;
  --app-secondary: #6f7076;
  --app-tertiary: #9a9ba1;
  --app-line: rgba(60,60,67,.10);
  --app-green: #5f7550;
  --app-green-dark: #43563a;
  --app-green-soft: #edf4ea;
  --app-sage: #e8f1e8;
  --app-sand: #f5eee2;
  --app-sand-accent: #ad8d59;
  --app-red: #c94a4a;
  --app-radius: 18px;
  --app-radius-lg: 24px;
  --app-bottom-nav-h: 68px;
  --app-font-en: 'Google Sans Flex', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --app-font-th: 'Google Sans', 'Google Sans Flex', system-ui, sans-serif;
}

html, body {
  background: var(--app-bg) !important;
}

body.ios-shell-active {
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ---------- App pages ---------- */
.ios-page {
  display: none;
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top, 0px)) 16px calc(92px + env(safe-area-inset-bottom, 0px));
  font-family: var(--app-font-en);
  color: var(--app-label);
}

.ios-page.is-active {
  display: block;
}

.ios-home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 20px;
}

.ios-brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.ios-brand-icon {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 5px 16px rgba(37,44,31,.10);
}

.ios-brand-title {
  margin: 0;
  font-size: clamp(25px, 6.5vw, 32px);
  line-height: 1.02;
  letter-spacing: -.042em;
  font-weight: 730;
}

.ios-brand-subtitle {
  margin: 4px 0 0;
  color: var(--app-secondary);
  font-family: var(--app-font-th);
  font-size: 12.5px;
  line-height: 1.35;
}

.ios-home-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 7px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--app-green-soft);
  color: var(--app-green-dark);
  font: 620 11px/1 var(--app-font-en);
}

.ios-home-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5c8a4b;
}

.ios-home-status.offline {
  background: #f9ecec;
  color: #a63b3b;
}

.ios-home-status.offline::before { background: #d04b4b; }

.ios-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 24px 2px 10px;
}

.ios-section-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -.018em;
  font-weight: 680;
}

.ios-link-button {
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--app-secondary);
  font: 540 12px/1 var(--app-font-en);
}

/* ---------- Home report cards ---------- */
.ios-report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ios-report-card {
  position: relative;
  min-height: 190px;
  overflow: hidden;
  padding: 18px 16px 16px;
  border: 0;
  border-radius: 22px;
  text-align: left;
  color: var(--app-label);
  box-shadow: 0 5px 18px rgba(32,32,35,.045);
  transition: transform .14s ease, box-shadow .14s ease;
}

.ios-report-card:active {
  transform: scale(.985);
  box-shadow: 0 2px 10px rgba(32,32,35,.035);
}

.ios-report-card.client { background: linear-gradient(145deg, #eef6ef 0%, #e4efe4 100%); }
.ios-report-card.excursion { background: linear-gradient(145deg, #faf4ea 0%, #f1e7d7 100%); }

.ios-report-card::after {
  content: '';
  position: absolute;
  width: 116px;
  height: 116px;
  right: -25px;
  bottom: -30px;
  border-radius: 50%;
  opacity: .34;
  pointer-events: none;
}
.ios-report-card.client::after { background: #cddfc9; }
.ios-report-card.excursion::after { background: #e4cfad; }

.ios-report-icon {
  position: relative;
  z-index: 1;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: rgba(255,255,255,.72);
  box-shadow: inset 0 0 0 .5px rgba(0,0,0,.04);
}

.ios-report-card.client .ios-report-icon { color: #557b56; }
.ios-report-card.excursion .ios-report-icon { color: #9b7743; }
.ios-report-icon svg { width: 22px; height: 22px; }

.ios-report-card h3 {
  position: relative;
  z-index: 1;
  margin: 14px 0 5px;
  font-size: 19px;
  line-height: 1.08;
  letter-spacing: -.022em;
  font-weight: 690;
}

.ios-report-card p {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 150px;
  color: #64666b;
  font-family: var(--app-font-th);
  font-size: 11.5px;
  line-height: 1.4;
}

.ios-report-arrow {
  position: absolute;
  z-index: 2;
  right: 14px;
  bottom: 14px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 18px;
  line-height: 1;
}
.ios-report-card.client .ios-report-arrow { background: #66875e; }
.ios-report-card.excursion .ios-report-arrow { background: #af8e5b; }

/* ---------- Quick actions ---------- */
.ios-quick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.ios-quick-tile {
  min-width: 0;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 6px;
  border: 0;
  border-radius: 18px;
  background: #fff;
  color: var(--app-label);
  box-shadow: 0 3px 14px rgba(32,32,35,.035);
  font: 590 11px/1.1 var(--app-font-en);
}

.ios-quick-tile:active { transform: scale(.98); }

.ios-quick-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--app-green-soft);
  color: var(--app-green);
}
.ios-quick-icon svg { width: 19px; height: 19px; }

/* ---------- Recent ---------- */
.ios-list-card {
  overflow: hidden;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(32,32,35,.035);
}

.ios-recent-item,
.ios-settings-row {
  width: 100%;
  min-height: 66px;
  display: grid;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--app-label);
  text-align: left;
}

.ios-recent-item {
  grid-template-columns: 40px minmax(0,1fr);
  gap: 11px;
  padding: 11px 13px;
  align-items: start;
}

.ios-recent-item + .ios-recent-item,
.ios-settings-row + .ios-settings-row {
  border-top: .5px solid var(--app-line);
}

.ios-recent-icon,
.ios-settings-icon {
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.ios-recent-icon {
  width: 40px;
  height: 40px;
  background: var(--app-green-soft);
  color: var(--app-green);
}
.ios-recent-icon.excursion { background: #f6efe3; color: var(--app-sand-accent); }
.ios-recent-icon svg, .ios-settings-icon svg { width: 19px; height: 19px; }

.ios-recent-copy { min-width: 0; display: block; }
.ios-recent-head {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  min-width: 0;
}
.ios-recent-title {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  font-size: 13.2px;
  line-height: 1.32;
  font-weight: 650;
}
.ios-recent-meta {
  display: block;
  margin-top: 4px;
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--app-secondary);
  font-size: 11.3px;
  line-height: 1.35;
}
.ios-recent-head .ios-status-chip {
  margin-top: 1px;
}

.ios-status-chip {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--app-green-soft);
  color: var(--app-green-dark);
  font-size: 10px;
  font-weight: 620;
}
.ios-status-chip.draft { background: #f7efe2; color: #8d6f3f; }

.ios-empty-state {
  padding: 24px 16px;
  color: var(--app-secondary);
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
}

.ios-stats-card {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  padding: 14px 8px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(32,32,35,.035);
}
.ios-stat { text-align: center; }
.ios-stat + .ios-stat { border-left: .5px solid var(--app-line); }
.ios-stat strong { display: block; font-size: 19px; font-weight: 690; letter-spacing: -.02em; }
.ios-stat span { display: block; margin-top: 3px; color: var(--app-secondary); font-size: 10.5px; }

/* ---------- More page ---------- */
.ios-page-titlebar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  min-height: 48px;
  margin-bottom: 18px;
}
.ios-page-titlebar h1 {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 680;
  letter-spacing: -.02em;
}
.ios-titlebar-spacer { width: 40px; height: 40px; }

.ios-connection-card {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 94px;
  padding: 16px;
  border-radius: 22px;
  background: linear-gradient(145deg,#eef6ee,#e7f1e8);
}
.ios-connection-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(91,126,79,.12);
  color: #577a4e;
}
.ios-connection-icon svg { width: 23px; height: 23px; }
.ios-connection-card.offline { background: #f9eded; }
.ios-connection-card.offline .ios-connection-icon { background: rgba(184,72,72,.10); color: #b34848; }
.ios-connection-title { font-size: 16px; font-weight: 660; }
.ios-connection-subtitle { margin-top: 3px; color: var(--app-secondary); font-size: 12px; line-height: 1.35; }

.ios-settings-row {
  grid-template-columns: 38px minmax(0,1fr) 18px;
  gap: 11px;
  padding: 11px 13px;
}
.ios-settings-icon {
  width: 38px;
  height: 38px;
  background: var(--app-surface-soft);
  color: #4e5055;
}
.ios-settings-title { font-size: 14px; font-weight: 610; }
.ios-settings-sub { margin-top: 2px; color: var(--app-secondary); font-size: 11.5px; }
.ios-row-chevron { color: var(--app-tertiary); font-size: 20px; font-weight: 300; }

/* ---------- Bottom tab bar ---------- */
.ios-tabbar {
  position: fixed;
  z-index: 10800;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 760px);
  min-height: calc(var(--app-bottom-nav-h) + env(safe-area-inset-bottom,0px));
  display: grid;
  grid-template-columns: repeat(4,1fr);
  align-items: start;
  padding: 7px 8px calc(6px + env(safe-area-inset-bottom,0px));
  border-top: .5px solid var(--app-line);
  background: rgba(250,250,251,.96);
  box-shadow: 0 -4px 20px rgba(0,0,0,.035);
}

@supports (backdrop-filter: blur(10px)) {
  .ios-tabbar {
    background: rgba(250,250,251,.90);
    backdrop-filter: blur(12px) saturate(1.12);
    -webkit-backdrop-filter: blur(12px) saturate(1.12);
  }
}

.ios-tabbar button {
  min-width: 0;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: #9a9ba1;
  font: 540 9.5px/1 var(--app-font-en);
}

.ios-tabbar button svg { width: 21px; height: 21px; stroke-width: 1.7; }
.ios-tabbar button.is-active { color: var(--app-green); }
.ios-tabbar button.is-active .ios-tab-icon-wrap { background: var(--app-green-soft); }
.ios-tab-icon-wrap {
  width: 38px;
  height: 29px;
  display: grid;
  place-items: center;
  border-radius: 999px;
}

/* ---------- Existing report editor as an iOS page ---------- */
#app.ios-report-page {
  display: none;
  width: min(100%,760px) !important;
  min-height: 100dvh;
  padding: calc(max(10px, env(safe-area-inset-top,0px)) + 54px) 14px calc(160px + env(safe-area-inset-bottom,0px)) !important;
}
#app.ios-report-page.is-active { display: block; }

#app.ios-report-page .topbar {
  position: fixed !important;
  z-index: 10700;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%,760px);
  min-height: calc(54px + env(safe-area-inset-top,0px));
  display: grid !important;
  grid-template-columns: 44px minmax(0,1fr) 44px;
  align-items: end !important;
  gap: 4px !important;
  margin: 0 !important;
  padding: max(8px,env(safe-area-inset-top,0px)) 10px 8px !important;
  border-bottom: .5px solid var(--app-line);
  background: rgba(250,250,251,.97);
}

#app.ios-report-page .ios-report-back {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--app-label);
}
#app.ios-report-page .ios-report-back svg { width: 23px; height: 23px; }

#app.ios-report-page .title {
  padding: 0 !important;
  text-align: center;
}
#app.ios-report-page .title h1 {
  margin: 0 !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px !important;
  line-height: 1.05 !important;
  letter-spacing: -.02em !important;
  font-weight: 660 !important;
}
#app.ios-report-page .title p,
#app.ios-report-page .type-chip { display: none !important; }
#app.ios-report-page .top-actions {
  display: flex !important;
  justify-content: flex-end !important;
  align-items: center !important;
  gap: 0 !important;
}
#app.ios-report-page .top-actions > .ios-history-action,
#app.ios-report-page .top-actions > .ios-change-type-action,
#app.ios-report-page .top-actions > .ios-new-action { display: none !important; }
#app.ios-report-page .top-actions .pwa-more-button {
  width: 38px !important;
  min-width: 38px !important;
  height: 38px !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  box-shadow: none !important;
  font-size: 18px !important;
}
#app.ios-report-page .pwa-status-pill { display: none !important; }

#app.ios-report-page .ios-section-label {
  margin: 19px 12px 7px !important;
  color: var(--app-secondary) !important;
  font-size: 10.5px !important;
  font-weight: 630 !important;
  letter-spacing: .04em !important;
}

#app.ios-report-page .card {
  border-radius: 20px !important;
  box-shadow: 0 3px 14px rgba(32,32,35,.028) !important;
}

#app.ios-report-page .meta-card,
#app.ios-report-page .clients-card,
#app.ios-report-page .report-note-card,
#app.ios-report-page .excursion-card {
  overflow: hidden;
  background: #fff !important;
}

#app.ios-report-page input[type="text"],
#app.ios-report-page input[type="date"],
#app.ios-report-page textarea,
#app.ios-report-page select,
#app.ios-report-page .fixed-author,
#app.ios-report-page .location-tag-editor {
  background: #f7f7f9 !important;
  border-radius: 12px !important;
}

#app.ios-report-page textarea { line-height: 1.5 !important; }

.mobile-actionbar {
  z-index: 10750 !important;
  bottom: calc(var(--app-bottom-nav-h) + env(safe-area-inset-bottom,0px)) !important;
  border-top: .5px solid var(--app-line) !important;
  background: rgba(250,250,251,.97) !important;
  box-shadow: 0 -4px 16px rgba(0,0,0,.025) !important;
}
.mobile-actionbar.ios-hidden { display: none !important; }
.mobile-actionbar .mobile-actionbar-inner {
  width: min(100%,760px) !important;
  padding: 8px 12px !important;
  gap: 8px !important;
}
.mobile-actionbar .btn {
  min-height: 44px !important;
  border-radius: 13px !important;
  font-size: 14px !important;
  font-weight: 620 !important;
}
.mobile-actionbar .btn-primary {
  background: var(--app-green-dark) !important;
  color: #fff !important;
}
.mobile-actionbar .btn-secondary {
  background: #eeeef1 !important;
  color: var(--app-label) !important;
  border: 0 !important;
}

/* Make legacy chooser a polished report picker when invoked. */
.report-type-panel {
  background: var(--app-bg) !important;
}
.type-options {
  grid-template-columns: 1fr 1fr !important;
}
.type-card {
  min-height: 180px !important;
  align-content: space-between;
}
.type-card:first-child { background: linear-gradient(145deg,#eef6ef,#e4efe4) !important; }
.type-card.excursion { background: linear-gradient(145deg,#faf4ea,#f1e7d7) !important; }
.type-card-kicker { color: var(--app-secondary) !important; }
.type-card-action { color: var(--app-green-dark) !important; }
.type-card.excursion .type-card-action { color: #8b6a3b !important; }

/* History stays as an iOS sheet, but aligns with app palette. */
.modal,
.pwa-modal {
  background: var(--app-bg) !important;
}
.history-item,
.ios-quick-action,
.pwa-note,
.pwa-draft-meta {
  background: #fff !important;
}

@media (max-width: 430px) {
  .ios-page { padding-left: 13px; padding-right: 13px; }
  .ios-brand-title { font-size: 25px; }
  .ios-brand-subtitle { font-size: 11.5px; }
  .ios-home-status { padding-inline: 8px; }
  .ios-report-grid { gap: 10px; }
  .ios-report-card { min-height: 178px; padding: 16px 14px 14px; }
  .ios-report-card h3 { font-size: 17.5px; }
  .ios-report-card p { max-width: 128px; font-size: 10.8px; }
  .ios-quick-grid { gap: 7px; }
  .ios-quick-tile { min-height: 82px; padding-inline: 3px; font-size: 10px; }
  .ios-quick-icon { width: 34px; height: 34px; }
}

@media (max-width: 350px) {
  .ios-report-grid { grid-template-columns: 1fr; }
  .ios-report-card { min-height: 150px; }
  .ios-report-card p { max-width: 190px; }
  .ios-quick-grid { grid-template-columns: repeat(2,1fr); }
}

@media (min-width: 720px) {
  .ios-page { padding-top: 28px; }
  .ios-home-header { margin-top: 8px; }
  .ios-report-card { min-height: 210px; }
}

@media (prefers-reduced-motion: reduce) {
  .ios-report-card,
  .ios-quick-tile { transition: none !important; }
}


/* v2.5 — modal sheets own the bottom edge; do not let the tab bar overlap them. */
body.tdr-report-type-open .ios-tabbar,
body.tdr-pwa-sheet-open .ios-tabbar,
body.tdr-history-open .ios-tabbar,
body.tdr-pdf-ready-open .ios-tabbar {
  transform: translate(-50%, calc(100% + env(safe-area-inset-bottom, 0px))) !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.tdr-report-type-open .report-type-panel,
body.tdr-pwa-sheet-open .pwa-modal {
  padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px)) !important;
}

.history-loading-state {
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  padding: 24px 18px;
  border-radius: 18px;
  background: #fff;
  color: var(--app-text);
  text-align: left;
}
.history-loading-state strong {
  display: block;
  font: 650 14px/1.25 var(--app-font-en);
}
.history-loading-state span:not(.history-loading-spinner) {
  display: block;
  margin-top: 4px;
  color: var(--app-secondary);
  font: 430 12px/1.4 var(--app-font-en);
}
.history-loading-spinner {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border: 2.5px solid rgba(76, 104, 66, .16);
  border-top-color: var(--app-green);
  border-radius: 50%;
  animation: tdr-history-spin .7s linear infinite;
}
@keyframes tdr-history-spin { to { transform: rotate(360deg); } }

.history-actions .history-download {
  background: rgba(82, 111, 72, .10) !important;
  color: #45643e !important;
}


/* v2.7 — workflow polish: visible chooser close, stable loading, compact history actions. */
body.tdr-report-type-open .report-type-panel {
  padding-top: 22px !important;
}
body.tdr-report-type-open .type-brand,
body.tdr-report-type-open #reportTypeTitle,
body.tdr-report-type-open .type-intro {
  padding-right: 42px;
}

.history-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 8px !important;
}
.history-actions .history-delete {
  grid-column: auto !important;
  width: 100%;
}
.history-actions.draft-only .history-edit,
.history-actions.draft-only .history-delete {
  grid-column: auto !important;
}
.history-actions .btn {
  width: 100%;
}

@media (max-width: 360px) {
  .history-actions { gap: 6px !important; }
  .history-actions .btn { font-size: 10.5px !important; padding-inline: 7px !important; }
}
