:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 4px 16px rgba(15,23,42,.05);
}

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

body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb 55%, #3b82f6);
  padding: 16px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
}
.login-logo { text-align: center; }
.login-logo img { height: 84px; width: auto; }
.topbar-title { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.topbar-logo { height: 30px; width: auto; }
.login-card h1 { text-align: center; font-size: 22px; margin-top: 8px; }
.login-sub { text-align: center; color: var(--muted); margin: 4px 0 20px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.login-err { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 4px; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 8px; padding: 9px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(15,23,42,.06); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn-block { width: 100%; margin-top: 18px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--card); padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-user { margin-left: auto; color: var(--muted); font-size: 13px; }
.topnav { display: flex; gap: 4px; margin-left: 12px; }
.nav-btn { border-radius: 8px; }
.nav-btn.nav-active { background: var(--primary); color: #fff; }
.nav-btn.nav-active:hover { background: var(--primary-dark); color: #fff; }
.zoom-ctl { display: flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.zoom-btn { padding: 4px 9px; font-size: 13px; border-radius: 6px; }
.zoom-val { min-width: 52px; font-variant-numeric: tabular-nums; }
.zoom-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* ---------- List ---------- */
#list-view { margin: 0 auto; padding: 20px; }
.list-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-input {
  flex: 1; min-width: 220px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none;
}
.search-input:focus { border-color: var(--primary); }
.list-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.filter-panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.fgroup label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.fgroup select, .fgroup input[type=date] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; background: #fff; outline: none;
}
.filter-actions { display: flex; align-items: flex-end; gap: 8px; }

.table-wrap {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); overflow: auto;
}
.req-table { width: 100%; border-collapse: collapse; }
.req-table th {
  position: sticky; top: 0; background: #f8fafc; text-align: left;
  padding: 7px 10px; font-size: 12px; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap;
  cursor: pointer; user-select: none;
}
.req-table th:hover { color: var(--text); }
.req-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  vertical-align: middle; white-space: nowrap; font-size: 13px;
}
.req-table tbody tr { cursor: pointer; }
.req-table tbody tr:hover { background: #f1f5ff; }
.req-table tbody tr:last-child td { border-bottom: none; }
.cell-ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.st-new { background: #e2e8f0; color: #475569; }
.st-inwork { background: #fef3c7; color: #92400e; }
.st-work { background: #ffedd5; color: #9a3412; }
.st-done { background: #dcfce7; color: #166534; }
.st-cancel { background: #ede9fe; color: #6d28d9; }

.list-empty { text-align: center; padding: 40px; color: var(--muted); }

/* ---------- Calendar (вид «Месяц») ---------- */
#cal-view { margin: 0 auto; padding: 20px; }
.cal-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-title { font-size: 17px; font-weight: 700; margin-left: 6px; }
.cal-toolbar .spacer { flex: 1; }
.cal-legend { display: flex; gap: 6px; flex-wrap: wrap; }
.cal-layout { display: flex; gap: 14px; align-items: flex-start; }
.cal-side {
  flex: none; width: 216px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
  position: sticky; top: 64px;
}
.cal-side .btn-block { margin-bottom: 12px; }
.cal-mini-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-mini-title { font-size: 13px; font-weight: 700; }
.cal-mini-wd, .cal-mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.cal-mini-wd { font-size: 11px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
.cal-mini-day {
  font-size: 12px; padding: 4px 0; cursor: pointer; border-radius: 50%;
  width: 24px; height: 24px; line-height: 16px; margin: 0 auto;
}
.cal-mini-day:hover { background: #f1f5ff; }
.cal-mini-day.other { color: #cbd5e1; }
.cal-mini-day.today { background: var(--danger); color: #fff; }
.cal-side-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin: 12px 0 6px; }
.cal-side .cal-legend { flex-direction: column; align-items: stretch; }
.cal-side .cal-chip { justify-content: flex-start; }
.cal-main { flex: 1; min-width: 0; }
@media (max-width: 900px) {
  .cal-layout { flex-direction: column; }
  .cal-side { width: 100%; position: static; }
}
.cal-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--text);
}
.cal-chip.off { opacity: .4; }
.cal-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.cal-grid { padding: 12px; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-body { display: flex; flex-direction: column; }
.cal-week { flex: 1 1 0; display: flex; flex-direction: column; min-height: 0; }
.cal-nums, .cal-ovs { flex: none; }
.cal-lanes { flex: 1; min-height: 30px; }
.cal-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.cal-head > div { padding: 6px 8px; }
.cal-body { border-top: 1px solid var(--border); }
.cal-week { border-bottom: 1px solid var(--border); }
.cal-nums, .cal-ovs { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-numcell {
  border-left: 1px solid var(--border); padding: 4px 8px; background: #fff;
}
.cal-numcell:last-child { border-right: 1px solid var(--border); }
.cal-numcell.weekend { background: #f8fafc; }
.cal-search { max-width: 240px; flex: none; }
.cal-numcell.other .cal-num { color: #cbd5e1; }
.cal-numcell.today .cal-num {
  background: var(--danger); color: #fff; border-radius: 50%;
  width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center;
}
.cal-num { font-size: 13px; font-weight: 600; cursor: pointer; display: inline-block; padding: 1px 2px; }
.cal-num:hover { text-decoration: underline; }
.cal-lanes {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px 0;
  grid-auto-rows: max-content; align-content: start;
  background: repeating-linear-gradient(to right, transparent 0, transparent calc(100%/7 - 1px), var(--border) calc(100%/7 - 1px), var(--border) calc(100%/7));
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  padding: 2px 0;
  flex: 1; min-height: 30px;
}
.cal-bar { align-self: start; }
.cal-ovs { min-height: 20px; }
.cal-ovcell { border-left: 1px solid var(--border); padding: 0 4px; background: #fff; }
.cal-ovcell:last-child { border-right: 1px solid var(--border); }
.cal-more { font-size: 12px; color: var(--primary); cursor: pointer; padding: 0 7px; }
.cal-more:hover { text-decoration: underline; }
/* Полосы-блоки внутри недели: одна надпись на весь отрезок */
.cal-bar {
  font-size: 12px; line-height: 19px; padding: 0 7px; margin: 0 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
  min-width: 0;
}
.cal-bar.k-request { background: #dbeafe; color: #1d4ed8; }
.cal-bar.k-task { background: #fef3c7; color: #92400e; }
.cal-bar.k-vacation { background: #dcfce7; color: #166534; }
.cal-bar.overdue { background: #fee2e2; color: #b91c1c; font-weight: 700; }
.cal-bar.span-start { border-radius: 5px 0 0 5px; }
.cal-bar.span-mid { border-radius: 0; }
.cal-bar.span-end { border-radius: 0 5px 5px 0; }
.cal-bar.single { border-radius: 5px; }
/* Пилюли вида «Неделя» (полоса «Весь день») */
.cal-pill {
  font-size: 12px; line-height: 1.35; padding: 1px 7px; border-radius: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.cal-pill.k-request { background: #dbeafe; color: #1d4ed8; }
.cal-pill.k-task { background: #fef3c7; color: #92400e; }
.cal-pill.k-vacation { background: #dcfce7; color: #166534; }
.cal-pill.overdue { background: #fee2e2; color: #b91c1c; font-weight: 700; }
.cal-loading { padding: 30px; text-align: center; color: var(--muted); }
.cal-dayrow {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px;
  border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.cal-dayrow:last-child { border-bottom: none; }
.cal-dayrow:hover { background: #f8fafc; }

/* ---------- Calendar: вид «Неделя» ---------- */
.cal-create-btn { background: #ffcc00; color: #1a1a1a; font-weight: 700; }
.cal-create-btn:hover { background: #f5c000; color: #1a1a1a; }
#cal-viewsel { cursor: pointer; }
.calw-head, .calw-allday { display: grid; grid-template-columns: 64px repeat(7, 1fr); }
.calw-body {
  display: grid; grid-template-columns: 64px repeat(7, 1fr);
  max-height: 46vh; overflow-y: auto; border-top: 1px solid var(--border);
}
.calw-gutter { font-size: 11px; color: var(--muted); padding: 4px 6px 4px 0; text-align: right; }
.calw-dayhead { text-align: center; padding: 6px 4px; font-size: 13px; }
.calw-dayhead.today b {
  background: var(--danger); color: #fff; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
}
.calw-allday { border-top: 1px solid var(--border); border-bottom: 2px solid var(--border); }
.calw-allday-label { font-size: 11px; align-self: start; }
.calw-cell {
  border-left: 1px solid var(--border); padding: 4px; min-height: 54px;
  display: flex; flex-direction: column; gap: 2px; overflow-y: auto; max-height: 130px;
  background: #fff;
}
.calw-slot { border-left: 1px solid #eef2f7; border-bottom: 1px solid #f1f5f9; min-height: 28px; cursor: pointer; }
.calw-slot:hover { background: #f8fafc; }

/* ---------- Detail / Edit ---------- */
#detail-view { margin: 0 auto; padding: 20px; }
.detail-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--card); padding: 14px 20px;
  border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.detail-head h2 { font-size: 18px; }
.detail-head .spacer { flex: 1; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 14px; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 8px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.fgroup input[type=text], .fgroup input[type=number], .fgroup input[type=date], .fgroup textarea,
.fgroup select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; background: #fff; outline: none;
}
.fgroup input:focus, .fgroup select:focus, .fgroup textarea:focus { border-color: var(--primary); }
.fgroup textarea { resize: vertical; min-height: 70px; }
.fgroup-wide { grid-column: 1 / -1; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 16px; }
.kv { border-bottom: 1px dashed #eef2f7; padding-bottom: 6px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-weight: 600; }
.kv .v.empty { color: #cbd5e1; font-weight: 400; }

/* ---------- Notes / children lists ---------- */
.plain-list { list-style: none; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.plain-list li:last-child { border-bottom: none; }
.plain-list .muted { color: var(--muted); font-size: 12px; }
a.contact-link { color: var(--primary); text-decoration: underline; }
a.contact-link:hover { color: var(--primary-dark); }

.rep-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.rep-row {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap;
}
.rep-row input, .rep-row select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none; flex: 1; min-width: 120px; }
.rep-del { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 16px; }

.notes-box {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; white-space: pre-wrap; font-size: 13px;
}

.form-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- Multi-selects, checkboxes, departments ---------- */
select[multiple] { min-height: 90px; }
.chk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 12px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.chk input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
.dept-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: #fbfdff; }
.dept-block { border-bottom: 1px dashed var(--border); padding: 8px 0; }
.dept-block:last-child { border-bottom: none; }
.dept-chk { font-size: 13px; }
.asg-sel { width: 100%; margin-top: 6px; min-height: 64px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.asg-sub { margin: 2px 0 2px 8px; padding-left: 10px; border-left: 2px solid var(--border); }
.asg-sub > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.asg-sub .rep-row { margin-bottom: 6px; }

/* ---------- Autocomplete ---------- */
.ac-wrap { position: relative; }
.ac-wrap input[type=text] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; outline: none; }
.ac-wrap input[type=text]:focus { border-color: var(--primary); }
.ac-wrap input[type=text]:disabled, .fgroup input:disabled, .fgroup textarea:disabled {
  background: #f1f5f9; color: #94a3b8; cursor: not-allowed;
}
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: #fff; border: 1px solid var(--border); border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgba(15,23,42,.15); max-height: 240px; overflow-y: auto;
}
.ac-item { padding: 8px 12px; font-size: 13px; cursor: pointer; }
.ac-item:hover, .ac-item.active { background: #f1f5ff; }
.ac-empty { padding: 8px 12px; font-size: 13px; color: var(--muted); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s; pointer-events: none; font-size: 14px;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.err { background: var(--danger); }

@media (max-width: 700px) {
  .kv-grid, .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Modal ---------- */
.modal-ov {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  padding: 20px 22px;
}
.modal-card h3 { font-size: 16px; margin-bottom: 14px; }
.modal-err { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.ac-item.ac-create { color: var(--primary); font-weight: 600; }
.cp-sub { font-size: 12px; padding: 2px 0 0 2px; }
.cp-sub:empty { display: none; }
.totp-qr svg { width: 220px; height: 220px; display: block; }
