:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e8ef;
  --text: #172033;
  --muted: #6b7686;
  --brand: #16304f;
  --brand-2: #234a76;
  --accent: #d9932b;
  --accent-soft: #fdf3e3;
  --green: #1f9254;
  --green-soft: #e8f6ee;
  --red: #c8472f;
  --red-soft: #fbecea;
  --blue: #2c6fbd;
  --blue-soft: #eaf2fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 51, .06), 0 6px 20px rgba(16, 32, 51, .05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 10px; }

/* ---------- Вход ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(150deg, #16304f 0%, #234a76 55%, #2c6fbd 100%);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px;
  padding: 32px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--brand); color: #cfdcea; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 6px 12px 18px; }
.brand b { color: #fff; font-size: 16px; display: block; letter-spacing: -.01em; }
.brand span { font-size: 12px; color: #8ba6c4; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: #cfdcea; cursor: pointer; font-size: 14.5px; border: 0; background: none; width: 100%;
  text-align: left; font-family: inherit;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #23180a; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; opacity: .95; }
.nav-badge { margin-left: auto; background: rgba(255,255,255,.16); border-radius: 20px; padding: 1px 7px; font-size: 11.5px; }
.nav-item.active .nav-badge { background: rgba(0,0,0,.15); }
.sidebar-foot { margin-top: auto; padding: 14px 12px 4px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot .role { color: #8ba6c4; font-size: 12px; margin-bottom: 10px; }

.main { padding: 26px 30px 60px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 220px; }
.page-head p { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

/* ---------- Элементы ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.card > h3 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }

button, .btn {
  font-family: inherit; font-size: 14px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-weight: 500; transition: .12s; line-height: 1.35;
}
button:hover, .btn:hover { background: var(--surface-2); border-color: #cfd8e3; text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #23180a; }
.btn-accent:hover { background: #c9861f; border-color: #c9861f; }
.btn-danger { color: var(--red); border-color: #f0cdc6; background: var(--red-soft); }
.btn-danger:hover { background: #f7ddd8; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef1f5; }

input, select, textarea {
  font-family: inherit; font-size: 14px; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd3ee; outline-offset: -1px; border-color: #8fb6e0; }
textarea { resize: vertical; min-height: 76px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
.inline-field { display: flex; gap: 8px; align-items: center; }
.checkbox { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); }
.checkbox input { width: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px;
  font-size: 12.5px; font-weight: 600; background: #eef1f5; color: var(--muted); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--accent-soft); color: #9a6a12; }
.badge.gray { background: #eef1f5; color: var(--muted); }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 7px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12.5px; margin: 0 5px 5px 0; color: var(--muted);
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 27px; font-weight: 680; letter-spacing: -.02em; }
.stat .l { font-size: 13px; color: var(--muted); margin-top: 2px; }

.bar { height: 8px; background: #eef1f5; border-radius: 20px; overflow: hidden; position: relative; min-width: 90px; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 20px; }
.bar.good > i { background: var(--green); }
.bar.warn > i { background: var(--accent); }
.bar.bad > i { background: var(--red); }
.bar-plan { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #98a4b3; }

.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: .5; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit; }
.tab:hover { color: var(--text); background: none; }
.tab.active { color: var(--brand); border-bottom-color: var(--accent); font-weight: 600; }

.list-item { padding: 13px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }

/* ---------- Календарь ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal .dow { background: var(--surface-2); padding: 7px; text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.cal .day { background: var(--surface); min-height: 104px; padding: 6px; font-size: 12.5px; }
.cal .day.out { background: var(--surface-2); opacity: .55; }
.cal .day.today { background: #fffdf6; box-shadow: inset 0 0 0 2px var(--accent); }
.cal .day .n { font-weight: 600; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.cal-ev { display: block; width: 100%; text-align: left; border: 0; padding: 3px 6px; border-radius: 6px; background: var(--blue-soft); color: #1c4f8c; font-size: 11.5px; margin-bottom: 3px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: inherit; }
.cal-ev:hover { background: #dbe9f9; }
.cal-ev.mine { background: var(--accent-soft); color: #8a5f0f; }
.cal-ev.going { background: var(--green-soft); color: var(--green); }

.slot {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 9px; margin-bottom: 7px; background: var(--surface); font-size: 14px;
}
.slot.free { border-color: #bfe0cc; background: #f4fbf7; }
.slot.event { background: var(--surface-2); color: var(--muted); }
.slot.booked { background: #f6f7f9; color: var(--muted); }
.slot.mine { border-color: var(--accent); background: var(--accent-soft); }
.slot .time { font-family: var(--mono); font-weight: 600; font-size: 13.5px; min-width: 96px; }

/* ---------- Чат ---------- */
.chat-box { height: 56vh; min-height: 320px; overflow-y: auto; padding: 4px 4px 10px; }
.msg { display: flex; gap: 10px; padding: 9px 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand-2); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 600; flex: 0 0 34px;
}
.avatar.staff { background: var(--accent); color: #23180a; }
.msg .body { flex: 1; min-width: 0; }
.msg .meta { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.msg .meta b { color: var(--text); font-size: 13.5px; }
.msg .text { white-space: pre-wrap; word-break: break-word; }

/* ---------- Тесты ---------- */
.q { padding: 15px 0; border-bottom: 1px solid var(--border); }
.q .qt { margin-bottom: 9px; font-size: 15px; }
.q .qn { color: var(--muted); font-family: var(--mono); font-size: 12.5px; margin-right: 6px; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; }
.opt { flex: 1 1 130px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; font-size: 12.5px; text-align: center; font-family: inherit; }
.opt:hover { border-color: #8fb6e0; }
.opt.sel { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.scale-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; font-size: 13.5px; }
.scale-row .nm { min-width: 175px; }
.scale-row .val { font-family: var(--mono); min-width: 44px; text-align: right; font-weight: 600; }

/* ---------- Модальное окно и уведомления ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(12, 22, 36, .5); display: grid; place-items: center; padding: 20px; z-index: 60; }
.modal { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 70px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #172033; color: #fff; padding: 11px 15px; border-radius: 10px; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 380px; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

.hint { background: var(--accent-soft); border: 1px solid #f0dcb8; border-radius: 10px; padding: 11px 13px; font-size: 13.5px; color: #7a5510; margin-bottom: 14px; }
.hint b { color: #5f420c; }

/* ---------- Переключатель языка ---------- */
.lang-switch { display: inline-flex; gap: 2px; background: rgba(255,255,255,.1); border-radius: 8px; padding: 2px; margin-bottom: 12px; }
.lang-btn {
  border: 0; background: none; color: #9fb4cc; font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  padding: 4px 9px; border-radius: 6px; cursor: pointer; font-family: inherit;
}
.lang-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.lang-btn.active { background: var(--accent); color: #23180a; }
.lang-switch.on-login { background: #eef1f5; float: right; margin: -8px 0 0; }
.lang-switch.on-login .lang-btn { color: var(--muted); }
.lang-switch.on-login .lang-btn:hover { background: #e2e7ee; color: var(--text); }
.lang-switch.on-login .lang-btn.active { background: var(--brand); color: #fff; }

@media (max-width: 900px) {
  /* minmax(0,...) и min-width:0 не дают широким таблицам растянуть страницу вбок */
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .main { min-width: 0; }
  /* Подпись «Занято: мероприятие» переносится, а не растягивает строку окошка */
  .slot { flex-wrap: wrap; }
  .slot .time { min-width: auto; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .brand { width: 100%; padding-bottom: 10px; }
  .nav-item { width: auto; }
  .sidebar-foot { width: 100%; margin-top: 8px; }
  .main { padding: 18px 14px 50px; }
}
