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

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-soft: #e8f0fe;
  --danger: #d93025;
  --danger-dark: #b3261e;
  --danger-soft: #fce8e6;
  --success: #188038;
  --success-soft: #e6f4ea;
  --warning: #f9ab00;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --shadow-xl: 0 10px 30px rgba(0,0,0,0.2);
}

html {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.btn-sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.btn-sync-chip:active {
  transform: scale(0.96);
  background: rgba(255,255,255,0.25);
}

.btn-sync-chip:disabled {
  opacity: 0.7;
  cursor: wait;
}

.btn-sync-chip.syncing .sync-icon {
  animation: spin 1s linear infinite;
}

.sync-icon {
  display: inline-block;
  font-size: 0.9rem;
  line-height: 1;
}

.sync-label {
  display: none;
}

@media (min-width: 360px) {
  .sync-label {
    display: inline;
  }
}

.sync-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warning);
  color: #202124;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 40px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.section-separated {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s, opacity 0.2s, background 0.2s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

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

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow);
}

.btn-primary:not(:disabled):active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow);
}

.btn-danger {
  background: var(--danger);
  color: white;
  box-shadow: var(--shadow);
}

.btn-danger:not(:disabled):active {
  background: var(--danger-dark);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: var(--radius-xs);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

#form-section {
  margin-bottom: 8px;
}

.image-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--primary-soft);
  border: 2px dashed var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-bottom: 20px;
}

.image-placeholder:active {
  transform: scale(0.99);
  background: #d2e3fc;
}

.image-placeholder.has-image {
  border-style: solid;
  border-color: transparent;
}

.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 16px;
}

.placeholder-content span {
  font-weight: 600;
  font-size: 1rem;
}

.placeholder-content small {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.camera-icon {
  width: 48px;
  height: 48px;
  fill: currentColor;
  opacity: 0.8;
}

.image-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  flex: 1 1 auto;
  min-width: 90px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

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

.chip.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

#desc-wrapper {
  position: relative;
}

#desc-wrapper textarea {
  padding-right: 56px;
  resize: vertical;
  min-height: 90px;
}

#btn-dictate {
  position: absolute;
  bottom: 8px;
  right: 8px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
  flex-shrink: 0;
}

.btn-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.btn-icon:active {
  transform: scale(0.9);
}

.btn-icon:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.btn-icon.listening {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}

.status-hidden {
  display: none !important;
}

#dictation-status {
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 6px;
  margin-bottom: 4px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

#dictation-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.2s infinite;
}

.actions {
  margin-top: 8px;
}

.actions .btn {
  width: 100%;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.hidden {
  display: none !important;
}

#records-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 16px;
  font-size: 0.95rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.record-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.1s;
}

.record-card:active {
  box-shadow: var(--shadow-lg);
  transform: scale(0.995);
}

.record-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
}

.record-card-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  background: #e8eaed;
  flex-shrink: 0;
}

.record-card-info {
  flex: 1;
  min-width: 0;
}

.record-card-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-card-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.record-card-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.record-card-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 500;
}

.record-card-arrow {
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: transform 0.2s;
}

.record-card.expanded .record-card-arrow {
  transform: rotate(180deg);
}

.record-card-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.record-card.expanded .record-card-body {
  display: block;
}

.record-card-body .desc-text {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-top: 14px;
  margin-bottom: 14px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.record-card-body .card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.record-card-body .card-actions .btn {
  flex: 1;
  font-size: 0.85rem;
  padding: 10px 14px;
  min-width: 100px;
}

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s, transform 0.3s;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
}

.toast-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  border: none;
  cursor: pointer;
}

.modal-content {
  position: relative;
  max-width: 100%;
  max-height: 90vh;
  z-index: 1;
}

.modal-content img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-xl);
  object-fit: contain;
}

.modal-close {
  position: absolute;
  top: -48px;
  right: 0;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(4px);
}

#btn-load-more {
  width: 100%;
  margin-top: 8px;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.1); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #e8eaed;
    --text-secondary: #9aa0a6;
    --border: #3c4043;
    --primary: #8ab4f8;
    --primary-dark: #aecbfa;
    --primary-soft: rgba(138,180,248,0.15);
    --danger: #f28b82;
    --danger-dark: #f6aea9;
    --danger-soft: rgba(242,139,130,0.15);
    --success: #81c995;
    --success-soft: rgba(129,201,149,0.15);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-xl: 0 10px 30px rgba(0,0,0,0.5);
  }

  .image-placeholder {
    background: rgba(138,180,248,0.12);
  }

  .image-placeholder:active {
    background: rgba(138,180,248,0.22);
  }

  .validation-hint {
    background: #2d2d2d;
  }

  .record-card-thumb {
    background: #2d2d2d;
  }
}
