/* Card Base */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
  position: relative;
  max-width: 100%;
  box-sizing: border-box;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

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

.card-title-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Badges & Tags */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  line-height: 1;
}

.badge-normal {
  background-color: var(--accent-emerald-light);
  color: var(--accent-emerald);
}

.badge-warning {
  background-color: var(--accent-amber-light);
  color: var(--accent-amber);
}

.badge-danger {
  background-color: var(--accent-rose-light);
  color: var(--accent-rose);
}

.badge-info {
  background-color: var(--primary-light);
  color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #2563eb);
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), #1d4ed8);
  box-shadow: 0 4px 14px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
  border-color: var(--border-subtle);
}
.btn-secondary:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-focus);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* Pill Visualizer (Medisafe / TOM Style) */
.pill-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  position: relative;
}

.pill-shape {
  width: 22px;
  height: 12px;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  display: flex;
}

.pill-shape.round {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.pill-shape.capsule {
  width: 24px;
  height: 11px;
  border-radius: 6px;
  overflow: hidden;
}

.pill-half {
  flex: 1;
  height: 100%;
}

/* Medication Item Card */
.med-item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-block-end: 0.65rem;
  transition: all var(--transition-fast);
}

.med-item-card:hover {
  border-color: rgba(255, 255, 255, 0.16);
  transform: translateX(2px);
}

.med-item-card.taken {
  opacity: 0.7;
  border-color: rgba(16, 185, 129, 0.3);
  background-color: rgba(16, 185, 129, 0.04);
}

.med-details {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.med-info h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.med-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.med-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modals & Dialogs (Modern HTML5 <dialog>) */
dialog.app-dialog {
  margin: auto;
  padding: 0;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: calc(100% - 2rem);
  backdrop-filter: blur(16px);
}

dialog::backdrop {
  background: rgba(10, 15, 26, 0.75);
  backdrop-filter: blur(6px);
}

.dialog-header {
  padding: 1.25rem 1.5rem;
  border-block-end: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-height: 75vh;
  overflow-y: auto;
}

.dialog-footer {
  padding: 1rem 1.5rem;
  border-block-start: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.form-label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Data Tables */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: block;
}

.health-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.health-table th {
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.health-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.health-table tr:hover td {
  background-color: var(--bg-surface-hover);
}

.health-table tr.alert-row td {
  background-color: rgba(244, 63, 94, 0.05);
}

.table-num {
  font-family: var(--font-family-mono);
  font-weight: 600;
}

/* Upload Dropzone & File Preview */
.upload-dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1rem;
  text-align: center;
  background: rgba(15, 23, 42, 0.4);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.upload-dropzone:hover, .upload-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
}

.upload-file-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
}

/* Dynamic Biomarker Input Table */
.biomarker-table-input {
  width: 100%;
  border-collapse: collapse;
}

.biomarker-table-input th {
  padding: 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.biomarker-table-input td {
  padding: 0.4rem 0.25rem;
}

.biomarker-table-input input, .biomarker-table-input select {
  padding: 0.4rem 0.5rem;
  font-size: 0.825rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: #fff;
  width: 100%;
}

.biomarker-table-input input:focus {
  border-color: var(--primary);
  outline: none;
}

/* More Menu Grid */
.more-menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
}

.more-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 0.75rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: center;
  gap: 0.6rem;
  transition: all var(--transition-fast);
  color: var(--text-main);
  text-decoration: none;
}

.more-menu-item:hover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
  transform: translateY(-2px);
}

.more-menu-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.more-menu-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
}

.more-menu-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}

@keyframes pulse-sos {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.5);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 8px rgba(244, 63, 94, 0);
  }
}
