@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg: #f3faf8;
  --surface: #fff;
  --surface-2: #e8f5f1;
  --text: #15343b;
  --muted: #789095;
  --primary: #087f78;
  --primary-light: #ddf7f0;
  --line: #d9ece8;
  --danger: #c75769;
  --warning: #a86b14;
  --shadow: 0 16px 45px rgba(21, 82, 83, .1);
}

[data-theme="dark"] {
  --bg: #091d23;
  --surface: #102b32;
  --surface-2: #173b40;
  --text: #effffb;
  --muted: #9ab8b7;
  --line: #285057;
  --primary-light: #174d4c;
  --shadow: 0 18px 48px #0005;
}

* { box-sizing: border-box; }

body { 
  margin: 0; 
  min-height: 100vh; 
  background: var(--bg); 
  color: var(--text); 
  font-family: Vazirmatn, sans-serif; 
  padding-bottom: 90px; 
}

button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }

/* استایل دکمه‌های غیرفعال */
button:disabled {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
}

.hidden { display: none !important; }

/* هدر اصلی برنامه */
.app-header {
  height: 68px; 
  padding: 0 max(18px, calc((100% - 840px)/2));
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--line); 
  position: sticky; 
  top: 0; 
  z-index: 10; 
  backdrop-filter: blur(16px);
}
.app-brand { color: var(--text); gap: 8px; text-decoration: none; display: flex; align-items: center; }
.app-brand span { display: grid; place-items: center; width: 34px; height: 34px; color: white; border-radius: 11px; background: linear-gradient(135deg, #18b5a1, var(--primary)); font-size: 20px; }
.header-actions { display: flex; gap: 8px; }
.icon-button { width: 37px; height: 37px; border-radius: 11px; color: var(--muted); background: var(--surface-2); transition: .2s; }
.icon-button:hover { color: var(--primary); transform: translateY(-2px); }

/* بدنه اصلی */
.app-container { width: min(840px, calc(100% - 28px)); margin: 23px auto; }

.welcome-card {
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  padding: 25px;
  background: linear-gradient(135deg, var(--surface), var(--primary-light)); 
  border: 1px solid var(--line);
  border-radius: 25px; 
  box-shadow: var(--shadow);
}
.welcome-card small, .next-label, .section-title small { color: var(--muted); font-size: 11px; }
.welcome-card h1 { font-size: 23px; margin: 6px 0; }
.welcome-card p { color: var(--muted); font-size: 11px; margin: 0; }
.welcome-icon { font-size: 52px; filter: drop-shadow(0 8px 7px #087f7830); animation: bob 3s ease-in-out infinite; }

.next-card { margin-top: 15px; padding: 22px; border-radius: 23px; color: white; background: linear-gradient(130deg, #087f78, #15ac9a); box-shadow: 0 15px 35px #087f7833; }
.next-label { color: #bff6ec; }
.next-main { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 9px; }
.next-main strong { display: block; font-size: 22px; }
.next-main span { display: block; color: #d7fff8; font-size: 12px; margin-top: 5px; }
.next-time { font-size: 31px; font-weight: 800; direction: ltr; }
.taken-button { color: var(--primary); background: white; border-radius: 11px; padding: 9px 15px; margin-top: 17px; font-size: 12px; font-weight: 700; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 15px; }
.quick-action { padding: 16px; text-align: right; border: 1px solid var(--line); background: var(--surface); border-radius: 18px; color: var(--text); transition: .25s; }
.quick-action:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.quick-action span { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); color: var(--primary); font-size: 20px; margin-bottom: 7px; }
.quick-action b, .quick-action small { display: block; }
.quick-action b { font-size: 13px; }
.quick-action small { color: var(--muted); font-size: 10px; margin-top: 3px; }
.quick-action.primary { background: var(--primary); border-color: var(--primary); color: white; }
.quick-action.primary span { background: #ffffff20; color: white; }
.quick-action.primary small { color: #c5f8ee; }

.dashboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 15px; }
.metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: 17px; padding: 16px; }
.metric-card span, .metric-card small { display: block; color: var(--muted); font-size: 10px; }
.metric-card strong { display: block; color: var(--primary); font-size: 25px; margin: 5px 0; }

.section-block { margin-top: 32px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.section-title h2 { margin: 3px 0 0; font-size: 19px; }
.text-button { color: var(--primary); background: transparent; font-size: 11px; font-weight: 700; }

.timeline { display: grid; gap: 10px; }
.empty-state { text-align: center; color: var(--muted); padding: 38px 20px; border: 1px dashed var(--line); border-radius: 20px; }
.empty-state strong { display: block; color: var(--text); margin-bottom: 7px; }

.dose-card { display: flex; align-items: center; gap: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; padding: 14px; transition: .2s; }
.dose-card.completed { opacity: .6; }
.dose-time { min-width: 55px; color: var(--primary); direction: ltr; font-weight: 800; font-size: 14px; }
.dose-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; background: var(--primary-light); font-size: 20px; }
.dose-info { flex: 1; min-width: 0; }
.dose-info strong, .dose-info small { display: block; }
.dose-info strong { font-size: 13px; }
.dose-info small { color: var(--muted); font-size: 10px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.offline-note { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border-radius: 17px; padding: 14px; margin-top: 25px; }
.offline-note > span { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: white; }
.offline-note b, .offline-note small { display: block; }
.offline-note b { font-size: 11px; }
.offline-note small { color: var(--muted); font-size: 10px; margin-top: 3px; }

/* نوار ناوبری پایین */
.bottom-nav { position: fixed; z-index: 15; bottom: 14px; left: 50%; transform: translateX(-50%); width: min(500px, calc(100% - 28px)); display: flex; justify-content: space-around; padding: 9px; border: 1px solid var(--line); border-radius: 22px; background: color-mix(in srgb, var(--surface) 90%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(17px); }
.bottom-nav a, .bottom-nav button { color: var(--muted); background: transparent; padding: 4px 12px; border-radius: 13px; text-decoration: none; }
.bottom-nav .active { color: var(--primary); background: var(--primary-light); }
.bottom-nav span, .bottom-nav small { display: block; text-align: center; }
.bottom-nav span { font-size: 19px; }
.bottom-nav small { font-size: 9px; margin-top: 3px; }

/* مدیریت لایه پاپ‌آپ و مودال‌ها (اصلاح ناهمخوانی active و open) */
.modal-backdrop { 
  display: none; 
  place-items: center; 
  position: fixed; 
  inset: 0; 
  z-index: 50; 
  padding: 15px; 
  background: #09252dcc; 
  backdrop-filter: blur(8px); 
}

.modal-backdrop.open,
.modal-backdrop.active { 
  display: grid !important; 
}

.modal { position: relative; width: min(470px, 100%); max-height: 92vh; overflow-y: auto; padding: 23px; color: var(--text); background: var(--surface); border-radius: 25px; box-shadow: 0 25px 80px #0005; animation: modalIn .25s ease; }
.modal.wide { width: min(650px, 100%); }
.modal-close { position: absolute; top: 15px; left: 15px; color: var(--muted); background: var(--surface-2); width: 29px; height: 29px; border-radius: 9px; font-size: 20px; display: grid; place-items: center; line-height: 1; }
.modal-heading { display: flex; align-items: center; gap: 11px; margin-bottom: 18px; }
.modal-heading small { color: var(--muted); font-size: 10px; }
.modal-heading h2 { margin: 3px 0 0; font-size: 20px; }
.modal-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--primary-light); color: var(--primary); font-size: 22px; }
.modal-icon.ai { background: #e5f8f1; }

label { display: block; color: var(--muted); font-size: 11px; margin: 12px 0; }
input, select { display: block; width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; outline: none; color: var(--text); background: var(--bg); }
input:focus, select:focus { border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.submit-button { width: 100%; color: white; background: var(--primary); border-radius: 12px; padding: 13px; font-weight: 700; margin-top: 12px; transition: .2s; }
.outline-button { width: 100%; color: var(--primary); border: 1px solid var(--primary); background: transparent; border-radius: 11px; padding: 11px; font-size: 12px; }
.legal-warning { color: var(--warning); background: #fff6df; border: 1px solid #f4e0a6; border-radius: 12px; padding: 11px; font-size: 10px; line-height: 1.9; margin-bottom: 15px; }

.upload-box { display: grid; place-items: center; gap: 7px; min-height: 170px; border: 2px dashed var(--line); border-radius: 18px; cursor: pointer; text-align: center; margin: 15px 0; }
.upload-box span { font-size: 35px; }
.upload-box b { color: var(--text); font-size: 13px; }
.upload-box small { color: var(--muted); font-size: 10px; }
.upload-box input[type="file"] { display: none; }

.preview-image { width: 100%; max-height: 250px; object-fit: contain; border-radius: 15px; background: var(--bg); margin-top: 10px; }
.scan-status { color: var(--primary); text-align: center; font-size: 12px; padding: 13px; font-weight: 600; }

.switch-line { display: flex; align-items: center; gap: 10px; color: var(--text); cursor: pointer; }
.switch-line input { display: inline-block; width: auto; margin: 0; accent-color: var(--primary); }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.toast { position: fixed; z-index: 100; top: 80px; right: 50%; transform: translateX(50%) translateY(-15px); color: white; background: #163f45; opacity: 0; pointer-events: none; border-radius: 12px; padding: 12px 17px; font-size: 11px; transition: .3s; }
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

@keyframes bob { 50% { transform: translateY(-7px) rotate(-5deg); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(.97); } to { opacity: 1; transform: none; } }

@media(max-width: 520px) {
  .quick-actions, .dashboard-grid { gap: 8px; }
  .quick-action { padding: 12px 10px; }
  .quick-action b { font-size: 11px; }
  .dose-card { gap: 8px; }
  .dose-time { min-width: 46px; font-size: 12px; }
}
