/* Dose Tracker Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #333;
  line-height: 1.5;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

header {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin-bottom: 24px;
}

header h1 {
  color: #4a90d9;
  font-size: 1.8rem;
}

.btn-settings {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  padding: 0;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-settings:hover {
  background: #e0e0e0;
  color: #555;
}

h2 {
  font-size: 1.1rem;
  color: #555;
  margin: 0;
}

/* Add Medication Form */
.add-medication {
  background: white;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}

.add-medication h2 {
  margin-bottom: 12px;
}

#add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-form-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.add-form-inputs input {
  flex: 1;
  min-width: 120px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
}

.add-form-inputs input:focus {
  outline: none;
  border-color: #4a90d9;
}

.add-form-actions {
  display: flex;
  gap: 8px;
}

.add-form-actions button {
  flex: 1;
  padding: 12px 24px;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.add-form-actions button:hover {
  background: #3a7bc8;
}

/* Camera Button */
.btn-camera {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  background: #9b59b6;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-camera:hover {
  background: #8e44ad;
}

.btn-camera.btn-library {
  background: #3498db;
}

.btn-camera.btn-library:hover {
  background: #2980b9;
}

.btn-camera.processing {
  background: #7d3c98;
  opacity: 0.8;
  pointer-events: none;
}

.btn-camera.processing::after {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 6px;
}

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

/* Pending Images */
.pending-images {
  margin-top: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
}

.pending-images-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: #555;
}

.btn-clear-images {
  padding: 4px 10px;
  background: #f0f0f0;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  color: #888;
  cursor: pointer;
}

.btn-clear-images:hover {
  background: #e0e0e0;
  color: #555;
}

.pending-images-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pending-image-thumb {
  width: 48px;
  height: 48px;
  background: #9b59b6;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pending-image-thumb::after {
  content: '';
  width: 24px;
  height: 24px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 20 20'%3E%3Cpath d='M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V5a2 2 0 00-2-2H4zm12 12H4l4-8 3 6 2-4 3 6z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.pending-image-add {
  width: 48px;
  height: 48px;
  background: #e0e0e0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.pending-image-add:hover {
  background: #d0d0d0;
}

.pending-image-add span {
  font-size: 1.5rem;
  color: #888;
}

.scan-options {
  display: flex;
  gap: 8px;
}

.scan-provider-select {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
}

.scan-provider-select:focus {
  outline: none;
  border-color: #9b59b6;
}

.btn-scan-all {
  flex: 1;
  padding: 12px;
  background: #9b59b6;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-scan-all:hover {
  background: #8e44ad;
}

.btn-scan-all:disabled {
  background: #7d3c98;
  opacity: 0.7;
  cursor: not-allowed;
}

/* Scan Status */
.scan-status {
  margin-top: 8px;
  padding: 8px 12px;
  background: #e8f5e9;
  color: #2e7d32;
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
}

.scan-status.error {
  background: #ffebee;
  color: #c62828;
}

.scan-status.hidden {
  display: none;
}

/* Search Section */
.search-section {
  margin-bottom: 16px;
}

#search-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: white;
}

#search-input:focus {
  outline: none;
  border-color: #4a90d9;
}

/* Medications List */
.medications-list {
  background: white;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.medications-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.btn-add-compact {
  padding: 6px 12px;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-add-compact:hover {
  background: #3a7bc8;
}

.empty-state {
  text-align: center;
  color: #888;
  padding: 24px;
}

#med-list {
  list-style: none;
}

.medication-item {
  padding: 16px;
  border-bottom: 1px solid #eee;
}

.medication-item.highlight-new {
  animation: highlight-fade 10s ease-out forwards;
}

@keyframes highlight-fade {
  0% {
    background-color: #d4edda;
  }
  100% {
    background-color: transparent;
  }
}

.medication-item.highlight-dosed {
  animation: highlight-dosed-pulse 2s ease-out forwards;
}

@keyframes highlight-dosed-pulse {
  0% {
    background-color: #e3f2fd;
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(74, 144, 217, 0.3);
  }
  50% {
    background-color: #bbdefb;
  }
  100% {
    background-color: transparent;
    transform: scale(1);
    box-shadow: none;
  }
}

.medication-item:last-child {
  border-bottom: none;
}

.med-row {
  display: flex;
  gap: 12px;
}

.med-main {
  flex: 1;
  min-width: 0;
}

.med-secondary-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: flex-start;
  padding-top: 2px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  background: #f0f0f0;
  border: none;
  border-radius: 6px;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: #e0e0e0;
  color: #555;
}

.btn-icon-danger:hover {
  background: #ffebee;
  color: #e74c3c;
}

.med-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.med-name {
  font-weight: 600;
  font-size: 1.1rem;
  color: #333;
}

.med-interval {
  font-size: 0.85rem;
  color: #888;
  background: #f0f0f0;
  padding: 2px 8px;
  border-radius: 12px;
}

.med-status {
  margin-bottom: 12px;
}

