/* ==========================================================================
   Mydicine — Medicine Reminder & Adherence Monitor
   CSS يدوي خفيف — دعم RTL/LTR عبر الخصائص المنطقية
   ========================================================================== */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0ea5e9;
  --brand-dark: #0369a1;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --gray: #6b7280;
  --radius: 14px;
  --shadow: 0 1px 3px rgb(15 23 42 / .08);
  --font: "Segoe UI", "Tajawal", "IBM Plex Sans Arabic", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: none; opacity: .85; }

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, #0369a1, #0ea5e9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1.25rem;
  box-shadow: var(--shadow);
}
.brand { font-weight: 800; font-size: 1.25rem; display: flex; align-items: center; gap: .5rem; }
.brand a { color: #fff; }
.brand .logo { font-size: 1.4rem; }

.userbox { display: flex; align-items: center; gap: .9rem; font-size: .92rem; }
.userbox .role {
  background: rgb(255 255 255 / .18);
  padding: .15rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
}

/* ---------- Nav ---------- */
.navbar {
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
}
.navbar ul { display: flex; gap: .25rem; padding: .4rem 1rem; list-style: none; }
.navbar a {
  display: inline-block;
  padding: .45rem .9rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
}
.navbar a.active, .navbar a:hover { background: #e0f2fe; color: var(--brand-dark); }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin-inline: auto; padding: 1.25rem 1rem 3rem; }
.page-title { font-size: 1.45rem; font-weight: 800; margin-block-end: .25rem; }
.page-sub { color: var(--muted); margin-block-end: 1.25rem; font-size: .92rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-block-end: 1rem;
}
.card > h2, .card > h3 { margin-block-end: .75rem; font-size: 1.05rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---------- Stat ---------- */
.stat { display: flex; flex-direction: column; gap: .25rem; }
.stat .n { font-size: 1.7rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .85rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  text-align: center;
}
.btn:hover { opacity: .9; color: #fff; }
.btn-outline { background: transparent; border-color: var(--brand); color: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-danger { background: var(--red); }
.btn-success { background: var(--green); }
.btn-sm { padding: .28rem .65rem; font-size: .8rem; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .6rem .7rem; text-align: start; border-block-end: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 700; font-size: .8rem; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }

/* ---------- Pills / badges ---------- */
.pill { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.pill-pending { background: #fef3c7; color: var(--amber); }
.pill-taken { background: #dcfce7; color: var(--green); }
.pill-missed { background: #fee2e2; color: var(--red); }
.pill-skipped { background: #e5e7eb; color: var(--gray); }
.pill-info { background: #e0f2fe; color: var(--brand-dark); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 700; font-size: .85rem; margin-block-end: .3rem; }
input, select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bae6fd; border-color: var(--brand); }
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-group { margin-block-end: .9rem; }
.help { color: var(--muted); font-size: .78rem; margin-block-start: .25rem; }
.error-text { color: var(--red); font-size: .8rem; margin-block-start: .25rem; }
input[type="file"] { padding: .4rem; }
input[type="checkbox"] { width: auto; }

/* ---------- Flash ---------- */
.flash { border-radius: 12px; padding: .8rem 1rem; margin-block-end: 1rem; font-weight: 600; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ---------- Medicine icon ---------- */
.med-icon {
  width: 46px; height: 46px; border-radius: 12px; object-fit: cover;
  background: #e0f2fe; border: 1px solid var(--border); flex-shrink: 0;
}
.med-pill { display: flex; align-items: center; gap: .8rem; }
.med-pill .t { font-weight: 700; }
.med-pill .s { color: var(--muted); font-size: .82rem; }

/* ---------- Alarm banner ---------- */
.alarm {
  position: fixed; inset-inline: 1rem; bottom: 1rem;
  background: #1e293b; color: #fff; border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(0 0 0 / .3);
  padding: 1.1rem; z-index: 1000;
  display: none;
  align-items: center; gap: 1rem; flex-wrap: wrap;
}
.alarm.show { display: flex; }
.alarm .msg { flex: 1 1 260px; font-size: .95rem; }
.alarm .msg b { font-size: 1.05rem; }
.alarm .actions { display: flex; gap: .5rem; }

/* ---------- Push banner ---------- */
.push-banner {
  background: #fffbeb; border: 1px solid #fde68a; color: #78350f;
  border-radius: 12px; padding: .8rem 1rem; margin-block-end: 1rem;
  display: flex; gap: .8rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
}

/* ---------- Monitoring grid ---------- */
.day-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.day-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem; }
.day-card .d { font-weight: 700; font-size: .82rem; }
.day-card .mini-bar { height: 6px; background: #e2e8f0; border-radius: 999px; margin-block: .4rem; overflow: hidden; }
.day-card .mini-bar > span { display: block; height: 100%; background: var(--green); }
.day-card .mini { font-size: .72rem; color: var(--muted); }

/* ---------- Chat ---------- */
.chat-items { display: flex; flex-direction: column; gap: .7rem; max-height: 55vh; overflow-y: auto; padding: .5rem; }
.bubble { max-width: 78%; padding: .65rem .9rem; border-radius: 14px; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--brand); color: #fff; border-end-end-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: #f1f5f9; border-start-start-radius: 4px; }
.bubble.error { background: #fee2e2; color: #991b1b; }

/* ---------- Guest / auth ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: linear-gradient(135deg, #0c4a6e, #0ea5e9);
}
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; padding: 2rem; box-shadow: 0 20px 50px rgb(0 0 0 / .25); }
.auth-card h1 { text-align: center; margin-block-end: 1.2rem; font-size: 1.4rem; }

/* ---------- Dose row ---------- */
.dose-row { display: flex; align-items: center; gap: .8rem; padding: .65rem; border-block-end: 1px solid var(--border); }
.dose-row:last-child { border-block-end: none; }
.dose-row .when { font-weight: 800; min-width: 60px; }
.dose-row .spacer { flex: 1; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mt { margin-block-start: 1rem; }
.mb { margin-block-end: 1rem; }
.center { text-align: center; }
.flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 2rem; }
.pagination { text-align: center; margin-block-start: 1rem; }
.pagination .page-link { margin-inline: .2rem; padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 8px; }

@media (max-width: 640px) {
  .container { padding-inline: .7rem; }
  .topbar { flex-wrap: wrap; }
  .alarm .actions { width: 100%; }
}