/* EMS pages: navigation, dashboards, tables. Builds on the variables in app.css. */

/* ---------- Main navigation ---------- */
.mainnav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .4rem 1rem;
    padding: .35rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.mainnav-links { display: flex; flex-wrap: wrap; gap: .2rem; }
.mainnav-links a {
    padding: .45rem .8rem;
    border-radius: 8px;
    color: #334155;
    font-size: .92rem;
    font-weight: 600;
    text-decoration: none;
}
.mainnav-links a:hover { background: #eef3fa; }
.mainnav-links a.active { background: #e3eefc; color: var(--blue-800); }
.org-switch { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); }
.org-switch select,
.filters input,
.filters select {
    padding: .5rem .7rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font: inherit;
    color: var(--text);
    background: #fff;
}
.org-switch select:focus,
.filters input:focus,
.filters select:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(29, 120, 216, .18); }

@media (max-width: 560px) {
    .mainnav { padding: .35rem .75rem; }
    .org-switch label { display: none; }
}

/* ---------- Page structure ---------- */
.crumb { display: inline-block; margin-bottom: .75rem; font-size: .9rem; text-decoration: none; }
.crumb:hover { text-decoration: underline; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .5rem 1rem; }
.section-title { margin: 1.75rem 0 .75rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

.card {
    padding: 1.1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.card h2 { margin-bottom: .8rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; margin: 1.25rem 0; }
.stat {
    padding: .9rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
}
.stat.good { border-left-color: #2f9e6b; }
.stat.warn { border-left-color: #d98a00; }
.stat-title { font-size: .82rem; font-weight: 600; color: var(--muted); }
.stat-value { margin-top: .15rem; font-size: 1.8rem; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat-hint { margin-top: .1rem; font-size: .8rem; color: var(--muted); }

/* ---------- Bar lists ---------- */
.bars { display: flex; flex-direction: column; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 2.2rem; align-items: center; gap: .6rem; font-size: .88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: 99px; background: #eaf0f8; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--blue-500), var(--cyan-400)); }
.bar-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Structure ---------- */
.dept { margin-bottom: .9rem; padding: 0; }
.dept summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: .25rem 1rem;
    padding: .9rem 1.25rem;
    cursor: pointer;
    list-style: none;
}
.dept summary::-webkit-details-marker { display: none; }
.dept summary:focus-visible { outline: 3px solid rgba(56, 189, 248, .55); outline-offset: -3px; border-radius: var(--radius); }
.dept-name { font-size: 1.05rem; font-weight: 600; }
.team-rows { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.team-rows li {
    display: grid;
    grid-template-columns: minmax(150px, 1.2fr) minmax(150px, 1.4fr) 3rem;
    align-items: center;
    gap: .25rem 1rem;
    padding: .65rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: .92rem;
}
.team-rows li:last-child { border-bottom: 0; }
.team-main, .team-lead { display: flex; flex-direction: column; }
.team-count { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }

@media (max-width: 560px) {
    .team-rows li { grid-template-columns: 1fr 2.5rem; }
    .team-lead { grid-column: 1; grid-row: 2; }
    .team-count { grid-column: 2; grid-row: 1; }
}

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.table-wrap.is-busy { opacity: .55; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .6rem .85rem; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data th { font-size: .78rem; font-weight: 600; color: var(--muted); background: #f8fafd; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #f8fafd; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Filters and paging ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; margin: 1.25rem 0 1rem; }
.filters label { display: block; margin-bottom: .3rem; font-size: .78rem; font-weight: 600; color: #334155; }
.filters .grow { flex: 1 1 200px; }
.filters .grow input { width: 100%; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-top: 1rem; font-size: .9rem; }
.pager-buttons { display: flex; gap: .5rem; }

/* ---------- Badges ---------- */
.badge-active { color: #14633f; background: #dcf5e8; }
.badge-on_leave { color: #7a4b00; background: #ffeccc; }
.badge-terminated { color: #7d1f16; background: #fde4e1; }
.badge-joined, .badge-moved_in { color: #14633f; background: #dcf5e8; }
.badge-left, .badge-moved_out { color: #7a4b00; background: #ffeccc; }

/* ---------- Team changes, facts, timeline ---------- */
.changes { display: flex; flex-direction: column; gap: .6rem; margin: 0; padding: 0; list-style: none; font-size: .9rem; }
.changes li { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .6rem; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.fact dt { font-size: .78rem; font-weight: 600; color: var(--muted); }
.fact dd { margin: .15rem 0 0; font-weight: 600; }

.timeline { margin: 0; padding: 0 0 0 .25rem; list-style: none; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 1.1rem 1.2rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
    content: "";
    position: absolute;
    left: -.45rem;
    top: .3rem;
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid #94a3b8;
}
.timeline li.is-current::before { border-color: var(--blue-500); background: var(--blue-500); }
.timeline-dates { font-size: .82rem; color: var(--muted); }
.timeline-body { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .6rem; }

/* ---------- Loading and error states ---------- */
.state-box { display: flex; flex-direction: column; align-items: center; gap: .75rem; padding: 2.5rem 1rem; color: var(--muted); text-align: center; }
.state-box p { margin: 0; max-width: 46ch; }
.state-error { color: var(--danger); background: #fff5f4; border: 1px solid #f6cfcb; border-radius: var(--radius); }
.spinner { width: 26px; height: 26px; border: 3px solid #dbe5f3; border-top-color: var(--blue-500); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- Welcome tiles as links ---------- */
.tile-link { display: block; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.tile-link:hover { border-color: var(--blue-500); box-shadow: var(--shadow); }
.tile-link:focus-visible { outline: 3px solid rgba(56, 189, 248, .55); outline-offset: 2px; }
