/* ===== Документи Ліцею ===== */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --text: #171c26;
  --text-2: #4b5565;
  --muted: #7b8494;
  --border: #e4e7ee;
  --border-strong: #d3d8e2;

  --accent: #2f5bd3;
  --accent-hover: #2549b3;
  --accent-soft: #eaf0fe;
  --accent-text: #2547a8;

  --ok: #16834a;      --ok-soft: #e4f5eb;
  --warn: #a35d00;    --warn-soft: #fff1d6;
  --bad: #c2352b;     --bad-soft: #fde9e7;
  --info: #2f5bd3;    --info-soft: #eaf0fe;
  --grey: #5f6878;    --grey-soft: #eef0f4;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, .10);
  --sidebar: 248px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --surface: #181d26;
    --surface-2: #1d232e;
    --text: #e8ebf1;
    --text-2: #b5bccb;
    --muted: #8a93a5;
    --border: #283040;
    --border-strong: #343e51;

    --accent: #5b82f0;
    --accent-hover: #7194f5;
    --accent-soft: #1f2a46;
    --accent-text: #a9bff9;

    --ok: #4cc685;      --ok-soft: #173326;
    --warn: #f0b04f;    --warn-soft: #3a2c13;
    --bad: #f07a6f;     --bad-soft: #3d1d1b;
    --info: #7f9ff5;    --info-soft: #1f2a46;
    --grey: #a3abba;    --grey-soft: #262d3a;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.ico { flex-shrink: 0; display: block; }

h1 { font-size: 1.6rem; line-height: 1.25; letter-spacing: -.02em; margin: 0 0 1.2rem; font-weight: 700; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; margin: 2rem 0 .8rem; font-weight: 650; }
h3 { font-size: 1rem; margin: 0 0 .5rem; font-weight: 650; }
p { margin: 0 0 .7rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
b, strong { font-weight: 600; }

/* ===== Каркас ===== */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; z-index: 20;
}
.main { min-height: 100vh; display: flex; flex-direction: column; }
.app .main { margin-left: var(--sidebar); }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 32px 32px 40px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 0 16px 24px; }

