:root {
  --leaf: #2f7d59;
  --leaf-deep: #1f543c;
  --leaf-light: #9fd0b4;
  --ink: #20231f;
  --muted: #6f7168;
  --line: #ded8ca;
  --cream: #f7f4ec;
  --paper: #fffdf8;
  --shadow: 0 8px 24px rgba(32, 35, 31, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sans: "Fredoka", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cream);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(32, 35, 31, 0.06);
}

.app-header .logo {
  height: 32px;
  width: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  background: var(--cream);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--leaf);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.btn-logout:hover {
  background: var(--cream);
  color: var(--ink);
}

/* Content */
.app-content {
  flex: 1;
  padding: 1.5rem 1.25rem;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* Login Screen */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 1.25rem;
  background: linear-gradient(135deg, #2f7d59 0%, #1f543c 100%);
  color: white;
}

.login-logo {
  height: 48px;
  margin-bottom: 1rem;
  filter: brightness(0) invert(1);
}

.login-title {
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  text-align: center;
}

.login-subtitle {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  margin: 0 0 2.5rem;
  text-align: center;
}

.login-box {
  background: var(--paper);
  border-radius: 24px;
  padding: 1.75rem 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-label {
  display: block;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 2rem;
}

.demo-accounts {
  display: grid;
  gap: 0.75rem;
}

.demo-account {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.demo-account:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--leaf);
}

.demo-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--leaf);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.demo-account.staff .demo-avatar {
  background: #2a784f;
}

.demo-info {
  flex: 1;
}

.demo-name {
  display: block;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.15rem;
}

.demo-role {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.demo-badge {
  background: var(--leaf);
  color: white;
  font-size: 0.7rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.demo-account.staff .demo-badge {
  background: #2a784f;
}

.login-note {
  margin: 1.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1.35rem;
  background: var(--leaf);
  color: white;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(47, 125, 89, 0.3);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(47, 125, 89, 0.4);
  background: var(--leaf-deep);
}

.btn-secondary {
  background: var(--cream);
  color: var(--ink);
  box-shadow: none;
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: var(--paper);
  box-shadow: var(--shadow);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  font-size: 1.1rem;
}

/* Cards */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 4px 16px rgba(32, 35, 31, 0.06);
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

.card-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.25rem 0 0;
}

.card-section {
  margin-bottom: 1.5rem;
}

.card-section:last-child {
  margin-bottom: 0;
}

.card-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--leaf);
  margin: 0 0 0.75rem;
}

/* Field Grid */
.field-grid {
  display: grid;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.field-value {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}

.field-value.highlight {
  color: var(--leaf);
  font-size: 1.15rem;
}

/* Form */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.85rem 1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  transition: all 0.2s var(--ease);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--leaf);
  box-shadow: 0 0 0 3px rgba(47, 125, 89, 0.12);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.message-item {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
}

.message-item.unread {
  border-color: var(--leaf);
  box-shadow: inset 3px 0 0 var(--leaf);
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.message-topic {
  font-weight: 700;
  color: var(--ink);
}

.message-time {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.message-body {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
}

.send-ok {
  background: #e7f2eb;
  color: var(--leaf-deep);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  font-weight: 600;
  margin-bottom: 1rem;
}

.client-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem;
  margin-bottom: 1.25rem;
}

.client-tab {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.75rem 0.5rem;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
}

.client-tab.active {
  background: var(--leaf);
  color: #fff;
  box-shadow: 0 4px 14px rgba(47, 125, 89, 0.28);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.bubble {
  border-radius: 18px;
  padding: 0.9rem 1rem;
  max-width: 100%;
}

.bubble.theirs {
  background: var(--paper);
  border: 1px solid var(--line);
}

.bubble.mine {
  background: #e7f2eb;
  border: 1px solid rgba(47, 125, 89, 0.2);
}

.thread-preview {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.65rem;
  cursor: pointer;
}

.thread-preview.unread {
  border-color: var(--leaf);
  box-shadow: inset 3px 0 0 var(--leaf);
}

.reply-box .form-label { margin-top: 0.75rem; }
.reply-box .form-label:first-child { margin-top: 0; }

.symptom-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.symptom {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--cream);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  color: var(--ink);
}

.symptom.on {
  background: var(--leaf);
  border-color: var(--leaf);
  color: #fff;
}

.form-label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.form-label.check input { width: auto; }

.diagnosis ul { padding-left: 1.2rem; color: var(--ink); }

.ai-steps {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
  color: var(--ink);
}

.ai-steps li { margin: 0.35rem 0; }

.mb-1 { margin-bottom: 1rem; }

/* Photo Upload */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.photo-slot {
  aspect-ratio: 4 / 3;
  background: var(--cream);
  border: 2px dashed var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  position: relative;
  overflow: hidden;
}

.photo-slot:hover {
  border-color: var(--leaf);
  background: rgba(47, 125, 89, 0.05);
}

.photo-slot.has-image {
  border-style: solid;
  border-color: var(--leaf);
}

.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-icon {
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.photo-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: var(--cream);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-badge.active {
  background: #e7f2eb;
  color: var(--leaf-deep);
}

.status-badge.pending {
  background: #fff3e0;
  color: #e65100;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* List */
.list {
  display: grid;
  gap: 0.75rem;
}

.list-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
}

.list-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--leaf);
}

.list-item-content {
  flex: 1;
}

.list-item-title {
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.list-item-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
}

.list-item-arrow {
  color: var(--leaf);
  font-size: 1.25rem;
  font-weight: 700;
}

/* Page Header */
.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
  color: var(--ink);
}

.page-subtitle {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--ink);
}

.empty-text {
  font-size: 0.95rem;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--leaf);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Utility Classes */
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.mb-2 { margin-bottom: 2rem; }

/* Back Link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--leaf);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  padding: 0.5rem 0;
  transition: gap 0.25s var(--ease);
}

.back-link:hover {
  gap: 0.35rem;
}

/* Responsive */
@media (min-width: 640px) {
  .app-content {
    padding: 2rem 1.5rem;
  }
  
  .field-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .photo-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* PWA Safe Area */
@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(1rem + env(safe-area-inset-top));
    padding-left: calc(1.25rem + env(safe-area-inset-left));
    padding-right: calc(1.25rem + env(safe-area-inset-right));
  }
  
  .app-content {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    padding-left: calc(1.25rem + env(safe-area-inset-left));
    padding-right: calc(1.25rem + env(safe-area-inset-right));
  }
}
