:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e2e6ee;
  --text: #1b2333;
  --muted: #6b7590;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.logo { font-weight: 700; font-size: 16px; letter-spacing: -.2px; white-space: nowrap; }
.logo span { color: var(--accent); }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab {
  padding: 7px 14px; border-radius: 8px; border: 1px solid transparent;
  background: none; cursor: pointer; color: var(--muted); font-weight: 500;
}
.tab:hover { background: #f0f3f9; color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); border-color: #cfe0ff; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card p.hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }

/* ---------- controls ---------- */
.btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #c8d0e0; background: #fafbfe; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #f3c9c9; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], select, textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.checkline { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.checkline input { width: auto; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f7f9fc; font-weight: 600; font-size: 12.5px; color: var(--muted);
     text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; z-index: 5; white-space: nowrap; }
tbody tr:hover { background: #fafbff; }
tr.group-row td { background: #eef2fb; font-weight: 600; color: var(--text); }
td.actions { white-space: nowrap; text-align: right; }
td.note-cell { min-width: 220px; position: relative; }
.note-inner { display: flex; align-items: center; gap: 6px; }
.note-text { flex: 1; padding: 3px 6px; border-radius: 6px; min-height: 22px; cursor: text; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: #eef1f7; color: var(--muted); }
.badge.soon { background: #fff4e5; color: #b45309; }
.badge.today { background: #dcfce7; color: #15803d; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.off { background: #fee2e2; color: #b91c1c; }
.muted { color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- colors ---------- */
.swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch { width: 20px; height: 20px; border-radius: 5px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; }
.swatch.none { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #e5e7eb 4px, #e5e7eb 8px); }
.color-pop {
  position: absolute; z-index: 30; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; box-shadow: var(--shadow);
}

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto;
}
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: var(--shadow); }
.modal.wide { max-width: 900px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal .body { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.hidden { display: none !important; }

/* ---------- login ---------- */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
#login-screen .card { width: 360px; }

/* ---------- toast ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; border-radius: 8px; background: #1f2937; color: #fff; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }


/* ---------- карточка сотрудника ---------- */
.tabs-inner { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px -4px 16px; flex-wrap: wrap; }
.tab-inner {
  padding: 8px 14px; border: none; background: none; cursor: pointer;
  color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent;
}
.tab-inner:hover { color: var(--text); }
.tab-inner.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { display: none; }
.tab-body.active { display: block; }

/* ---------- дети ---------- */
.child-row {
  display: grid; grid-template-columns: 1fr 150px 130px 90px 36px;
  gap: 8px; align-items: center; padding: 8px; border-radius: 8px; margin-bottom: 8px;
}
.child-row.boy { background: #EAF4FF; border: 1px solid #C7E1FF; }
.child-row.girl { background: #FFEAF3; border: 1px solid #FFC9DF; }
.child-age { font-size: 12px; color: var(--muted); text-align: right; }
tbody tr.boy td:first-child { box-shadow: inset 4px 0 0 #6BB1F0; }
tbody tr.girl td:first-child { box-shadow: inset 4px 0 0 #F08CB6; }

.badge.long { background: #e0e7ff; color: #3730a3; }
.badge.kids { background: #ede9fe; color: #5b21b6; }

/* ============ адаптив: планшеты ============ */
@media (max-width: 1100px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .logo { font-size: 15px; }
  main { padding: 14px; }
}

/* ============ адаптив: телефоны ============ */
@media (max-width: 760px) {
  body { font-size: 15px; }

  .topbar {
    flex-wrap: wrap; gap: 8px; padding: 8px 12px;
    align-items: center;
  }
  .logo { font-size: 15px; flex: 1; }
  .logo span { display: none; }
  .userbox { font-size: 12px; }
  .userbox #who { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabs {
    order: 3; flex: 0 0 100%; width: 100%; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 6px 12px; font-size: 14px; white-space: nowrap; }

  main { padding: 12px; }
  .card { padding: 14px; }

  /* панели инструментов — в колонку, элементы на всю ширину */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar > * { max-width: none !important; width: 100%; }
  .toolbar .grow { display: none; }
  .toolbar .checkline { justify-content: flex-start; }
  .btn { padding: 10px 14px; }
  .btn.sm { padding: 6px 10px; }

  .grid2 { grid-template-columns: 1fr; }

  /* модальные окна на всю ширину */
  .modal-back { padding: 12px; align-items: flex-start; }
  .modal { max-width: 100%; }
  .modal .body { padding: 14px; max-height: 70vh; overflow-y: auto; }
  .modal footer { padding: 12px 14px; }
  .modal footer .btn { flex: 1; }

  /* таблицы превращаются в карточки */
  #emp-table, #store-table, #bd-table, #tg-table, #user-table, #imp-hier-table,
  #emp-table tbody, #store-table tbody, #bd-table tbody, #tg-table tbody,
  #user-table tbody, #imp-hier-table tbody { display: block; width: 100%; }
  #emp-table thead, #store-table thead, #bd-table thead, #tg-table thead,
  #user-table thead, #imp-hier-table thead { display: none; }
  #emp-table tbody tr, #store-table tbody tr, #bd-table tbody tr, #tg-table tbody tr,
  #user-table tbody tr, #imp-hier-table tbody tr {
    display: block; padding: 10px 12px; border-bottom: 1px solid var(--line);
  }
  #emp-table tbody td, #store-table tbody td, #bd-table tbody td, #tg-table tbody td,
  #user-table tbody td, #imp-hier-table tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    border: none; padding: 3px 0; text-align: left; min-width: 0;
  }
  #emp-table tbody td:empty, #store-table tbody td:empty, #bd-table tbody td:empty,
  #tg-table tbody td:empty, #user-table tbody td:empty, #imp-hier-table tbody td:empty { display: none; }
  #emp-table tbody td::before, #store-table tbody td::before, #bd-table tbody td::before,
  #tg-table tbody td::before, #user-table tbody td::before, #imp-hier-table tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: .3px; flex: 0 0 auto;
  }
  /* первая строка карточки — заголовок */
  #emp-table tbody td.main, #store-table tbody td.main, #bd-table tbody td.main,
  #tg-table tbody td.main, #user-table tbody td.main, #imp-hier-table tbody td.main {
    display: block; font-size: 15px; margin-bottom: 4px;
  }
  #emp-table tbody td.main::before, #store-table tbody td.main::before,
  #bd-table tbody td.main::before, #tg-table tbody td.main::before,
  #user-table tbody td.main::before, #imp-hier-table tbody td.main::before { content: none; }

  tr.group-row td { display: block !important; background: #eef2fb; padding: 8px 12px; }
  tr.group-row td::before { content: none !important; }

  #emp-table tbody td.actions, #store-table tbody td.actions, #tg-table tbody td.actions,
  #user-table tbody td.actions {
    justify-content: flex-end; gap: 8px; padding-top: 8px !important;
  }
  td.actions::before { content: none !important; }
  #emp-table tbody td.note-cell { min-width: 0; }
  #emp-table tbody td.note-cell .note-inner { flex: 1; justify-content: flex-end; }
  #emp-table tbody td.note-cell .note-text:empty { flex: 0; }
  .note-inner { width: 100%; }
  .note-text { text-align: left; }

  .child-row { grid-template-columns: 1fr auto; }
  .child-row input[data-child], .child-row select[data-child] { grid-column: 1 / -1; }
  .child-row .child-age { text-align: left; }
  .child-row .btn { width: auto; justify-self: end; padding: 6px 12px; }
  .tabs-inner { overflow-x: auto; flex-wrap: nowrap; }
  .tab-inner { white-space: nowrap; padding: 8px 10px; }
  #rep-table, #rep-table tbody, #rep-children, #rep-children tbody,
  #cf-table, #cf-table tbody { display: block; width: 100%; }
  #rep-table thead, #rep-children thead, #cf-table thead { display: none; }
  #rep-table tbody tr, #rep-children tbody tr, #cf-table tbody tr {
    display: block; padding: 10px 12px; border-bottom: 1px solid var(--line);
  }
  #rep-table tbody td, #rep-children tbody td, #cf-table tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    border: none; padding: 3px 0;
  }
  #rep-table tbody td::before, #rep-children tbody td::before, #cf-table tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase;
  }
  #rep-table tbody td.main, #rep-children tbody td.main, #cf-table tbody td.main {
    display: block; margin-bottom: 4px; font-weight: 600;
  }
  #rep-table tbody td.main::before, #rep-children tbody td.main::before,
  #cf-table tbody td.main::before { content: none; }
  #cf-table tbody td.actions { justify-content: flex-end; gap: 8px; }
  #rep-totals { grid-template-columns: 1fr 1fr; }

  .color-pop { right: 6px !important; left: auto; }
  #login-screen .card { width: 100%; max-width: 360px; }
  #toasts { right: 10px; left: 10px; bottom: 10px; }
  .toast { max-width: none; }
}
