:root {
    --bar: #6e8eab;
    --bar-dark: #5d7d9a;
    --ink: #243140;
    --muted: #7b8794;
    --line: #e6ebf0;
    --bg: #f4f6f8;
    --card: #ffffff;
    --green: #2eae4e;
    --red: #e14b4b;
    --amber: #f0a202;
    --navy: #1b4f72;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
}

button, input, select, textarea {
    font: inherit;
}

button { cursor: pointer; }

.hidden { display: none !important; }

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #6e8eab 0%, #f4f6f8 42%);
}

.login-card {
    width: min(420px, calc(100% - 32px));
    background: #fff;
    border-radius: 12px;
    padding: 28px 28px 22px;
    box-shadow: 0 12px 40px rgba(27, 79, 114, 0.16);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 26px;
    color: var(--navy);
}

.login-card p { color: var(--muted); margin: 0 0 18px; }

.login-card label {
    display: block;
    margin: 12px 0 6px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.login-card input, .field input, .field select, .field textarea, .toolbar input, .toolbar select {
    width: 100%;
    border: 1px solid #d5dde5;
    border-radius: 6px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
}

.login-card button, .primary, .toolbar button, .modal-card .actions button, .inline-actions button {
    border: 0;
    border-radius: 6px;
    padding: 10px 14px;
    background: var(--navy);
    color: #fff;
}

.secondary, .ghost {
    background: #eef3f7 !important;
    color: var(--navy) !important;
}

.danger { background: #9b2c2c !important; }

.hint { color: var(--muted); font-size: 13px; }
.place { color: var(--ink); font-weight: 600; }
.error-text { color: var(--red); min-height: 1.2em; }

.topbar {
    height: 48px;
    background: var(--bar);
    display: flex;
    align-items: stretch;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    width: 48px;
    display: grid;
    place-items: center;
    font-weight: 700;
    background: var(--bar-dark);
}

.tabs { display: flex; align-items: stretch; }

.tab, .menu-btn {
    border: 0;
    background: transparent;
    color: #fff;
    padding: 0 16px;
    border-radius: 0;
}

.tab.active {
    background: #fff;
    color: #3d6d90;
}

.menu { position: relative; display: flex; }

.dropdown {
    display: none;
    position: absolute;
    top: 48px;
    left: 0;
    min-width: 240px;
    background: #fff;
    color: var(--ink);
    border: 1px solid #e5eaf0;
    box-shadow: 0 10px 24px rgba(20, 40, 60, 0.12);
    padding: 6px 0;
    z-index: 30;
}

.dropdown.open { display: block; }

.dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--ink);
    border: 0;
    border-radius: 0;
    padding: 10px 16px;
}

.dropdown button:hover { background: #f3f7fb; }

.top-spacer { flex: 1; }
.org { align-self: center; margin-right: 12px; opacity: 0.9; }

.logout {
    border: 0;
    background: transparent;
    color: #fff;
    padding: 0 16px;
}

main { padding: 18px 22px 40px; }

.page-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.page-head h1 { font-size: 22px; margin: 0; font-weight: 600; }
.page-head .spacer { flex: 1; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.toolbar .search { min-width: 240px; }
.count { color: var(--muted); }

.table-wrap {
    background: var(--card);
    border: 1px solid var(--line);
    overflow: auto;
}

table { width: 100%; border-collapse: collapse; }

th {
    text-align: left;
    font-weight: 600;
    color: #8b98a5;
    font-size: 13px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

td {
    padding: 12px 10px;
    border-bottom: 1px solid #f0f3f6;
    vertical-align: middle;
}

tr:last-child td { border-bottom: 0; }

.dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
    background: var(--red);
}

.dot.online { background: var(--green); }
.dot.away { background: var(--amber); }
.dot.offline, .dot.left { background: var(--red); }

.icon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #d7e0e8;
    background: #fff;
    color: #607080;
    border-radius: 4px;
    margin-right: 4px;
    padding: 0;
}

.icon-btn:hover { background: #f5f8fb; }

.link { color: #2b6f9b; background: none; border: 0; padding: 0; }

.cards { display: grid; gap: 12px; }

.card {
    background: #fff;
    border: 1px solid var(--line);
    padding: 16px 18px;
}

.card h2 { margin: 0 0 6px; font-size: 18px; }
.card p { margin: 0; color: #526170; line-height: 1.45; }

.card-actions { margin-top: 12px; display: flex; gap: 8px; }

.banner {
    background: #fff7e8;
    border: 1px solid #f0d7a2;
    color: #6a4b12;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); }

.modal-back {
    position: fixed;
    inset: 0;
    background: rgba(20, 32, 44, 0.45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 16px;
    z-index: 40;
    overflow: auto;
}

.modal-card {
    width: min(640px, 100%);
    background: #fff;
    border-radius: 10px;
    padding: 20px;
}

.modal-card h2 { margin: 0 0 14px; }
.modal-card .actions { display: flex; justify-content: flex-end; gap: 8px; }

.qr-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.qr-card {
    background: #fff;
    border: 1px solid var(--line);
    padding: 16px;
}

.qr-card img { width: 220px; height: 220px; display: block; }
.token {
    font-size: 28px;
    letter-spacing: 0.12em;
    font-weight: 700;
    color: var(--navy);
}

.mono {
    font-family: Consolas, "Courier New", monospace;
    white-space: pre-wrap;
    word-break: break-all;
    background: #f6f8fa;
    padding: 10px;
    border-radius: 6px;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: var(--navy);
    color: #fff;
    padding: 12px 14px;
    border-radius: 8px;
    z-index: 50;
    max-width: 360px;
}

.toast.error { background: #9b2c2c; }

.empty {
    padding: 28px 10px;
    color: var(--muted);
}

.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }

.map-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 12px;
    height: calc(100vh - 86px);
    min-height: 520px;
}

.map-side {
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    padding: 12px;
}

.map-side h2 {
    margin: 14px 0 8px;
    font-size: 15px;
}

.map-side .field { margin-bottom: 8px; }

#deviceMap {
    height: 100%;
    min-height: 420px;
    border: 1px solid var(--line);
    background: #d5e0ea;
}

.map-pin.leaflet-div-icon {
    background: transparent;
    border: 0;
}

.map-pin span {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(20, 40, 60, 0.35);
}

.legend { display: flex; gap: 12px; margin: 8px 0 12px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }

.place-tree button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--ink);
    border: 0;
    border-radius: 4px;
    padding: 5px 6px;
}

.place-tree button:hover, .place-tree button.active { background: #f3f7fb; }
.place-tree .country { font-weight: 700; }
.place-tree .city { padding-left: 14px; font-weight: 600; }
.place-tree .school { padding-left: 26px; }
.place-tree .tablet { padding-left: 38px; color: #526170; }

@media (max-width: 860px) {
    .map-layout { grid-template-columns: 1fr; height: auto; }
    #deviceMap { height: 460px; }
}

@media print {
    .topbar, .no-print, .toast { display: none !important; }
    body { background: #fff; }
    .qr-card { break-inside: avoid; }
}