.last-dose, .next-dose-container {
  display: flex;
  gap: 6px;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.label {
  color: #888;
}

.value {
  color: #555;
}

.value.clickable {
  color: #4a90d9;
  cursor: pointer;
  text-decoration: underline;
}

.value.clickable:hover {
  color: #3a7bc8;
}

.next-dose {
  font-weight: 600;
}

.next-dose.available {
  color: #2ecc71;
}

.next-dose.waiting {
  color: #e67e22;
}

.overdue {
  font-size: 0.85rem;
  font-weight: 500;
  color: #c0392b;
  background: #ffebee;
  padding: 2px 8px;
  border-radius: 12px;
  margin-left: 8px;
}

.med-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.med-actions button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.2s;
}

.med-actions button:hover {
  opacity: 0.85;
}

.btn-dose {
  background: #2ecc71;
  color: white;
}

.btn-history {
  background: #9b59b6;
  color: white;
}

.error {
  color: #e74c3c;
  text-align: center;
  padding: 24px;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  font-size: 1.1rem;
  color: #333;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #888;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: #333;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: white;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #4a90d9;
}

.field-hint {
  margin-top: 4px;
  font-size: 0.8rem;
  color: #888;
}

.settings-version {
  text-align: right;
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 12px;
}

.notification-enabled {
  color: #2e7d32 !important;
}

.notification-denied {
  color: #c62828 !important;
}

.btn-enable-notifications {
  width: 100%;
  padding: 10px 16px;
  background: #9b59b6;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-enable-notifications:hover {
  background: #8e44ad;
}

/* In-app dose alert banner */
.dose-alert {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 2000;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.dose-alert-text {
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

.dose-alert-dismiss {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 12px;
  transition: background 0.2s;
}

.dose-alert-dismiss:hover {
  background: rgba(255, 255, 255, 0.3);
}

.settings-description {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: #666;
  line-height: 1.5;
}

.settings-description a {
  color: #4a90d9;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-cancel {
  background: #f0f0f0;
  color: #555;
}

.btn-save, .btn-add-dose {
  background: #4a90d9;
  color: white;
}

.btn-save:hover, .btn-add-dose:hover {
  background: #3a7bc8;
}

/* Dose History List */
.dose-list {
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
}

.dose-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid #eee;
}

.dose-item:last-child {
  border-bottom: none;
}

.dose-time {
  font-size: 0.95rem;
  color: #333;
}

.dose-actions {
  display: flex;
  gap: 6px;
}

.dose-actions button {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-edit-dose {
  background: #f0f0f0;
  color: #555;
}

.btn-delete-dose {
  background: #ffebee;
  color: #e74c3c;
}

.btn-delete-dose:hover {
  background: #e74c3c;
  color: white;
}

.loading {
  text-align: center;
  color: #888;
  padding: 24px;
}

/* Debug Log Section */
.debug-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #eee;
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.debug-header h4 {
  margin: 0;
  font-size: 0.95rem;
  color: #555;
}

.btn-clear-log {
  padding: 4px 10px;
  background: #f0f0f0;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  color: #666;
  cursor: pointer;
}

.btn-clear-log:hover {
  background: #e0e0e0;
}

.debug-empty {
  color: #888;
  font-size: 0.85rem;
  font-style: italic;
}

.debug-log {
  max-height: 200px;
  overflow-y: auto;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 8px;
}

.debug-entry {
  display: flex;
  gap: 8px;
  padding: 8px;
  margin-bottom: 6px;
  background: white;
  border-radius: 4px;
  font-size: 0.8rem;
  border-left: 3px solid #ccc;
}

.debug-entry:last-child {
  margin-bottom: 0;
}

.debug-request {
  border-left-color: #4a90d9;
}

.debug-response {
  border-left-color: #2ecc71;
}

.debug-error {
  border-left-color: #e74c3c;
}

.debug-parsed {
  border-left-color: #9b59b6;
}

.debug-notification {
  border-left-color: #f39c12;
}

.debug-time {
  color: #888;
  white-space: nowrap;
  font-size: 0.75rem;
}

.debug-content {
  flex: 1;
  word-break: break-word;
}

.debug-content strong {
  color: #333;
}

.debug-content details {
  margin-top: 4px;
}

.debug-content summary {
  cursor: pointer;
  color: #4a90d9;
  font-size: 0.75rem;
  display: inline;
}

.btn-copy-body {
  margin-left: 8px;
  padding: 2px 8px;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 3px;
  font-size: 0.7rem;
  cursor: pointer;
  vertical-align: middle;
}

.btn-copy-body:hover {
  background: #3a7bc8;
}

.debug-content pre {
  margin-top: 4px;
  padding: 6px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.7rem;
  white-space: pre-wrap;
  max-height: 150px;
}

/* Responsive */
@media (max-width: 480px) {
  #app {
    padding: 12px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .add-form-inputs {
    flex-direction: column;
  }

  .add-form-inputs input {
    width: 100%;
  }

  .add-form-actions {
    flex-direction: row;
  }

  .add-form-actions button,
  .btn-camera {
    flex: 1;
    padding: 12px 12px;
  }

  .med-actions {
    justify-content: stretch;
  }

  .med-actions button {
    flex: 1;
    text-align: center;
    padding: 8px 8px;
    font-size: 0.8rem;
  }

  .modal {
    max-height: 90vh;
  }

  .dose-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .dose-actions {
    width: 100%;
  }

  .dose-actions button {
    flex: 1;
  }

  .med-secondary-actions {
    flex-direction: row;
  }
}
