:root {
  --bg: #f3f5f4; --card: #ffffff; --ink: #0f1f1b; --muted: #66756f; --line: #e2e8e5; --soft: #eef2f0;
  --brand: #0f6b57; --brand-2: #0a4d3f; --brand-soft: #e2f1ec; --brand-ink: #ffffff;
  --amber: #a86412; --amber-soft: #fcf1df; --red: #c03a28; --red-soft: #fdeceb;
  --blue: #2f5bd3; --blue-soft: #e8eeff; --violet: #6d3fc9; --violet-soft: #f0e9ff;
  --shadow: 0 1px 2px rgba(16, 32, 27, .06), 0 8px 24px rgba(16, 32, 27, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1412; --card: #151f1c; --ink: #e8efec; --muted: #93a39d; --line: #24312d; --soft: #1b2724;
    --brand: #2fa585; --brand-2: #25876c; --brand-soft: #173a31; --amber: #e3a54c; --amber-soft: #3a2c15;
    --red: #f07a68; --red-soft: #3d1d18; --blue: #7c9cf5; --blue-soft: #1c2747; --violet: #b394f2; --violet-soft: #2a2043;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1412; --card: #151f1c; --ink: #e8efec; --muted: #93a39d; --line: #24312d; --soft: #1b2724;
  --brand: #2fa585; --brand-2: #25876c; --brand-soft: #173a31; --amber: #e3a54c; --amber-soft: #3a2c15;
  --red: #f07a68; --red-soft: #3d1d18; --blue: #7c9cf5; --blue-soft: #1c2747; --violet: #b394f2; --violet-soft: #2a2043;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; line-height: 1.45;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
input, select, textarea, button { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid transparent; background: var(--brand); color: var(--brand-ink); font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-2); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--soft); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; transition: .15s; margin: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { left: 19px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--soft); color: var(--muted); }
.chip.green { background: var(--brand-soft); color: var(--brand); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.violet { background: var(--violet-soft); color: var(--violet); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px; }

/* ---------- экран сотрудника ---------- */
.emp { max-width: 460px; margin: 0 auto; padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.emp-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .02em; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.hero { padding: 22px 18px 20px; text-align: center; background: linear-gradient(165deg, #0f3d34 0%, #0f6b57 70%, #13806a 100%); color: #fff; border: 0; }
.hero .hello { font-size: 15px; opacity: .85; }
.hero .clock { font-size: 52px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 2px; font-variant-numeric: tabular-nums; }
.hero .date { font-size: 13px; opacity: .75; }
.hero .state { margin: 14px auto 0; display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 99px; background: rgba(255,255,255,.14); font-size: 13px; font-weight: 600; }
.punch {
  margin: 20px auto 6px; width: 190px; height: 190px; border-radius: 50%; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: #fff; color: #0f6b57; box-shadow: 0 0 0 10px rgba(255,255,255,.12), 0 16px 40px rgba(0,0,0,.25);
  font-size: 17px; font-weight: 800; transition: transform .1s;
}
.punch:active { transform: scale(.97); }
.punch .ico { font-size: 40px; line-height: 1; }
.punch small { font-size: 12px; font-weight: 600; opacity: .7; max-width: 150px; }
.punch.out { color: #a8461f; }
.punch.done { color: #66756f; }
.punch[disabled] { opacity: .7; }
.geo { margin-top: 12px; font-size: 12.5px; opacity: .8; min-height: 18px; }
.stat-rows { display: flex; flex-direction: column; }
.stat-rows .r { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.stat-rows .r:last-child { border-bottom: 0; }
.timeline { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.hist .r { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.hist .r:last-child { border-bottom: 0; }
.hist .d b { display: block; }
.hist .d span { font-size: 12px; color: var(--muted); }
.result { position: fixed; inset: 0; background: rgba(8, 20, 17, .55); display: grid; place-items: center; z-index: 1050; padding: 20px; animation: fade .15s; }
.result .box { background: var(--card); border-radius: 22px; padding: 28px 22px; width: 100%; max-width: 360px; text-align: center; box-shadow: var(--shadow); }
.result .big { width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 14px; display: grid; place-items: center; font-size: 42px; }
.result .big.ok { background: var(--brand-soft); color: var(--brand); }
.result .big.bad { background: var(--red-soft); color: var(--red); }
.result h2 { font-size: 20px; }
.result p { color: var(--muted); margin: 10px 0 18px; }
@keyframes fade { from { opacity: 0; } }
.center-screen { min-height: 80vh; display: grid; place-items: center; text-align: center; padding: 24px; }
.center-screen .card { max-width: 420px; padding: 28px 22px; }
.center-screen h2 { margin: 12px 0 8px; }

/* ---------- панель руководителя ---------- */
.adm { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .brand { padding: 4px 8px 16px; }
.side .brand small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 11px; color: var(--ink); font-weight: 500; }
.nav a:hover { background: var(--soft); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; font-weight: 800; }
.topbar .acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi.green .v { color: var(--brand); } .kpi.amber .v { color: var(--amber); } .kpi.red .v { color: var(--red); } .kpi.blue .v { color: var(--blue); }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--soft); }
.who b { display: block; } .who span { font-size: 12px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); font-weight: 500; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.notice.blue { background: var(--blue-soft); color: var(--blue); }
.notice.green { background: var(--brand-soft); color: var(--brand); }

/* табель */
.ts { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.ts th, .ts td { padding: 0; text-align: center; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
.ts th { font-size: 11px; color: var(--muted); padding: 8px 0; font-weight: 600; background: var(--card); position: sticky; top: 0; }
.ts th.we { color: var(--red); }
.ts td.nm, .ts th.nm { position: sticky; left: 0; background: var(--card); text-align: left; padding: 8px 12px; min-width: 170px; z-index: 1; border-right: 1px solid var(--line); }
.ts td.c { width: 38px; min-width: 38px; height: 38px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ts td.ok { background: var(--brand-soft); color: var(--brand); }
.ts td.late { background: var(--amber-soft); color: var(--amber); }
.ts td.abs { background: var(--red-soft); color: var(--red); }
.ts td.lv { background: var(--blue-soft); color: var(--blue); }
.ts td.off { background: var(--soft); color: var(--muted); }
.ts td.open { background: var(--violet-soft); color: var(--violet); }
.ts td.tot { padding: 6px 10px; font-weight: 700; white-space: nowrap; background: var(--card); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; }

/* сотрудники */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.ecard { padding: 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: border-color .15s; }
.ecard:hover { border-color: var(--brand); }
.ecard .hd { display: flex; gap: 12px; align-items: center; }
.ava { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 17px; flex: none; }
.ecard .meta { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.ecard.off { opacity: .55; }

/* модальные окна */
.modal { position: fixed; inset: 0; background: rgba(8, 20, 17, .5); z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; animation: fade .12s; }
.modal .box { background: var(--card); border-radius: 20px; width: 100%; max-width: 620px; box-shadow: var(--shadow); }
.modal .hd { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal .hd h3 { font-size: 17px; }
.modal .bd { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal .ft { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.sched { display: flex; flex-direction: column; gap: 6px; }
.sched .r { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 10px; align-items: center; }
.sched .r.off .input { opacity: .35; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.checks input { accent-color: var(--brand); }
.invite { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; padding: 14px; border-radius: 14px; background: var(--soft); }
.invite .qr { background: #fff; border-radius: 10px; padding: 6px; }
.invite .qr svg { width: 100%; height: auto; display: block; }
.invite .acts { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 560px) { .invite { grid-template-columns: 1fr; } .invite .qr { max-width: 200px; margin: auto; } }
.sec-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.split { display: grid; grid-template-columns: 340px 1fr; gap: 16px; }
#map { height: 520px; border-radius: var(--radius); border: 1px solid var(--line); }
/* слои Leaflet (z-index 400+) не должны вылезать поверх окон */
#map, #pmap { position: relative; z-index: 0; isolation: isolate; }
.geo-search { position: relative; }
.geo-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 5; max-height: 260px; overflow-y: auto; }
.geo-results div { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 13px; }
.geo-results div:last-child { border-bottom: 0; }
.geo-results div:hover { background: var(--soft); }
.plist .p { padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.plist .p:hover { background: var(--soft); }
.plist .p:last-child { border-bottom: 0; }
.mark-row td .thumb { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; cursor: zoom-in; display: block; }
.settings { display: flex; flex-direction: column; gap: 16px; max-width: 860px; }
.settings .card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.settings h3 { font-size: 16px; }
.hint { font-size: 12.5px; color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: #10201b; color: #fff; padding: 11px 16px; border-radius: 12px; font-weight: 500; box-shadow: var(--shadow); max-width: 90vw; animation: fade .15s; }
#toast div.err { background: var(--red); }
.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: sp .8s linear infinite; margin: 40px auto; }
@keyframes sp { to { transform: rotate(360deg); } }
.print-only { display: none; }

@media (max-width: 960px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .split { grid-template-columns: 1fr; }
  #map { height: 360px; }
}
@media (max-width: 760px) {
  .adm { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); z-index: 20; overflow-x: auto; gap: 2px; }
  .side .brand, .side .foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 8px 10px; font-size: 13px; white-space: nowrap; }
  .nav a span { display: none; }
  .nav a.on span { display: inline; }
  .main { padding: 16px 16px 50px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .tbl th, .tbl td { padding: 10px; }
  .hide-sm { display: none; }
}
@media print {
  .side, .topbar .acts, #toast { display: none !important; }
  .adm { display: block; } .main { padding: 0; }
  .print-only { display: block; }
  .card { box-shadow: none; }
}
