:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --primary-dark: #075985;
  --accent: #0d9488;
  --accent-light: #ccfbf1;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --card-bg: #ffffff;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--slate-100);
  color: var(--slate-800);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 80px;
}

/* Header */
.app-header {
  background: var(--slate-900);
  color: white;
  padding: 14px 18px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-md);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #0284c7, #0d9488);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--slate-400);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Sync status badge in header */
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--slate-300);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.sync-dot.synced {
  background: #22c55e;
}

.sync-dot.syncing {
  background: #38bdf8;
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

/* Main Container */
.main-content {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  flex: 1;
}

/* Bottom Tab Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-around;
  padding: 6px 4px env(safe-area-inset-bottom, 8px);
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  color: var(--slate-500);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  min-width: 68px;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 2;
}

.nav-item.active {
  color: var(--primary);
  font-weight: 700;
}

.nav-item.active svg {
  stroke: var(--primary);
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--slate-200);
}

/* Today Featured Card */
.today-card {
  background: linear-gradient(145deg, #0f172a, #1e293b);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.today-card::after {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(2, 132, 199, 0.25) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.today-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.today-badge {
  background: rgba(2, 132, 199, 0.3);
  color: #38bdf8;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
  margin-bottom: 4px;
}

.today-date {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.today-day-number {
  font-size: 0.85rem;
  color: var(--slate-400);
}

.dose-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

@media (max-width: 500px) {
  .dose-action-grid {
    grid-template-columns: 1fr;
  }
}

.dose-box {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.dose-box.logged {
  background: rgba(22, 163, 74, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
}

.dose-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.dose-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate-300);
}

.dose-time-display {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: white;
  margin-bottom: 10px;
}

.dose-time-display.empty {
  color: var(--slate-500);
  font-size: 1.1rem;
  font-weight: 500;
}

.btn-dose-action {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-log-now {
  background: var(--primary);
  color: white;
}

.btn-log-now:hover {
  background: var(--primary-hover);
}

.btn-edit-dose {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.btn-edit-dose:hover {
  background: rgba(255, 255, 255, 0.2);
}

.today-comment-bar {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--slate-300);
}

.btn-chip {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 0.78rem;
  cursor: pointer;
}

/* Week Selector Tabs */
.week-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.week-btn {
  flex: 1;
  min-width: 80px;
  padding: 10px 12px;
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--slate-600);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.week-btn.active {
  background: var(--slate-900);
  color: white;
  border-color: var(--slate-900);
  box-shadow: var(--shadow-sm);
}

/* Daily Log Table / Cards */
.days-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.day-card {
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 140px 1fr 1fr 1.2fr auto;
  align-items: center;
  gap: 12px;
  transition: all 0.2s;
}

@media (max-width: 720px) {
  .day-card {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .day-card-date {
    grid-column: 1 / -1;
  }
  .day-card-comments {
    grid-column: 1 / -1;
  }
  .day-card-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
  }
}

.day-card.current-day {
  border-left: 4px solid var(--primary);
  background: #f8fbff;
}

.day-card-date {
  display: flex;
  flex-direction: column;
}

.day-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--slate-800);
}

.day-sub {
  font-size: 0.75rem;
  color: var(--slate-500);
}

.dose-chip {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--slate-100);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
}

.dose-chip-label {
  font-size: 0.65rem;
  color: var(--slate-500);
  text-transform: uppercase;
  font-weight: 600;
}

.dose-chip-val {
  font-weight: 700;
  color: var(--slate-700);
}

.dose-chip.filled {
  background: var(--success-light);
  color: var(--success);
}

.dose-chip.filled .dose-chip-val {
  color: #15803d;
}

.day-comments-text {
  font-size: 0.8rem;
  color: var(--slate-600);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-box {
  transform: translateY(0);
}

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

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--slate-900);
}

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

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate-700);
  margin-bottom: 6px;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--slate-100);
  color: var(--slate-700);
}

.btn-secondary:hover {
  background: var(--slate-200);
}

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

/* PIN Screen */
.pin-screen {
  position: fixed;
  inset: 0;
  background: var(--slate-900);
  color: white;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: opacity 0.3s;
}

.pin-screen.hidden {
  display: none;
}

.pin-lock-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(2, 132, 199, 0.2);
  color: #38bdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.pin-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.pin-sub {
  font-size: 0.85rem;
  color: var(--slate-400);
  margin-bottom: 28px;
  text-align: center;
}

.pin-dots {
  display: flex;
  gap: 18px;
  margin-bottom: 36px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pin-dot.filled {
  background: #38bdf8;
  transform: scale(1.15);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.pin-dot.error {
  background: var(--danger);
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 18px;
}

.pin-key {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1.6rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.pin-key:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.94);
}

.pin-key.key-action {
  font-size: 1rem;
  background: transparent;
  border: none;
  color: var(--slate-400);
}

/* Emergency & Action Matrix Card */
.emergency-banner {
  background: linear-gradient(135deg, #b91c1c, #dc2626);
  color: white;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.emergency-info h3 {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.emergency-info p {
  font-size: 0.8rem;
  opacity: 0.9;
}

.call-btn {
  background: white;
  color: #b91c1c;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.contact-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 600px) {
  .contact-card-grid {
    grid-template-columns: 1fr;
  }
}

.contact-box {
  background: white;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.contact-box h4 {
  font-size: 0.9rem;
  color: var(--slate-800);
  margin-bottom: 4px;
}

.contact-box .hours {
  font-size: 0.75rem;
  color: var(--slate-500);
  margin-bottom: 12px;
}

.contact-phone-btn {
  background: var(--slate-100);
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.contact-phone-btn:hover {
  background: var(--primary-light);
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.matrix-table th {
  background: var(--slate-100);
  color: var(--slate-700);
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
  border-bottom: 1px solid var(--slate-200);
}

.matrix-table td {
  padding: 12px;
  border-bottom: 1px solid var(--slate-200);
  vertical-align: top;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--slate-900);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
  pointer-events: auto;
}

.toast.toast-success {
  border-left: 4px solid #22c55e;
}

.toast.toast-error {
  border-left: 4px solid #ef4444;
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