.brand { display: flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none !important; padding: 4px 8px 18px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3d6cf0, #2346b8); color: #fff; box-shadow: 0 4px 12px rgba(47, 91, 211, .35);
}
.brand-mark.lg { width: 52px; height: 52px; border-radius: 14px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: .8rem; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; text-decoration: none; transition: background .15s, color .15s;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.side-nav a .count {
  margin-left: auto; font-style: normal; font-size: .75rem; font-weight: 700;
  background: var(--accent); color: #fff; border-radius: 20px; padding: 1px 8px; min-width: 22px; text-align: center;
}

.side-user {
  display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; border-top: 1px solid var(--border); margin-top: 12px;
}
.side-user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.side-user-text b { font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-text small { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent-text); font-weight: 700; font-size: .8rem;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  color: var(--muted); text-decoration: none !important; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.mobilebar, .tabbar { display: none; }

/* Сторінки входу */
.auth .main { justify-content: flex-start; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 48px 16px 8px; }
.auth-brand .brand-text b { font-size: 1.25rem; }
.auth .wrap { max-width: 460px; padding-top: 20px; }
.login-box { max-width: 440px; margin: 0 auto; }
.login-box h1 { text-align: center; font-size: 1.35rem; }

/* ===== Картки ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { display: flex; align-items: center; gap: 8px; }
.card > :last-child { margin-bottom: 0; }
.card.highlight { border-left: 4px solid var(--warn); }
.card.done { border-left: 4px solid var(--ok); }

.order-head { display: flex; justify-content: space-between; gap: 6px 14px; flex-wrap: wrap; align-items: baseline; }
.order-num { font-weight: 650; color: var(--accent-text); font-size: .9rem; }
.order-title { margin: 6px 0 14px; font-size: 1.02rem; font-weight: 500; line-height: 1.45; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* Статистика */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; color: inherit; text-decoration: none !important; transition: border-color .15s, transform .15s;
  display: flex; flex-direction: column; gap: 2px;
}
a.stat:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.stat b { font-size: 1.75rem; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: .84rem; }

/* ===== Кнопки ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: .92rem; font-weight: 550; text-decoration: none !important; cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(47, 91, 211, .3); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: var(--ok); filter: brightness(1.07); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad-soft); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: .84rem; border-radius: 9px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: grayscale(.3); }

/* ===== Позначки ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px;
  font-size: .76rem; font-weight: 600; white-space: nowrap; line-height: 1.4;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-ok   { background: var(--ok-soft);   color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad  { background: var(--bad-soft);  color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-grey { background: var(--grey-soft); color: var(--grey); }

.flash {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: .92rem; border: 1px solid transparent;
}
.flash .ico { margin-top: 2px; }
.flash-ok    { background: var(--ok-soft);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 20%, transparent); }
.flash-error { background: var(--bad-soft);  color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 20%, transparent); }
.flash-info  { background: var(--info-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--info) 20%, transparent); display: block; }
.flash a { color: inherit; text-decoration: underline; }
.flash-info > .ico { display: inline-block; vertical-align: -4px; margin-right: 8px; }

/* Порожній стан */
.empty { text-align: center; padding: 34px 20px; }
.empty .empty-ico {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 12px;
  background: var(--ok-soft); color: var(--ok);
}
.empty b { display: block; font-size: 1.02rem; margin-bottom: 2px; }

.progress { height: 6px; background: var(--grey-soft); border-radius: 6px; overflow: hidden; min-width: 80px; margin-top: 5px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 6px; }

/* ===== Форми ===== */
label { display: block; font-weight: 550; font-size: .86rem; margin: 14px 0 6px; color: var(--text-2); }
label.check { font-weight: 450; display: flex; gap: 10px; align-items: center; color: var(--text); font-size: .92rem; cursor: pointer; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: .93rem; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
.hint { color: var(--muted); font-size: .8rem; margin-top: 5px; line-height: 1.45; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid2 > .card { margin-bottom: 0; }
.grid2:has(> .card) { gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 14px; }
.form-actions { margin-top: 18px; display: flex; gap: 8px; flex-wrap: wrap; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=text] { flex: 1; min-width: 180px; width: auto; }
.filters select { width: auto; min-width: 190px; }

/* ===== Таблиці ===== */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th {
  background: var(--surface-2); font-size: .74rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
}
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.nowrap { white-space: nowrap; }
.tbl td.grow { width: 48%; min-width: 200px; }
.tbl th, .tbl td { padding-left: 14px; padding-right: 14px; }
.tbl td a b { color: var(--text); }
.tbl td a:hover b { color: var(--accent); }

code, .code {
  background: var(--grey-soft); color: var(--text-2); padding: 2px 7px; border-radius: 6px;
  font-size: .82rem; word-break: break-all; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.copy-row { display: flex; gap: 8px; align-items: center; }

/* Вибір отримувачів наказу */
.audience { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.audience-opt {
  display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 14px 16px; cursor: pointer;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text); font-weight: 400;
  transition: border-color .15s, background .15s;
}
.audience-opt:hover { border-color: var(--accent); }
.audience-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.audience-opt input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.audience-opt span { display: flex; flex-direction: column; line-height: 1.35; }
.audience-opt small { color: var(--muted); font-size: .8rem; }
.people { margin-top: 14px; }
.people[hidden] { display: none; }
.people-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.people-tools input { flex: 1; min-width: 200px; width: auto; }
.people-list {
  max-height: 380px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); overflow-x: hidden;
}
.person .badge { flex-shrink: 0; }
.person {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-weight: 400; color: var(--text);
}
.person[hidden] { display: none; }
.person:hover { background: var(--surface-2); }
.person:has(input:checked:not(:disabled)) { background: var(--accent-soft); }
.person.is-sent { cursor: default; opacity: .7; }
.person-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.person-text b { font-size: .88rem; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-text small { font-size: .76rem; color: var(--muted); }
.avatar.sm { width: 30px; height: 30px; font-size: .72rem; }
@media (max-width: 860px) {
  .audience { grid-template-columns: 1fr; }
  .people-list { grid-template-columns: minmax(0, 1fr); max-height: 55vh; }
  .person .badge { font-size: .68rem; padding: 2px 7px; }
}

/* Посилання, що копіюється натисканням */
.copy-link {
  position: relative; display: inline-flex; align-items: center; gap: 7px; max-width: 100%;
  padding: 6px 10px; border: 1px dashed var(--border-strong); border-radius: 9px;
  background: var(--surface-2); color: var(--text-2); cursor: pointer;
  font: 500 .8rem/1.3 ui-monospace, "Cascadia Mono", Consolas, monospace;
  transition: border-color .15s, background .15s, color .15s;
}
.tbl .copy-link { max-width: 230px; }
.copy-link:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.copy-link .copy-link-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.copy-link.copied { border-style: solid; border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.copy-link.copied .copy-link-text { visibility: hidden; }
.copy-link.copied::after {
  content: "✓ Скопійовано"; position: absolute; left: 32px; top: 50%; transform: translateY(-50%);
  font-family: var(--font); font-weight: 600;
}
.copy-row input { font-size: .84rem; }
.pager { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .88rem; margin-bottom: 10px; }
.back-link:hover { color: var(--text); text-decoration: none; }

/* ===== Перегляд документа ===== */
.viewer { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.viewer-bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0; }
.viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.viewer-title small { color: var(--accent-text); font-weight: 600; font-size: .78rem; }
.viewer-title b { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-ext { flex-shrink: 0; }
.viewer-flash { margin: 10px 14px 0; flex-shrink: 0; }
.viewer-doc { flex: 1; min-height: 0; background: #e9ebf0; position: relative; }
.viewer-doc iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-nopreview { max-width: 420px; margin: 40px auto; text-align: center; }
.viewer-actions {
  flex-shrink: 0; padding: 12px 14px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: center;
}
.viewer-actions:empty { display: none; }
.viewer-actions form { width: 100%; max-width: 520px; margin: 0; }
.viewer-ack { width: 100%; min-height: 50px; font-size: 1rem; }
.viewer-done { display: flex; align-items: center; gap: 8px; color: var(--ok); font-weight: 600; padding: 8px 0; }
@media (max-width: 560px) {
  .viewer-ext span { display: none; }
}

/* ===== Планшет ===== */
@media (max-width: 1080px) {
  .wrap { padding: 26px 22px 36px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
}

/* ===== Телефон ===== */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .app .main { margin-left: 0; }
  .mobilebar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 20; padding: 10px 12px 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--surface);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--border);
  }
  .mobilebar .brand { padding: 0; gap: 10px; }
  .mobilebar .brand-mark { width: 32px; height: 32px; border-radius: 9px; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border); padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 2px;
    color: var(--muted); font-size: .68rem; font-weight: 550; text-decoration: none !important; border-radius: 10px;
  }
  .tabbar a.active { color: var(--accent); }
  .tab-ico { position: relative; }
  .tab-ico .dot {
    position: absolute; top: -5px; right: -10px; font-style: normal; font-size: .62rem; font-weight: 700;
    background: var(--bad); color: #fff; border-radius: 10px; padding: 0 5px; line-height: 16px; min-width: 16px; text-align: center;
  }
  .has-tabbar .main { padding-bottom: 72px; }

  .wrap { padding: 18px 14px 28px; }
  h1 { font-size: 1.35rem; margin-bottom: 1rem; }
  h2 { margin-top: 1.6rem; }
  .card { padding: 16px; }
  .grid2, .grid4 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat b { font-size: 1.45rem; }
  .actions .btn { flex: 1 1 auto; }
  .filters input[type=text] { flex-basis: 100%; }
  .filters select { min-width: 0; flex: 1; }

  .table-wrap { background: transparent; border: none; box-shadow: none; overflow: visible; }
  table.tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { display: none; }
  .tbl tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 10px; padding: 8px 0; box-shadow: var(--shadow);
  }
  .tbl tbody tr:hover { background: var(--surface); }
  .tbl td { border: none; padding: 5px 16px; }
  .tbl td.grow { width: 100%; min-width: 0; }
  .tbl .copy-link { max-width: 100%; }
  .tbl td:empty { display: none; }
  .tbl td[data-label]::before {
    content: attr(data-label); display: block; font-size: .7rem; color: var(--muted);
    font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 1px;
  }
  .tbl td .btn { width: 100%; margin-top: 4px; }

  .auth-brand { padding-top: 32px; }
}

@media (max-width: 330px) {
  .stats { grid-template-columns: 1fr; }
}

/* Повернення до наказу в списку: рядок не ховається під верхньою панеллю і коротко підсвічується */
.tbl tr[id^="o"] { scroll-margin-top: 80px; }
.tbl tr:target > td { animation: row-flash 2.4s ease-out; }
@keyframes row-flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
