:root {
  --brand: #F5821F;
  --brand-dark: #d96f12;
  --bg: #121212;
  --surface: #1c1c1e;
  --surface-2: #262628;
  --text: #f2f2f2;
  --muted: #9a9a9e;
  --border: #333336;
  --green: #34c759;
  --red: #ff453a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
.screen { width: 100%; max-width: 480px; margin-inline: auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

/* ---------- Экран входа ---------- */
#login-screen { align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-box .logo { width: 100%; max-width: 260px; margin: 0 auto 8px; display: block; }
.subtitle { color: var(--muted); margin: 0 0 28px; font-size: 15px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input[type=text], #login-form input[type=password] {
  padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px; outline: none;
}
#login-form input:focus { border-color: var(--brand); }
.remember { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; justify-content: flex-start; }
.remember input { width: 18px; height: 18px; accent-color: var(--brand); }
#login-btn { margin-top: 6px; padding: 14px; border: none; border-radius: 12px; background: var(--brand); color: #fff; font-size: 16px; font-weight: 600; }
#login-btn:active { background: var(--brand-dark); }
.error { color: var(--red); font-size: 14px; margin-top: 4px; }

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(32px + env(safe-area-inset-top) + var(--tg-content-safe-top, 0px));
  background: var(--brand); position: sticky; top: 0; z-index: 10;
}
.logo-sm { height: 30px; }
.branch { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 14px; }
.icon-btn { background: rgba(255,255,255,.12); border: none; color: var(--text); width: 34px; height: 34px; border-radius: 8px; font-size: 20px; }
.logout-btn { background: rgba(255,255,255,.2); border: none; color: #fff; padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; }

/* ---------- Вкладки ---------- */
.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 9; }
.tab { flex: 1; padding: 14px; background: none; border: none; color: var(--muted); font-size: 15px; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.badge { background: var(--brand); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px; margin-left: 4px; }

/* ---------- Контент ---------- */
.tab-content { flex: 1; overflow-y: auto; padding: 16px 16px 48px; }

/* ---------- Поиск по центру ---------- */
.search-block { max-width: 560px; margin: 0 auto 10px; }
.search-wrap { position: relative; margin-top: 8vh; }
.search-bar { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; padding: 4px 10px; }
.search-bar:focus-within { border-color: var(--brand); }
.search-icon { font-size: 16px; opacity: .7; }
.search-bar input { flex: 1; padding: 14px 4px; border: none; background: transparent; color: var(--text); font-size: 17px; outline: none; }
.search-bar .icon-btn { width: 30px; height: 30px; font-size: 18px; }

.suggestions {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; max-height: 52vh; overflow-y: auto; z-index: 30;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.sug-item { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.sug-item:last-child { border-bottom: none; }
.sug-item:active { background: var(--surface); }
.sug-item .sug-name { font-weight: 600; font-size: 15px; }
.sug-item .sug-dosage { color: var(--muted); font-size: 13px; margin-left: 6px; }
.sug-item .sug-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.sug-item .sug-mnn { color: var(--brand); font-size: 12px; margin-top: 2px; }
.sug-item.custom { color: var(--brand); font-weight: 600; }

.selected-row { margin-top: 10px; background: var(--surface-2); border: 1px solid var(--brand); border-radius: 12px; padding: 12px; }
.selected-med { font-weight: 600; margin-bottom: 10px; }
.selected-med .dosage { color: var(--muted); font-weight: 400; margin-left: 6px; }
.qty-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.qty-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 20px; }
#qty-input { width: 60px; height: 40px; text-align: center; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px; }
.unit-toggle { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.unit { padding: 10px 12px; background: var(--surface); border: none; color: var(--muted); font-size: 14px; }
.unit.active { background: var(--brand); color: #fff; }
.add-btn { margin-left: auto; padding: 11px 20px; background: var(--brand); color: #fff; border: none; border-radius: 10px; font-size: 15px; font-weight: 600; }

/* ---------- Список позиций ---------- */
.entry-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.entry { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.entry .info { flex: 1; min-width: 0; }
.entry .name { font-weight: 600; font-size: 15px; }
.entry .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.entry .custom-tag { color: var(--brand); font-size: 11px; border: 1px solid var(--brand); border-radius: 6px; padding: 0 5px; margin-left: 6px; }
.entry .qty { font-weight: 700; color: var(--brand); white-space: nowrap; }
.entry .del { background: none; border: none; color: var(--muted); font-size: 20px; padding: 4px 8px; }
.empty { text-align: center; color: var(--muted); padding: 30px 20px; font-size: 14px; }
.submit-btn { width: 100%; margin-top: 16px; padding: 15px; background: var(--green); color: #fff; border: none; border-radius: 12px; font-size: 16px; font-weight: 700; position: sticky; bottom: 12px; }

/* ---------- История ---------- */
.history-day { margin-bottom: 18px; }
.history-day h3 { color: var(--brand); font-size: 14px; margin: 0 0 8px; }

/* ---------- Тост ---------- */
.toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); background: #000; color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.4); }

/* Daily files and administrator */
button:disabled { opacity: .55; cursor: wait; }
.search-bar input { min-width: 0; width: 100%; }
.branch { min-width: 0; }
.logo-sm { max-width: 115px; object-fit: contain; }
#branch-name { max-width: 155px; overflow-wrap: anywhere; }
.entry .name, .entry .meta { overflow-wrap: anywhere; }
.save-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.admin-filters { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.admin-filters label { color: var(--muted); font-size: 13px; }
.branch-select, .date-input { width: 100%; min-width: 0; padding: 12px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 14px; color-scheme: dark; }
.date-row { display: flex; gap: 10px; }
.date-row label { flex: 1; min-width: 0; }
.date-input { display: block; margin-top: 6px; }
.dl-row { display: flex; gap: 8px; }
.dl-row .dl-btn { flex: 1; }
.dl-btn { border: none; border-radius: 10px; padding: 12px; background: var(--brand); color: white; font-weight: 600; font-size: 14px; }
.dl-btn.csv { background: var(--surface-2); border: 1px solid var(--border); }
.file-card { margin: 16px 0; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.file-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.file-title { min-width: 0; }
.file-branch { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.file-day { color: var(--muted); font-size: 12px; margin-top: 5px; }
.file-acts { display: flex; gap: 5px; flex-shrink: 0; }
.dl-btn.sm { padding: 8px; font-size: 12px; }
.file-card .entry-list { margin-top: 12px; }
.file-card .entry { background: var(--surface-2); }
.file-delete { display: block; width: 100%; margin-top: 12px; padding: 10px; border: 1px solid var(--red); border-radius: 10px; background: transparent; color: var(--red); font-weight: 600; font-size: 13px; cursor: pointer; }
.tabs { position: static; }
.type-tag { display: inline-block; font-size: 11px; padding: 2px 6px; margin-left: 6px; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); }
.type-tag.bad { background: #352146; border-color: #9360b8; color: #ddb7f5; }
#custom-category-row { display: block; margin-bottom: 12px; }
#custom-category { margin-top: 6px; }
