/* Kudex web UI — implements the mockups from the project charter:
   dark navy sidebar app shell, white admin/HR pages, blue primary accent. */

:root {
    --navy: #16233c;
    --navy-light: #22334f;
    --navy-border: #2e405f;
    --blue: #2f80ed;
    --blue-dark: #1f6dd6;
    --indigo: #4b53bc;   /* Teams button */
    --purple: #4a154b;   /* Slack button */
    --bg: #f3f5f9;
    --card: #ffffff;
    --line: #e4e8ef;
    --text: #1c2333;
    --muted: #67718a;
    --green: #1e9e5a;
    --red: #d64545;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(22, 35, 60, .06), 0 1px 3px rgba(22, 35, 60, .04);
}

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

body {
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

h1, h2, h3 { line-height: 1.25; }
a { color: var(--blue); }
kbd { background: #e9edf4; border-radius: 4px; padding: 0 .35rem; font-size: .85em; }
code { font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; font-size: .9em; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    border: 1px solid transparent; border-radius: 8px;
    padding: .55rem 1.1rem; font-size: .92rem; font-weight: 600;
    cursor: pointer; text-decoration: none; color: var(--text); background: none;
}
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-ghost { background: #fff; border-color: var(--line); }
.btn-ghost:hover { background: #f6f8fb; }
.btn-block { width: 100%; }
.btn-danger-outline { border-color: #f0caca; color: var(--red); background: #fff; padding: .3rem .7rem; font-size: .82rem; }
.btn-danger-outline:hover { background: #fdf3f3; }
.btn-toggle { border-color: var(--line); background: #fff; color: var(--muted); padding: .3rem .8rem; font-size: .82rem; }
.btn-toggle.on { border-color: #bfe3cf; color: var(--green); background: #f0faf4; }
.btn-toggle:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards & layout primitives ---------- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.25rem 1.4rem; margin-bottom: 1.1rem;
}
.card-title { font-size: 1.02rem; font-weight: 700; margin-bottom: .35rem; }
.card-subtitle { font-size: .95rem; margin: 1.2rem 0 .5rem; }
.card-sub { color: var(--muted); font-size: .88rem; margin-bottom: .9rem; }
.card-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; gap: 1rem; }
.page-title { font-size: 1.45rem; margin-bottom: .15rem; }
.empty { color: var(--muted); font-size: .9rem; padding: .4rem 0; }

.flash { border-radius: 8px; padding: .65rem 1rem; margin-bottom: 1rem; font-size: .9rem; }
.flash-success { background: #eafaf1; border: 1px solid #bfe3cf; color: #14663c; }
.flash-error { background: #fdf1f1; border: 1px solid #f0caca; color: #9c2f2f; }

/* ---------- Logo ---------- */
.logo-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 8px;
    background: var(--blue); color: #fff; font-weight: 800; font-size: 1.15rem;
}
.logo-mark-lg { width: 52px; height: 52px; border-radius: 12px; font-size: 1.7rem; }
.logo-word { font-weight: 800; letter-spacing: .12em; color: #fff; }
.logo-word-dark { font-weight: 800; letter-spacing: .12em; color: var(--text); }

/* ---------- App shell (sidebar layout) ---------- */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px; flex-shrink: 0;
    background: var(--navy); color: #cfd8e8;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-logo { display: flex; align-items: center; gap: .6rem; padding: 1.25rem 1.2rem; }
.sidebar-balance {
    margin: .35rem 1rem 1.1rem; padding: .8rem 1rem;
    background: var(--navy-light); border: 1px solid var(--navy-border); border-radius: 10px;
    display: flex; flex-direction: column;
}
.balance-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #8fa0bd; }
.balance-value { font-size: 1.7rem; font-weight: 800; color: #fff; }
.balance-value small { font-size: .95rem; font-weight: 600; color: #8fa0bd; }

.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; padding: 0 .7rem; }
.sidebar-nav a {
    display: flex; align-items: center; gap: .65rem;
    padding: .6rem .8rem; border-radius: 8px;
    color: #cfd8e8; text-decoration: none; font-size: .93rem; font-weight: 500;
}
.sidebar-nav a:hover { background: var(--navy-light); color: #fff; }
.sidebar-nav a.active { background: var(--blue); color: #fff; }
.nav-icon { width: 1.1rem; text-align: center; }

.sidebar-user { margin-top: auto; padding: 1rem 1.2rem; border-top: 1px solid var(--navy-border); }
.user-card { display: flex; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.user-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--blue); color: #fff; font-weight: 700; text-transform: uppercase;
}
.user-name { color: #fff; font-weight: 600; font-size: .92rem; }
.btn-logout {
    width: 100%; text-align: left; background: none; border: none; cursor: pointer;
    color: #8fa0bd; font-size: .88rem; padding: .2rem 0;
}
.btn-logout:hover { color: #fff; }

.app-main { flex: 1; padding: 1.6rem 2rem 2.5rem; max-width: 980px; }

/* ---------- Dashboard ---------- */
.command-bar {
    display: flex; align-items: center; gap: .7rem;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: var(--shadow); padding: .6rem .9rem; margin-bottom: 1.1rem;
}
.command-icon { color: var(--blue); font-weight: 700; }
.command-bar input {
    flex: 1; border: none; outline: none; font-size: .95rem; background: none; color: var(--text);
}
.command-hint { color: var(--muted); font-size: .78rem; white-space: nowrap; }

.points-card { display: flex; justify-content: space-between; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.points-value { font-size: 2.6rem; font-weight: 800; }
.points-value small { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.points-resets { color: var(--muted); font-size: .85rem; }

.give-details summary { list-style: none; }
.give-details summary::-webkit-details-marker { display: none; }
.give-form { display: grid; gap: .7rem; margin-top: 1rem; min-width: 260px; }
.give-form label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); font-weight: 600; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.summary-item {
    border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem;
    display: flex; flex-direction: column;
}
.summary-label { color: var(--muted); font-size: .8rem; }
.summary-value { font-size: 1.5rem; font-weight: 800; }

.recipient-list, .leaderboard, .account-list, .dept-list, .invite-list, .feed { list-style: none; }
.recipient-list li, .leaderboard li {
    display: flex; justify-content: space-between; align-items: center; gap: .8rem;
    padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .93rem;
}
.recipient-list li:last-child, .leaderboard li:last-child { border-bottom: none; }
.pts { color: var(--blue); font-weight: 700; font-size: .88rem; }
.leaderboard li { justify-content: flex-start; }
.leaderboard .rank { color: var(--muted); font-weight: 700; width: 2.4rem; }
.leaderboard .pts { margin-left: auto; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; margin-bottom: 1.1rem; }
.stat-tile { display: flex; flex-direction: column; gap: .1rem; margin-bottom: 0; }
.stat-icon { color: var(--blue); font-size: 1.05rem; }
.stat-label { color: var(--muted); font-size: .82rem; }
.stat-value { font-size: 1.55rem; font-weight: 800; }

.feed li {
    display: flex; justify-content: space-between; gap: 1rem;
    padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .92rem;
}
.feed li:last-child { border-bottom: none; }
.feed-time { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.feed-text em { color: var(--muted); }

.quick-commands { color: var(--muted); font-size: .82rem; text-align: center; margin-top: .4rem; }

/* ---------- Auth pages ---------- */
.auth-layout { background: var(--bg); }
.auth-main {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 2rem 1rem;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: .35rem; margin-bottom: 1.4rem; }
.auth-brand { font-weight: 800; letter-spacing: .18em; font-size: 1.05rem; }
.auth-tagline { color: var(--muted); font-size: .82rem; }
.auth-card { width: 100%; max-width: 360px; }
.auth-title { font-size: 1.15rem; margin-bottom: .9rem; text-align: center; }
.auth-note { color: var(--muted); font-size: .87rem; margin-bottom: 1rem; text-align: center; }

.btn-provider { width: 100%; margin-bottom: .6rem; color: #fff; padding: .7rem 1rem; }
.btn-teams { background: var(--indigo); }
.btn-teams:hover { background: #3f46a5; }
.btn-slack { background: var(--purple); }
.btn-slack:hover { background: #3d113e; }
.provider-icon { font-size: 1.05rem; }

.auth-divider {
    display: flex; align-items: center; gap: .8rem; color: var(--muted);
    font-size: .8rem; margin: .9rem 0;
}
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.admin-login summary { cursor: pointer; color: var(--muted); font-size: .88rem; text-align: center; }
.admin-login form { display: grid; gap: .7rem; margin-top: .9rem; }
.admin-login label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
.auth-switch { margin-top: 1rem; text-align: center; font-size: .87rem; color: var(--muted); }

/* ---------- Admin / HR shell ---------- */
.admin-layout { background: var(--bg); }
.topbar {
    display: flex; align-items: center; gap: 2rem;
    background: #fff; border-bottom: 1px solid var(--line);
    padding: .7rem 1.6rem; position: sticky; top: 0; z-index: 10;
}
.topbar-logo { display: flex; align-items: center; gap: .55rem; }
.badge-admin {
    background: var(--navy); color: #fff; border-radius: 5px;
    font-size: .68rem; font-weight: 700; letter-spacing: .06em; padding: .15rem .45rem;
}
.topbar-nav { display: flex; gap: .4rem; }
.topbar-nav a {
    text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem;
    padding: .45rem .9rem; border-radius: 8px;
}
.topbar-nav a:hover { background: var(--bg); color: var(--text); }
.topbar-nav a.active { background: var(--navy); color: #fff; }
.topbar-logout { margin-left: auto; }

.admin-main { max-width: 760px; margin: 0 auto; padding: 1.7rem 1.5rem 3rem; }
.admin-main > .page-title + .card-sub { margin-bottom: 1.2rem; }
.admin-wide { max-width: 1080px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-row label, .stack-form label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
.field-hint { color: var(--muted); font-size: .8rem; margin-top: .7rem; }

input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="search"], select {
    border: 1px solid var(--line); border-radius: 8px;
    padding: .5rem .7rem; font-size: .92rem; font-family: inherit;
    background: #fff; color: var(--text); width: 100%;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }

.cycle-reset { display: flex; justify-content: space-between; align-items: center; gap: 1.5rem; }

.invite-list li, .dept-list li {
    display: flex; align-items: center; gap: .9rem;
    padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: .9rem;
}
.invite-list li:last-child, .dept-list li:last-child { border-bottom: none; }
.invite-url { flex: 1; overflow-wrap: anywhere; font-size: .8rem; color: var(--text); }
.invite-expiry, .dept-members { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.dept-list li span:first-child { flex: 1; font-weight: 600; }
.dept-add { display: flex; gap: .7rem; margin-bottom: .9rem; }

.inline-form select { width: auto; font-size: .85rem; padding: .3rem .5rem; }

/* ---------- HR ---------- */
.hr-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; }
.badge-restricted {
    background: #fdeaea; color: var(--red); border: 1px solid #f0caca;
    border-radius: 6px; font-size: .7rem; font-weight: 800; letter-spacing: .05em;
    padding: .3rem .6rem; white-space: nowrap;
}
.hr-toolbar { display: flex; gap: .7rem; margin-bottom: 1.1rem; }
.hr-toolbar input { flex: 1; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); }
thead th {
    background: #f7f9fc; color: var(--muted); font-size: .74rem;
    text-transform: uppercase; letter-spacing: .05em;
}
tbody tr:hover { background: #fafbfd; }
td.num { font-weight: 700; }
td.num-received { color: var(--blue); }
td.msg { color: var(--muted); max-width: 320px; }
td.time { color: var(--muted); white-space: nowrap; font-size: .84rem; }

/* ---------- Settings ---------- */
.stack-form { display: grid; gap: .8rem; max-width: 420px; }
.account-list li { display: flex; align-items: center; gap: .9rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.account-list li:last-child { border-bottom: none; }
.account-platform { border-radius: 6px; font-size: .68rem; font-weight: 800; letter-spacing: .05em; padding: .25rem .5rem; color: #fff; }
.account-slack { background: var(--purple); }
.account-teams { background: var(--indigo); }
.account-name { flex: 1; font-weight: 600; }
.badge-primary {
    background: #eef4fd; color: var(--blue); border: 1px solid #cfe0f8;
    border-radius: 6px; font-size: .7rem; font-weight: 700; padding: .15rem .5rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .sidebar-user { margin-top: .5rem; }
    .app-main { padding: 1.2rem 1rem 2rem; }
    .summary-grid, .stat-row, .field-row { grid-template-columns: 1fr; }
    .points-card, .cycle-reset, .hr-header { flex-direction: column; align-items: flex-start; }
    .command-hint { display: none; }
}

/* ---------- Connectors (admin) ---------- */
.connector-add { display: grid; grid-template-columns: 1fr 1fr 2fr auto; gap: .7rem; margin-bottom: .9rem; }
.connector-secret { display: inline-block; max-width: 220px; overflow-wrap: anywhere; font-size: .72rem; }
.btn-xs { padding: .15rem .5rem; font-size: .75rem; }
@media (max-width: 860px) { .connector-add { grid-template-columns: 1fr; } }

/* Wider main column for HR/admin data tables inside the sidebar layout. */
.app-main-wide { max-width: 1100px; }

/* ---------- HR activity charts ---------- */
.range-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.range-tabs a { padding: .35rem .85rem; font-size: .85rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.range-tabs a:hover { background: var(--bg); }
.range-tabs a.active { background: var(--blue); color: #fff; }

.stat-strip { display: flex; gap: 2.5rem; margin: .3rem 0 1.2rem; }
.stat-strip > div { display: flex; flex-direction: column; }
.stat-strip .stat-num { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-strip .stat-cap { color: var(--muted); font-size: .8rem; }

.chart { display: flex; align-items: flex-end; gap: .5rem; height: 180px; padding: .5rem 0 0; overflow-x: auto; }
.chart-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1 0 28px; height: 100%; }
.chart-bar { width: 60%; min-height: 2px; background: var(--blue); border-radius: 3px 3px 0 0; }
.chart-col:hover .chart-bar { background: var(--navy); }
.chart-label { margin-top: .4rem; font-size: .7rem; color: var(--muted); white-space: nowrap; }

/* ---------- HR log toolbar + pagination ---------- */
.log-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .8rem; margin-bottom: 1rem; }
.log-toolbar label { display: grid; gap: .2rem; font-size: .78rem; color: var(--muted); font-weight: 600; }
.log-toolbar input, .log-toolbar select { width: auto; }
.count-badge { background: var(--bg); color: var(--muted); border-radius: 999px; padding: .05rem .5rem; font-size: .75rem; font-weight: 700; vertical-align: middle; }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; }
.pager-info { color: var(--muted); font-size: .85rem; }
.pager .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }

.build-info { color: var(--muted); font-size: .78rem; text-align: center; margin-top: 1.5rem; font-family: ui-monospace, Menlo, monospace; }


/* ---------- Icons ---------- */
.icon { width: 1.05em; height: 1.05em; flex-shrink: 0; vertical-align: -0.15em; }
.sidebar-nav a, .btn, .btn-logout, .stat-icon, .command-icon { display: inline-flex; align-items: center; gap: .5rem; }
.stat-icon .icon { width: 1.2rem; height: 1.2rem; color: var(--blue); }
.command-icon .icon { color: var(--muted); }

/* Line up all the numbers. */
.balance-value, .points-value, .summary-value, .stat-value, .stat-num,
td.num, .pts, .points-value small, .balance-value small {
    font-variant-numeric: tabular-nums;
}

.connect-buttons { display: flex; flex-wrap: wrap; gap: .6rem; }
.account-actions { display: inline-flex; gap: .4rem; align-items: center; }
.btn-connect {
    background: #fff; border: 1px solid var(--line); color: var(--text);
    font-weight: 600; padding: .55rem 1rem; gap: .55rem;
}
.btn-connect::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; }
.btn-connect:hover { background: #f6f8fb; border-color: #cdd5e2; }
.btn-connect-teams::before { background: var(--indigo); }
.btn-connect-slack::before { background: var(--purple); }

/* ---------- Admin account merge ---------- */
.merge-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .8rem; }
.merge-form label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
.merge-preview { display: flex; align-items: center; gap: 1.5rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.merge-name { font-weight: 700; margin: .2rem 0 0; }
.merge-arrow { font-size: 1.6rem; color: var(--muted); }
.merge-summary { margin: 0 0 1.2rem; }
.merge-actions { display: flex; gap: .7rem; align-items: center; }
