/* =========================================================
   Dementia Care Assistant — Global Styles
   (Bootstrap-friendly; tablet-focused)
   ========================================================= */

/* ---------- CSS Variables ---------- */
:root{
  --brand: #0d6efd;
  --brand-600: #0a58ca;
  --ink: #1f2937;
  --muted: #6b7280;
  --bg: #fff;
  --card: #ffffff;
  --border: #e9eef6;
  --danger: #dc3545;
  --success: #198754;
  --warning: #ffc107;

  --rail-top: 88px;
  --tab-font: 1.05rem;

  --r-md: 12px;
  --r-lg: 14px;
  --shadow-soft: 0 4px 10px rgba(0,0,0,.08);
  --shadow-strong: 0 10px 24px rgba(13,110,253,.18);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); text-decoration: underline; }

h1,h2,h3,h4,h5 { color: var(--ink); margin: 0 0 .5rem 0; }

/* Header */
.navbar, .site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

/* Cards / shells */
.card, .patient-shell {
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border);
}

/* Forms */
.form-control, .form-select {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 .2rem rgba(13,110,253,.15);
}
label { font-weight: 600; color: #3b4452; }

/* Buttons */
.btn { border-radius: 12px; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-danger { border-radius: 10px; }

/* =========================================================
   Canvas layout
   ========================================================= */
.canvas{
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  align-items: start;
  min-height: calc(100vh - var(--rail-top) - 24px);
  grid-auto-rows: minmax(0, auto);   /* let children shrink so inner areas can scroll */
}

/* Patient bar — centered name, small mode pill on the right */
.patient-bar{
  position: relative;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#fff;
  border:1px solid var(--border);
  border-radius:12px;
  padding:12px 16px;
  margin-bottom:12px;
  box-shadow: var(--shadow-soft);
}
.patient-bar__name{
  font-weight:800; font-size:1.35rem; letter-spacing:.2px; text-align:center;
}
.patient-bar__mode{
  position:absolute; right:12px; top:50%; transform: translateY(-50%);
  font-size:.8rem; font-weight:700; padding:4px 8px; border-radius:999px;
  border: 1px solid var(--border);
  background: #f8fafc; color:#374151;
}
.patient-bar__mode.mode-edit{ background:#e8f1ff; color:#0a58ca; border-color:#cfe1ff; }
.patient-bar__mode.mode-view{ background:#f3f4f6; color:#4b5563; }

/* Sidebar (left menu) */
.sidebar{
  position: sticky;
  top: var(--rail-top);
  height: calc(100vh - var(--rail-top) - 24px); /* explicit height helps on some browsers */
  min-height: 0;                                 /* allow inner overflow to work */
  display: flex;
  flex-direction: column;
  padding-right: 0;
  background: #fff;                              /* solid background (no weird stop) */
  border-right: 0;                               /* no vertical rule */
}
.sidebar__photo{
  display:flex; flex-direction:column; align-items:center; margin:10px 12px 12px;
}
.sidebar__avatar{
  width: 120px; height:120px; border-radius:50%; object-fit:cover;
  border: 3px solid #e0e0e0;
}
#delete-btn{
  position: absolute; top: -8px; right: -8px;
  background: var(--danger); color: #fff; border: none; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.upload-btn-wrapper{ position: relative; overflow: hidden; display: inline-block; margin-top: 8px; }
.upload-btn{
  background: var(--brand); color: #fff; padding: 8px 16px; border: none; border-radius: 10px;
  font-size: 15px; cursor: pointer;
}
.upload-btn-wrapper input[type=file]{ position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Full-height, independently scrollable nav */
.sidebar__nav{
  flex: 1 1 auto;
  min-height: 0;                      /* critical for inner scroll */
  overflow-y: auto;                   /* independent scroll area */
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  padding-right: 6px;
  padding-bottom: 8px;
  margin-top: 6px;
}
/* Optional slimmer scrollbar (WebKit) */
.sidebar__nav::-webkit-scrollbar{ width:8px; }
.sidebar__nav::-webkit-scrollbar-thumb{ background:#cfd6e3; border-radius:8px; }
.sidebar__nav::-webkit-scrollbar-thumb:hover{ background:#bcc5d6; }

/* Menu rows – remove real borders, use inset shadow separators */
.sidebar__tabline{
  width:100%;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  text-align: left;
  font-weight: 700;
  font-size: var(--tab-font);
  color: #2b2f38;
  border-radius: 0;
  box-shadow: inset 0 -1px 0 0 var(--border);  /* soft bottom separator */
}
.sidebar__tabline:last-child{ box-shadow:none; }
.sidebar__tabline:hover{ background:#f7f9fc; }
.sidebar__tabline.active{
  background: #e9f2ff;
  color: #0a58ca;
  box-shadow:
    inset 4px 0 0 0 var(--brand),       /* left accent bar */
    inset 0 -1px 0 0 var(--border);     /* keep bottom separator */
}

/* Content surface */
.content{
  min-height: calc(100vh - var(--rail-top) - 24px);
  background:#fff;
  border:1px solid var(--border);
  border-radius:12px;
  padding:16px;
  box-shadow: var(--shadow-soft);
}

/* Save rail in main content */
.save-rail{
  position: sticky; bottom: 0; background: #fff;
  padding-top: 10px; margin-top: 12px;
  border-top: 1px solid var(--border);
  display:flex; justify-content:flex-end;
}

/* Bootstrap tab visibility */
#medicines:not(.show) { display: none !important; }
.tab-pane { display: none; }
.tab-pane.active.show { display: block; }

/* =========================================================
   Tables / Modals / Toasts
   ========================================================= */
.table thead th { font-weight: 700; color: royalblue; border-bottom: 2px solid var(--border); }
.table td, .table th { vertical-align: middle; }
.table-hover tbody tr:hover { background: #fafcff; }

#medicines-table-wrapper .btn { border-radius: 10px; padding: .375rem .6rem; }

.modal-content{ border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-soft); }
.modal-header{ border-bottom: 1px solid var(--border); }
.modal-footer{ border-top: 1px solid var(--border); }

/* Time fields min width */
#add_time_fields .form-control[type="time"],
#edit_time_fields .form-control[type="time"]{ min-width: 140px; }
#add_time_fields .form-select,
#edit_time_fields .form-select{ min-width: 140px; }

/* Repeat-type helper containers (default hidden) */
#add_every_n_days_container, #edit_every_n_days_container{ display: none; }

/* Toasts */
#toast-success, #toast-error, #toast-info{
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 24px; min-width: 240px; max-width: 90vw;
  padding: 12px 16px; border-radius: 12px; font-weight: 700; color: #fff;
  z-index: 1080; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
#toast-success{ background: var(--success); }
#toast-error{ background: var(--danger); }
#toast-info{ background: var(--brand); }

/* =========================================================
   Medicines modal: time input + slim right cap
   ========================================================= */
.med-time-row { --ctrl-h: 38px; --cap-w: 42px; }
.med-time-row .form-control[type="time"]{
  height: var(--ctrl-h);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}
.med-time-row .time-remove{
  width: var(--cap-w);
  height: var(--ctrl-h);
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: -1px;
  background: #fff; color: #dc3545;
  border: 1px solid #ced4da;
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  border-top-right-radius: 999px; border-bottom-right-radius: 999px;
  outline: none;
}
.med-time-row .time-remove:focus{ box-shadow: 0 0 0 .2rem rgba(220,53,69,.15); }

.modal .med-time-row { --ctrl-h: 40px; --cap-w: 44px; }
@media (max-width: 480px){ .med-time-row { --ctrl-h: 36px; --cap-w: 38px; } }

/* Utilities */
.shadow-soft { box-shadow: var(--shadow-soft); }
.rounded-12 { border-radius: 12px; }
.muted { color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px){
  :root{ --tab-font: 1rem; --rail-top: 72px; }
  .canvas{ grid-template-columns: 1fr; }
  .sidebar{
    position: static;
    height: auto;
    min-height: 0;
    background: transparent;
  }
  .sidebar__nav{ overflow: visible; padding-right: 0; }
  .sidebar__avatar{ width: 108px; height:108px; }
}
@media (min-width: 1400px){
  .patient-bar__name{ font-size: 1.45rem; }
  .sidebar__avatar{ width: 130px; height:130px; }
}

.table .action-btn{
  width:34px; height:34px; padding:0;
  display:inline-flex; align-items:center; justify-content:center; border-radius:8px;
}
.table .action-btn i{ font-size:1rem; line-height:1; }
