:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #eef7f3;
  --text: #17332a;
  --muted: #60736c;
  --primary: #087f5b;
  --primary-dark: #06684a;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --border: #d8e3df;
  --focus: #5cc8a1;
  --shadow: 0 12px 32px rgba(18, 62, 48, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf7f3 0, var(--bg) 260px);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }
button:disabled { cursor: not-allowed; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: clamp(1.55rem, 3vw, 2.15rem); }
h2 { margin-bottom: 18px; font-size: 1.2rem; }
h3 { margin-bottom: 14px; font-size: 1rem; }
.container { width: min(1500px, calc(100% - 32px)); margin: 0 auto; }
.card { background: var(--surface); border: 1px solid rgba(216, 227, 223, .9); border-radius: var(--radius); box-shadow: var(--shadow); }
.subtitle { margin: 0; color: var(--muted); }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(470px, 100%); padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-loading { margin: 0; color: var(--muted); text-align: center; }
.auth-card form h2 { margin-bottom: 16px; }
.auth-submit { width: 100%; }
.auth-error { min-height: 24px; }
.setup-note { padding: 12px; border-radius: 11px; background: var(--surface-soft); color: #426257; font-size: .88rem; }

header { padding: 30px 0 20px; }
.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 15px; background: var(--primary); color: white; box-shadow: var(--shadow); font-size: 27px; font-weight: 800; }
.version-badge { display: inline-flex; align-items: center; margin-top: 7px; padding: 4px 9px; border-radius: 999px; background: #dff5ec; color: #06684a; border: 1px solid #a9d9c8; font-size: .78rem; font-weight: 800; letter-spacing: .02em; }
.session-panel { display: flex; align-items: flex-end; flex-direction: column; gap: 9px; min-width: 260px; }
.session-identity { text-align: right; }
.session-identity strong, .session-identity span { display: block; }
.session-identity span { color: var(--muted); font-size: .82rem; }
.session-buttons { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.privacy-note { margin: 18px 0 0; padding: 12px 14px; border: 1px solid #b9d9cd; border-radius: 12px; background: rgba(255,255,255,.72); color: #31594b; font-size: .91rem; }

main { display: block; padding-bottom: 36px; }
.page-actions { display: flex; align-items: center; padding: 0 0 20px; }
.page-actions .btn { min-height: 48px; padding-inline: 20px; font-size: 1rem; box-shadow: 0 9px 24px rgba(8,127,91,.18); }
body.modal-open { overflow: hidden; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 10px 15px; border-radius: 10px; font-weight: 750; transition: transform .12s ease, background .12s ease, opacity .12s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .58; transform: none; }
.btn:focus-visible { outline: 3px solid rgba(92,200,161,.48); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e8efec; color: #294a3f; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-small { min-height: 32px; padding: 6px 9px; font-size: .76rem; }

label { display: block; margin-bottom: 6px; font-weight: 700; font-size: .92rem; }
input, select { width: 100%; border: 1px solid var(--border); border-radius: 11px; background: #fff; color: var(--text); padding: 11px 12px; outline: none; transition: border-color .15s ease, box-shadow .15s ease; }
input:focus, select:focus { border-color: var(--focus); box-shadow: 0 0 0 4px rgba(92,200,161,.18); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: #e77972; box-shadow: 0 0 0 3px rgba(180,35,24,.1); }
input:disabled, select:disabled { background: #edf1ef; color: #6b7772; }
.field { margin-bottom: 15px; }
.hint { display: block; margin-top: 5px; color: var(--muted); font-size: .79rem; }
.error { min-height: 18px; margin-top: 4px; color: var(--danger); font-size: .78rem; }
.form-actions { display: flex; gap: 9px; margin-top: 5px; }
.form-actions .btn-primary { flex: 1; }
.form-grid, .treatment-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.treatment-grid .doctor-field { grid-column: 1 / -1; }
.treatment-section { margin: 21px 0 17px; padding: 17px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.change-question { margin: 0 0 13px; padding: 0; border: 0; }
.change-question legend { margin-bottom: 10px; font-weight: 800; font-size: .98rem; }
.choice-group { display: grid; grid-template-columns: repeat(2, minmax(0,150px)); gap: 10px; }
.choice-option { display: flex; align-items: center; gap: 9px; min-height: 46px; margin: 0; padding: 10px 13px; border: 1px solid var(--border); border-radius: 11px; background: #fff; cursor: pointer; font-weight: 800; }
.choice-option:has(input:checked) { border-color: var(--primary); background: #e4f5ee; box-shadow: 0 0 0 3px rgba(8,127,91,.10); }
.choice-option input { width: 19px; height: 19px; margin: 0; accent-color: var(--primary); flex: 0 0 auto; }
.details-status { margin: 0 0 14px; color: var(--muted); font-size: .82rem; }
.insulin-details[aria-disabled="true"] { opacity: .52; }

.list-card { min-width: 0; overflow: hidden; }
.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding: 20px; border-bottom: 1px solid var(--border); }
.search-wrap { flex: 1; max-width: 520px; }
.search-wrap label, .filter-wrap label { margin-bottom: 7px; }
.filter-wrap { width: min(250px,100%); }
.toolbar-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.summary { display: flex; justify-content: space-between; gap: 12px; padding: 13px 20px; background: var(--surface-soft); color: #426257; font-size: .88rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 930px; }
th, td { padding: 11px 8px; border-bottom: 1px solid #e8efec; text-align: left; vertical-align: middle; }
th { background: #fbfcfc; color: #49645b; font-size: .78rem; text-transform: uppercase; letter-spacing: .045em; white-space: nowrap; }
td { font-size: .91rem; }
tbody tr:hover { background: #fbfefd; }
.name-cell { font-weight: 750; }
.nowrap { white-space: nowrap; }
.actions-heading { text-align: right; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 50%; background: var(--surface-soft); font-size: 26px; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,35,29,.62); backdrop-filter: blur(3px); }
.modal-panel { position: relative; width: min(780px,100%); max-height: min(90vh,900px); overflow: hidden; display: flex; flex-direction: column; background: var(--surface); border: 1px solid rgba(255,255,255,.65); border-radius: 20px; box-shadow: 0 28px 80px rgba(0,0,0,.28); }
.modal-panel-wide { width: min(1180px,100%); }
.modal-panel-small { width: min(520px,100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 22px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg,#f8fcfa,#fff); }
.modal-header h2 { margin: 0; font-size: 1.28rem; }
.modal-close { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 10px; background: #edf3f0; color: #294a3f; font-size: 1.5rem; line-height: 1; }
.modal-close:hover { background: #dfeae5; }
.modal-body { overflow-y: auto; padding: 22px; }

.new-user-card { padding: 16px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); margin-bottom: 20px; }
.user-create-grid { display: grid; grid-template-columns: 1.3fr .9fr 1.2fr auto; gap: 12px; align-items: end; }
.user-create-grid .field { margin-bottom: 0; }
.user-create-button { margin-bottom: 0; white-space: nowrap; }
.user-card { display: grid; grid-template-columns: minmax(210px,1.4fr) minmax(170px,.8fr) 110px minmax(200px,1fr) auto; gap: 12px; align-items: end; padding: 14px 0; border-bottom: 1px solid var(--border); }
.user-card:last-child { border-bottom: 0; }
.user-email { align-self: center; min-width: 0; }
.user-email strong, .user-email span { display: block; overflow-wrap: anywhere; }
.user-email span { color: var(--muted); font-size: .78rem; }
.user-card .field { margin: 0; }
.active-control { display: flex; align-items: center; gap: 8px; min-height: 43px; margin: 0; }
.active-control input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(390px,calc(100% - 40px)); padding: 13px 16px; border-radius: 12px; background: #17332a; color: #fff; box-shadow: 0 16px 40px rgba(0,0,0,.18); opacity: 0; transform: translateY(14px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 150; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error-toast { background: #812018; }
footer { padding: 0 0 26px; text-align: center; color: var(--muted); font-size: .82rem; }

@media (max-width: 1000px) {
  .user-create-grid { grid-template-columns: 1fr 1fr; }
  .user-create-button { align-self: stretch; }
  .user-card { grid-template-columns: 1fr 1fr; align-items: start; }
}
@media (max-width: 900px) {
  .header-row { flex-direction: column; }
  .session-panel { align-items: flex-start; min-width: 0; }
  .session-identity { text-align: left; }
  .session-buttons { justify-content: flex-start; }
  .form-grid, .treatment-grid { grid-template-columns: 1fr; }
  .treatment-grid .doctor-field { grid-column: auto; }
}
@media (max-width: 620px) {
  .container { width: min(100% - 20px,1500px); }
  .auth-screen { padding: 10px; }
  .auth-card { padding: 20px; }
  header { padding-top: 24px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .search-wrap { max-width: none; }
  .toolbar-actions .btn { flex: 1; }
  .summary { flex-direction: column; gap: 3px; }
  .form-actions { flex-direction: column; }
  .choice-group { grid-template-columns: 1fr 1fr; }
  .modal { padding: 10px; }
  .modal-header, .modal-body { padding-left: 16px; padding-right: 16px; }
  .page-actions .btn { width: 100%; }
  .user-create-grid, .user-card { grid-template-columns: 1fr; }
}

@media print {
  .auth-screen, header, .page-actions, .modal, .toolbar, .row-actions, footer, .privacy-note, .toast { display: none !important; }
  body { background: #fff; }
  #app-shell, main, .container { display: block !important; width: 100%; margin: 0; padding: 0; }
  .list-card { box-shadow: none; border: 0; }
  .summary { background: #fff; }
  table { min-width: 0; font-size: 8px; }
  th, td { padding: 5px; }
  .actions-heading { display: none; }
}
