/* =======================================================================
   ЦАЛИН, KPI СИСТЕМ — нийтлэг загвар (бүх хуудас)
   ======================================================================= */

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

body {
    font-family: Arial, sans-serif;
    background: #f4f7fb;
    color: #172033;
    line-height: 1.4;
}

a { color: #2563eb; }
button, input, select { font-family: inherit; }
[hidden] { display: none !important; }


/* ===================== SIDEBAR ===================== */

.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 240px; height: 100vh;
    background: #10192d;
    color: #fff;
    padding: 25px 15px;
    overflow-y: auto;
    z-index: 50;
    transition: transform .2s ease;
}

.logo { text-align: center; padding-bottom: 18px; }

.company-logo {
    width: 190px; max-width: 100%; height: auto;
    display: block; margin: 0 auto 12px;
}

.logo-icon {
    width: 55px; height: 55px;
    background: #2563eb; border-radius: 14px;
    margin: 0 auto 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: bold;
}

.logo p { color: #9aa6bd; font-size: 12px; }

.menu-title {
    color: #71809b; font-size: 11px; letter-spacing: .5px;
    margin: 20px 10px 8px;
}

.menu {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%;
    color: #d5dbea; text-decoration: none;
    padding: 12px 14px; margin: 4px 0;
    border: none; border-radius: 9px; background: none;
    font-size: 14px; text-align: left;
    cursor: pointer; user-select: none;
}
.menu:hover { background: #1b2945; }
.menu.active { background: #2563eb; color: #fff; }

.menu.disabled { cursor: default; opacity: .55; }
.menu.disabled:hover { background: none; }
.menu small {
    font-size: 10px; background: #24334f; color: #aeb9cd;
    padding: 2px 6px; border-radius: 6px;
}

.caret { font-size: 10px; opacity: .8; transition: transform .18s ease; }
.menu-parent.open .caret { transform: rotate(180deg); }

.submenu {
    display: none;
    margin: 2px 0 6px 6px; padding-left: 10px;
    border-left: 2px solid #24334f;
}
.menu-parent.open .submenu { display: block; }

.submenu-item {
    display: block;
    color: #aeb9cd; text-decoration: none;
    font-size: 13px; line-height: 1.35;
    padding: 8px 12px; margin: 2px 0;
    border-radius: 8px;
}
.submenu-item:hover { background: #1b2945; color: #fff; }
.submenu-item.active { background: #2563eb; color: #fff; font-weight: bold; }

.nav-toggle {
    display: none;
    align-items: center; justify-content: center;
    width: 42px; height: 42px; flex: 0 0 42px;
    border: 1px solid #dce2eb; border-radius: 10px;
    background: #fff; font-size: 20px; cursor: pointer;
}
.sidebar-backdrop { display: none; }


/* ===================== MAIN / TOPBAR ===================== */

.main { margin-left: 240px; padding: 30px; min-width: 0; }

.topbar {
    display: flex; align-items: center; gap: 14px;
    margin-bottom: 25px;
}
.topbar h1 { font-size: 27px; }
.topbar p { color: #7b879b; margin-top: 6px; }

.user {
    margin-left: auto;
    background: #fff; padding: 12px 18px; border-radius: 10px;
    box-shadow: 0 3px 15px rgba(0,0,0,.05);
    white-space: nowrap;
}


/* ===================== CARDS ===================== */

.cards {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 18px; margin-bottom: 22px;
}

.card {
    background: #fff; padding: 22px; border-radius: 14px;
    display: flex; align-items: center; gap: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,.04);
    min-width: 0;
}

.card-icon {
    width: 52px; height: 52px; flex: 0 0 52px;
    background: #eef4ff; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 23px;
}

.card p { color: #7d889c; font-size: 13px; }
.card h2 { margin-top: 5px; font-size: 22px; white-space: nowrap; }
.card small { display: block; margin-top: 4px; color: #98a2b3; font-size: 12px; }
.card .tier { color: #667085; font-weight: bold; }


/* ===================== PANELS ===================== */

.content-grid {
    display: grid; grid-template-columns: 2fr 1fr;
    gap: 20px; margin-bottom: 22px;
}

.panel {
    background: #fff; border-radius: 14px; padding: 22px;
    box-shadow: 0 4px 20px rgba(0,0,0,.04);
    margin-bottom: 22px;
    min-width: 0;
}
.content-grid .panel { margin-bottom: 0; }

.panel-header {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; flex-wrap: wrap;
    margin-bottom: 20px;
}
.panel-header h2 { font-size: 18px; }
.panel-header p { color: #8993a5; font-size: 13px; margin-top: 5px; }

.table-panel { overflow-x: auto; }

.notice {
    background: #eef4ff; border: 1px solid #cfdcfb; color: #1e3a8a;
    padding: 13px 16px; border-radius: 10px; font-size: 14px;
    margin-bottom: 22px;
}


/* ===================== CHART ===================== */

.chart {
    height: 260px;
    display: flex; align-items: flex-end; justify-content: space-around;
    border-bottom: 1px solid #e7ebf1;
    padding: 28px 10px 0;
    margin-bottom: 30px;
}

.bar {
    width: 45px;
    background: #2563eb;
    border-radius: 7px 7px 0 0;
    position: relative;
    display: flex; justify-content: center;
}
.bar.empty { background: transparent; }

.bar span {
    position: absolute; top: -22px;
    font-size: 12px; font-weight: bold; white-space: nowrap;
}
.bar.empty span { color: #98a2b3; font-weight: normal; }

.bar small {
    position: absolute; bottom: -25px;
    color: #8a94a6; font-size: 12px; white-space: nowrap;
}


/* ===================== PROGRESS ===================== */

.progress-item { margin-bottom: 23px; }

.progress-item > div:first-child {
    display: flex; justify-content: space-between;
    margin-bottom: 8px; font-size: 13px;
}
.progress-item b { color: #667085; }

.progress { width: 100%; height: 8px; background: #edf0f5; border-radius: 10px; }
.progress div { height: 100%; background: #2563eb; border-radius: 10px; }
.progress .good   { background: #16a34a; }
.progress .medium { background: #eab308; }
.progress .bad    { background: #dc2626; }
.progress .wait   { background: #98a2b3; }


/* ===================== TABLE ===================== */

table { width: 100%; border-collapse: collapse; }

th {
    text-align: left; color: #7c8799; font-size: 12px;
    padding: 13px; border-bottom: 1px solid #e5e9f0; white-space: nowrap;
}

td {
    padding: 14px 13px;
    border-bottom: 1px solid #edf0f4;
    font-size: 13px; vertical-align: middle;
}

td .sub { display: block; color: #98a2b3; font-size: 11px; margin-top: 3px; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { white-space: nowrap; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafd; }
tr.current td { background: #f4f8ff; }

.empty-row td { text-align: center; padding: 40px; color: #8993a5; }

.dept-group-row td {
    background: #f4f7fb; font-weight: bold; color: #172033;
    padding: 12px 13px;
}
.dept-group-row .gsum { float: right; color: #2563eb; }


/* ===================== BUTTONS ===================== */

.primary-btn, .calculate-btn, .save-btn, .excel-btn, .ghost-btn, .cancel-btn {
    border: none; border-radius: 8px;
    font-weight: bold; font-size: 13px;
    cursor: pointer; text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 11px 16px;
}

.primary-btn, .calculate-btn, .excel-btn { background: #2563eb; color: #fff; }
.primary-btn:hover, .calculate-btn:hover, .excel-btn:hover { background: #1d4ed8; }

.save-btn { background: #16a34a; color: #fff; padding: 13px 22px; }
.save-btn:hover { background: #15803d; }
.save-btn:disabled { background: #a7c9b4; cursor: not-allowed; }

.ghost-btn, .cancel-btn {
    border: 1px solid #dce2eb; background: #fff; color: #667085;
}
.ghost-btn:hover, .cancel-btn:hover { background: #f4f6f8; }

.edit-btn, .delete-btn {
    border: none; width: 35px; height: 35px; border-radius: 7px; cursor: pointer;
}
.edit-btn { background: #eef4ff; color: #2563eb; margin-right: 6px; }
.edit-btn:hover { background: #dbe7ff; }
.delete-btn { background: #feecec; color: #dc2626; }
.delete-btn:hover { background: #fecaca; }

.link-btn {
    border: none; background: none; color: #2563eb;
    font-size: 13px; font-weight: bold; cursor: pointer; padding: 4px 6px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: #dc2626; }

.calculate-area { display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }


/* ===================== BADGES ===================== */

.kpi {
    display: inline-block; padding: 5px 9px; border-radius: 6px;
    font-weight: bold; font-size: 12px; white-space: nowrap;
}
.kpi.good   { background: #e7f8ef; color: #15945b; }
.kpi.medium { background: #fff4d8; color: #b77900; }
.kpi.bad    { background: #feecec; color: #dc2626; }
.kpi.wait   { background: #eef1f6; color: #7c8799; }

.status {
    display: inline-block; padding: 5px 9px; border-radius: 6px;
    font-size: 12px; white-space: nowrap;
}
.active-status { background: #e7f8ef; color: #15945b; }
.leave-status  { background: #fff4d8; color: #b77900; }
.left-status   { background: #f1f3f7; color: #7c8799; }


/* ===================== FORMS ===================== */

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.form-grid.five { grid-template-columns: repeat(5, 1fr); }

.form-group { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.form-group label { font-size: 13px; color: #667085; font-weight: bold; }

.form-group input,
.form-group select,
table input,
.search-input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #dce2eb; border-radius: 8px;
    outline: none; font-size: 13px; background: #fff;
}

.form-group input:focus,
.form-group select:focus,
table input:focus,
.search-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-group input[readonly] { background: #f5f7fa; color: #4b5565; }

table input { min-width: 90px; }
table input.kpi-name { min-width: 180px; }

select {
    padding: 8px 12px; border: 1px solid #dce2eb; border-radius: 7px; background: #fff;
}

.panel.editing { box-shadow: 0 0 0 2px #2563eb, 0 4px 20px rgba(0,0,0,.04); }


/* ===================== EXCEL ===================== */

.excel-import {
    padding: 18px 20px;
    background: #f7f9fc;
    border: 1px dashed #cbd5e1; border-radius: 10px;
}
.excel-import h3 { font-size: 16px; margin-bottom: 6px; }
.excel-import p { color: #667085; font-size: 13px; margin-bottom: 14px; }
.excel-import .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.excel-import .hint { margin: 12px 0 0; font-size: 12px; color: #8993a5; }


/* ===================== EMPLOYEES PAGE ===================== */

.stat-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 14px; margin-bottom: 22px;
}
.stat-box {
    background: #fff; border-radius: 12px; padding: 16px 18px;
    box-shadow: 0 4px 20px rgba(0,0,0,.04);
}
.stat-box b { display: block; color: #7d889c; font-size: 12px; font-weight: normal; }
.stat-box span { display: block; font-size: 22px; font-weight: bold; margin-top: 6px; white-space: nowrap; }

.dept-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px;
}
.excel-import .warn { margin-top: 14px; line-height: 1.5; }
.excel-import .warn small { color: #8a6100; }
.dept-card {
    background: #fff; border: 1px solid #e5e9f0; border-radius: 12px;
    padding: 14px; cursor: pointer; transition: .15s; text-align: left;
    font: inherit; color: inherit;
}
.dept-card:hover { border-color: #2563eb; box-shadow: 0 4px 16px rgba(37,99,235,.10); }
.dept-card.active { border-color: #2563eb; background: #f4f8ff; }
.dept-card h4 { font-size: 13px; margin-bottom: 8px; min-height: 34px; line-height: 1.3; }
.dept-card .num { font-size: 22px; font-weight: bold; color: #2563eb; }
.dept-card .sum { font-size: 12px; color: #7d889c; margin-top: 4px; }

.toolbar {
    display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
    margin-bottom: 16px;
}
.toolbar .search-input { flex: 1 1 280px; padding: 12px 16px; font-size: 14px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button {
    padding: 9px 14px; border: 1px solid #dce2eb; background: #fff;
    border-radius: 20px; cursor: pointer; font-size: 13px; color: #4b5565;
}
.chips button:hover { border-color: #2563eb; color: #2563eb; }
.chips button.active { background: #2563eb; border-color: #2563eb; color: #fff; }


/* ===================== KPI PAGE ===================== */

.warn, .dept-note, .record-status {
    margin-top: 16px; padding: 11px 14px; border-radius: 9px; font-size: 13px;
}
.warn { background: #fff8e6; border: 1px solid #f5d98a; color: #8a6100; }
.dept-note { background: #f4f7fb; border-left: 3px solid #2563eb; color: #4b5565; }
.dept-note b { color: #172033; }
.record-status { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.record-status.new { background: #f8fafc; border-color: #e2e8f0; color: #475569; }

.combo { position: relative; }

.combo-input {
    width: 100%;
    padding: 11px 34px 11px 12px;
    border: 1px solid #dce2eb; border-radius: 8px;
    outline: none; font-size: 13px; background: #fff;
}
.combo-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.combo-input:disabled { background: #f5f7fa; }

.combo-clear {
    position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
    border: none; background: transparent; color: #98a2b3;
    font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 4px;
    display: none;
}
.combo-clear.on { display: block; }
.combo-clear:hover { color: #dc2626; }

.combo-list {
    position: absolute; z-index: 40;
    left: 0; right: 0; top: calc(100% + 5px);
    min-width: 260px;
    background: #fff;
    border: 1px solid #dce2eb; border-radius: 10px;
    box-shadow: 0 12px 32px rgba(16,25,45,.14);
    max-height: 290px; overflow-y: auto;
    display: none;
}
.combo-list.on { display: block; }

.combo-item {
    padding: 10px 12px; cursor: pointer; font-size: 13px;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.combo-item:hover, .combo-item.hl { background: #f4f7fb; }
.combo-item.active { background: #eef4ff; color: #2563eb; font-weight: bold; }
.combo-item .meta { color: #98a2b3; font-size: 11px; font-weight: normal; text-align: right; }
.combo-empty { padding: 15px; text-align: center; color: #98a2b3; font-size: 13px; }


/* ===================== RESPONSIVE ===================== */

@media (max-width: 1300px) {
    .form-grid.five { grid-template-columns: repeat(3, 1fr); }
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1000px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
    .content-grid { grid-template-columns: 1fr; }
    .form-grid, .form-grid.five { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
    .sidebar { transform: translateX(-100%); width: 260px; }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0;
        background: rgba(16,25,45,.45); z-index: 40;
    }
    .nav-toggle { display: inline-flex; }

    .main { margin-left: 0; padding: 16px; }
    .topbar h1 { font-size: 21px; }
    .topbar p { font-size: 13px; }
    .user { display: none; }

    .cards, .form-grid, .form-grid.five { grid-template-columns: 1fr; }
    .stat-grid, .dept-cards { grid-template-columns: repeat(2, 1fr); }
    .bar { width: 30px; }
}


/* ===================== МЭДЭГДЭЛ / ЦОНХ ===================== */

:root { color-scheme: light; }

.toast-stack {
    position: fixed; z-index: 100;
    right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex; flex-direction: column; gap: 10px;
    max-width: min(420px, calc(100vw - 32px));
}
.toast {
    padding: 13px 16px; border-radius: 10px;
    font-size: 13px; line-height: 1.5; white-space: pre-line;
    box-shadow: 0 10px 30px rgba(16,25,45,.18);
    cursor: pointer;
    animation: toastIn .18s ease-out;
}
.toast.ok   { background: #10192d; color: #fff; }
.toast.warn { background: #fff8e6; color: #8a6100; border: 1px solid #f5d98a; }
@keyframes toastIn { from { transform: translateY(8px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.modal-back {
    position: fixed; inset: 0; z-index: 110;
    background: rgba(16,25,45,.45);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal {
    background: #fff; color: #172033;
    border-radius: 14px; padding: 22px;
    width: min(440px, 100%);
    box-shadow: 0 20px 50px rgba(16,25,45,.25);
}
.modal p { font-size: 14px; line-height: 1.55; white-space: pre-line; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

button:focus-visible, a:focus-visible, .dept-card:focus-visible {
    outline: 2px solid #2563eb; outline-offset: 2px;
}

.check-row {
    display: flex; gap: 10px; align-items: flex-start;
    margin-top: 14px; font-size: 13px; color: #4b5565; line-height: 1.5;
    cursor: pointer;
}
.check-row input { margin-top: 3px; width: 16px; height: 16px; flex: 0 0 16px; }
.dept-card .nosal { color: #b77900; }

.submenu-item.sub2 { padding-left: 22px; font-size: 12.5px; }


/* ===================== ҮҮЛЭН САН / НЭВТРЭЛТ ===================== */

.boot-overlay {
    position: fixed; inset: 0; z-index: 120;
    background: #f4f7fb;
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.boot-box {
    background: #fff; border-radius: 14px; padding: 28px 30px;
    box-shadow: 0 10px 40px rgba(16,25,45,.10);
    text-align: center; max-width: 420px; width: 100%;
    display: flex; flex-direction: column; gap: 14px; align-items: center;
}
.boot-box h2 { font-size: 18px; }
.boot-box p { color: #667085; font-size: 14px; line-height: 1.5; }
.spinner {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid #dbe7ff; border-top-color: #2563eb;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }

.user.user-badge {
    display: flex; align-items: center; gap: 14px; padding: 10px 14px; white-space: normal;
}
.user-badge b { display: block; font-size: 14px; }
.user-badge small { display: block; color: #8993a5; font-size: 12px; margin-top: 2px; }
.sync-state { font-size: 12px; white-space: nowrap; }
.sync-state.ok { color: #15945b; }
.sync-state.busy { color: #b77900; }

.remote-banner {
    position: fixed; z-index: 105; left: 50%; transform: translateX(-50%);
    top: calc(14px + env(safe-area-inset-top, 0px));
    background: #10192d; color: #fff;
    display: flex; gap: 12px; align-items: center;
    padding: 10px 12px 10px 16px; border-radius: 12px;
    box-shadow: 0 10px 30px rgba(16,25,45,.25); font-size: 13px;
    max-width: calc(100vw - 32px); flex-wrap: wrap;
}
.remote-banner .link-btn { color: #aeb9cd; }

body.read-only [data-edit] input:disabled,
body.read-only input[data-edit]:disabled,
body.read-only select[data-edit]:disabled { background: #f5f7fa; }
body.read-only button[data-edit]:disabled,
body.read-only [data-edit] button:disabled { opacity: .45; cursor: not-allowed; }
