/* CSS Variables & Theme Setup */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --critical: #b91c1c;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --font-family: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  line-height: 1.5;
  padding-bottom: 90px;
}

/* Header & Banner */
.app-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #ffffff;
  padding: 24px 16px 20px;
  border-bottom-left-radius: 24px;
  border-bottom-right-radius: 24px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

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

.title-container h1 {
  font-size: 1.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-container p {
  font-size: 0.9rem;
  opacity: 0.9;
  margin-top: 4px;
}

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

.btn-icon {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: var(--radius-full);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

/* Container */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Date & User Bar */
.control-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: -16px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: var(--radius-md);
}

.date-nav input[type="date"] {
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
  font-family: var(--font-family);
}

.date-btn {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.user-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

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

.user-selector select {
  border: none;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  outline: none;
  cursor: pointer;
  font-family: var(--font-family);
}

/* Progress Tracker */
.progress-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.progress-bar-bg {
  height: 10px;
  background-color: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #2563eb);
  width: 0%;
  border-radius: var(--radius-full);
  transition: width 0.4s ease-in-out;
}

/* Quick Sync & Backup Status */
.sync-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 4px 6px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
}

.status-dot.offline {
  background-color: #f59e0b;
}

/* Filter Chips */
.filters-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0 6px;
  scrollbar-width: none;
}

.filters-bar::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  white-space: nowrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Periods Sections */
.period-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  margin-top: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.period-header {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background-color: #fbfcfe;
}

.period-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.period-icon-badge {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: white;
}

.period-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.period-time-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background-color: #f1f5f9;
  color: var(--text-muted);
}

.critical-period {
  border: 2px solid #f43f5e;
}

.critical-period .period-header {
  background-color: #fff1f2;
}

.critical-banner {
  background-color: #ffe4e6;
  color: #9f1239;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #fecdd3;
}

.meal-banner {
  background-color: #fefce8;
  color: #854d0e;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #fef08a;
}

/* Items List */
.items-list {
  display: flex;
  flex-direction: column;
}

.item-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  gap: 14px;
  transition: background-color 0.2s;
}

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

.item-row.completed {
  background-color: #f0fdf4;
}

.item-time-col {
  min-width: 65px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.item-time {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--primary-dark);
}

.item-visual {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.item-visual svg, .item-visual img {
  width: 32px;
  height: 32px;
}

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

.item-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-subtitle {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
}

.item-dosage {
  font-size: 0.85rem;
  color: #334155;
  margin-top: 2px;
  font-weight: 500;
}

.item-instruction {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-critical {
  background-color: #fee2e2;
  color: #b91c1c;
}

.badge-insulin {
  background-color: #ffedd5;
  color: #c2410c;
}

.badge-ointment {
  background-color: #fef9c3;
  color: #854d0e;
}

/* Measurement Input in Row */
.measurement-box {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.measurement-input {
  width: 140px;
  padding: 6px 10px;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  direction: ltr;
  text-align: center;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
}

.measurement-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.reading-hint {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  display: none;
}

/* Checkbox Action */
.item-action {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.custom-checkbox {
  width: 36px;
  height: 36px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: white;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 1.2rem;
  color: transparent;
}

.custom-checkbox:hover {
  border-color: var(--primary);
  transform: scale(1.05);
}

.custom-checkbox.checked {
  background-color: var(--success);
  border-color: var(--success);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(22, 163, 74, 0.3);
}

.completed-time {
  font-size: 0.7rem;
  color: #15803d;
  font-weight: 700;
}

/* Notes Section */
.notes-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: 18px;
  border: 1px solid var(--border);
}

.notes-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.notes-card textarea {
  width: 100%;
  height: 70px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 0.9rem;
  font-family: var(--font-family);
  resize: vertical;
  outline: none;
}

.notes-card textarea:focus {
  border-color: var(--primary);
}

/* Floating Bottom Bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: center;
  z-index: 100;
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.05);
}

.bottom-bar-inner {
  max-width: 900px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.25);
}

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

.btn-excel {
  background: #166534;
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 4px 6px -1px rgba(22, 101, 52, 0.25);
}

.btn-excel:hover {
  background: #14532d;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 580px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.setting-group {
  margin-bottom: 18px;
}

.setting-group label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--text-main);
}

.setting-group input[type="text"],
.setting-group input[type="url"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
  font-family: monospace;
  direction: ltr;
}

.setting-group small {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Toast Message */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: #0f172a;
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive */
@media (max-width: 640px) {
  .title-container h1 {
    font-size: 1.3rem;
  }
  .item-row {
    padding: 12px 10px;
    gap: 10px;
  }
  .item-time-col {
    min-width: 50px;
  }
  .item-time {
    font-size: 0.85rem;
  }
  .item-name {
    font-size: 0.92rem;
  }
  .measurement-input {
    width: 110px;
    font-size: 0.85rem;
    padding: 5px 8px;
  }
  .bottom-bar-inner {
    flex-wrap: wrap;
    justify-content: stretch;
  }
  .btn-primary, .btn-excel {
    flex: 1;
    justify-content: center;
    font-size: 0.85rem;
    padding: 10px 8px;
  }
}

