/* Admin panel - redesigned */

:root {
    --accent: #4f46e5;
    --sidebar-bg: #1f2430;
    --sidebar-fg: #cfd4df;
    --sidebar-fg-active: #ffffff;
    --bg: #f1f3f8;
    --card-border: #e6e8ef;
    --muted: #6c757d;
}

/* KPI cards (base; dashboard refinements below) */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}
.kpi-card {
    background: #fff; border: 1px solid var(--card-border); border-radius: 14px;
    padding: 1rem 1.1rem; display: flex; align-items: center; gap: .9rem;
}
.kpi-ico {
    width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.3rem; color: #fff;
}
.kpi-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.kpi-sub { font-size: .78rem; color: var(--muted); }
.kpi-accent .kpi-ico { background: var(--accent); }
.kpi-green  .kpi-ico { background: #43a047; }
.kpi-red    .kpi-ico { background: #e53935; }
.kpi-blue   .kpi-ico { background: #2f80ed; }
.kpi-gray   .kpi-ico { background: #6c757d; }

.kpi-amber  .kpi-ico { background: #f59e0b; }
.chart-title { font-size: 1rem; font-weight: 700; margin-bottom: .15rem; }
.chart-sub { font-size: .82rem; color: var(--muted); margin-bottom: .9rem; }

/* Compact chart box */
.chart-box { position: relative; height: 240px; }

/* Latest responses pager */
.latest-pager { display: flex; align-items: center; justify-content: flex-end; gap: .75rem; margin-top: .6rem; }
.latest-info { font-size: .82rem; color: var(--muted); }

/* Department CSAT rows */
.dd-row { display: grid; grid-template-columns: minmax(130px, 1.4fr) 2fr 60px; align-items: center; gap: .75rem; }
.dd-name { font-weight: 600; font-size: .92rem; }
.dd-sub { font-size: .78rem; color: var(--muted); }

/* Dashboard tabs */
.dash-tabs .nav-link { color: var(--muted); cursor: pointer; }
.dash-tabs .nav-link.active { color: var(--accent); font-weight: 600; }

/* Faces distribution bars */
.faces-dist { display: flex; flex-direction: column; gap: .9rem; }
.fd-row { display: grid; grid-template-columns: 40px 1fr 54px; align-items: center; gap: .75rem; }
.fd-face svg { width: 34px; height: 34px; display: block; }
.fd-mid { display: flex; flex-direction: column; gap: .3rem; }
.fd-label { font-size: .9rem; font-weight: 600; }
.fd-track { height: 8px; background: #eef1f5; border-radius: 6px; overflow: hidden; }
.fd-fill { height: 100%; border-radius: 6px; }
.fd-pct { text-align: right; font-weight: 700; font-size: .95rem; }

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: #232733;
}

.btn-accent {
    background: var(--accent);
    border: none;
    color: #fff;
}
.btn-accent:hover {
    background: color-mix(in srgb, var(--accent), #000 12%);
    color: #fff;
}

/* Brand box (logo + name) */
.brand-box {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 800;
    font-size: 1.25rem;
}
.brand-box img { height: 34px; width: auto; }
.brand-dot {
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--accent);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800;
}

/* Language switcher (in topbar / login card) */
.topbar-lang { display: flex; gap: .5rem; }
.lang-row { display: flex; gap: .5rem; justify-content: flex-end; }
.flag-btn {
    padding: 0; border: 2px solid transparent; border-radius: 8px;
    background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15);
    cursor: pointer; line-height: 0; overflow: hidden; opacity: .75;
    transition: opacity .15s, border-color .15s;
}
.flag-btn:hover { opacity: 1; }
.flag-btn.active { opacity: 1; border-color: var(--accent); }
.flag-btn .flag { width: 38px; height: 25px; display: block; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    background:
        radial-gradient(1200px 500px at 10% 0%, color-mix(in srgb, var(--accent), #fff 82%), transparent),
        radial-gradient(900px 500px at 100% 100%, color-mix(in srgb, var(--accent), #fff 88%), transparent),
        #eef1fb;
}
.login-card {
    background: #fff; border-radius: 18px;
    box-shadow: 0 18px 50px rgba(30, 36, 60, .18);
    padding: 2.25rem; width: 100%; max-width: 400px;
}

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px; flex-shrink: 0;
    background: var(--sidebar-bg); color: var(--sidebar-fg);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
    padding: 1.25rem 1.25rem; color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .brand-box { color: #fff; }
.sidebar-nav { padding: .75rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.sidebar-nav .nav-item {
    display: flex; align-items: center; gap: .7rem;
    background: none; border: none; color: var(--sidebar-fg);
    padding: .7rem .85rem; border-radius: 10px; cursor: pointer;
    font-size: .98rem; text-align: left; width: 100%;
    transition: background .15s, color .15s;
}
.sidebar-nav .nav-item:hover { background: rgba(255,255,255,.06); color: var(--sidebar-fg-active); }
.sidebar-nav .nav-item.active {
    background: var(--accent); color: #fff;
}
.nav-ico { font-size: 1.05rem; width: 1.4rem; text-align: center; }

.sidebar-footer {
    padding: 1rem; border-top: 1px solid rgba(255,255,255,.08);
}
.user-box { margin-bottom: .6rem; }
.user-name { color: #fff; font-weight: 600; font-size: .95rem; }
.user-role { color: var(--sidebar-fg); font-size: .8rem; text-transform: capitalize; }

.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1040;
}

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: .75rem;
    background: #fff; border-bottom: 1px solid var(--card-border);
    padding: .85rem 1.25rem; position: sticky; top: 0; z-index: 900;
}
.topbar-title { font-size: 1.25rem; font-weight: 700; margin: 0; }
.topbar-spacer { flex: 1; }

.content { padding: 1.5rem; }
.section-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.section-title { font-size: 1.15rem; font-weight: 700; margin: 0; }

.card { border: 1px solid var(--card-border); border-radius: 14px; }

.link-cell { display: flex; align-items: center; gap: .4rem; max-width: 300px; }
.link-cell code {
    font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Icon action buttons */
.btn-icon { padding: .25rem .5rem; margin-left: .25rem; line-height: 1; }
.btn-icon i { font-size: .95rem; }
.protected-shield { color: var(--accent); margin-left: .35rem; }

/* Status toggle cell */
.form-switch .form-check-input { cursor: pointer; }

/* Collapsed sidebar (desktop) */
.sidebar { transition: width .2s ease; }
.shell.collapsed .sidebar { width: 74px; }
.shell.collapsed .nav-label { display: none; }
.shell.collapsed .brand-box span:not(.brand-dot) { display: none; }
.shell.collapsed .user-box { display: none; }
.shell.collapsed .sidebar-nav .nav-item { justify-content: center; }
.shell.collapsed .sidebar-brand { display: flex; justify-content: center; }
.shell.collapsed .sidebar-footer .btn .nav-label { display: none; }

/* Responsive sidebar */
@media (max-width: 767.98px) {
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 1050;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    /* On mobile the collapse rail is not used. */
    .shell.collapsed .sidebar { width: 250px; }
    .shell.collapsed .nav-label,
    .shell.collapsed .brand-box span:not(.brand-dot),
    .shell.collapsed .user-box,
    .shell.collapsed .sidebar-footer .btn .nav-label { display: initial; }
}

/* Keep hidden login, app shell and controls hidden even when styled as flex/grid. */
[hidden] { display: none !important; }

/* Branch selection and collection points, scoped to the locations section. */
#section-locations .locations-title { font-size: 1.45rem; font-weight: 700; margin-bottom: .35rem; }
#section-locations .locations-columns { display: grid; grid-template-columns: minmax(235px, .85fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
#section-locations .locations-panel { background: #fff; border: 1px solid var(--card-border); border-radius: 14px; overflow: hidden; min-width: 0; }
#section-locations .locations-panel-head { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: 1.15rem; border-bottom: 1px solid var(--card-border); flex-wrap: wrap; }
#section-locations .locations-panel-head h3 { font-size: 1.05rem; font-weight: 700; margin: 0; overflow-wrap: anywhere; }
#section-locations .location-caption { display: block; font-size: .78rem; color: var(--muted); margin-top: .2rem; }
#section-locations .location-branch { padding: 1rem 1.15rem; border-bottom: 1px solid var(--card-border); }
#section-locations .location-branch:last-child, #section-locations .location-point:last-child { border-bottom: 0; }
#section-locations .location-branch.selected { background: #f2f0ff; box-shadow: inset 3px 0 var(--accent); }
#section-locations .location-branch-select { width: 100%; display: block; text-align: left; border: 0; padding: 0; background: transparent; color: inherit; overflow-wrap: anywhere; }
#section-locations .location-branch-actions { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: .75rem; }
.location-switch { margin: 0; display: inline-flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--muted); }
.location-switch .form-check-input { flex-shrink: 0; margin-top: 0; cursor: pointer; }
.location-switch .form-check-input:disabled { cursor: not-allowed; }
#section-locations .location-point { padding: 1.25rem; border-bottom: 1px solid var(--card-border); }
#section-locations .location-point-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
#section-locations .location-point-identity { display: flex; align-items: center; gap: .75rem; min-width: 0; }
#section-locations .location-point-identity strong { overflow-wrap: anywhere; }
#section-locations .location-point-icon { background: #f2f0ff; color: var(--accent); border-radius: 10px; padding: .7rem; font-size: 1.15rem; }
#section-locations .location-destination { margin: 1rem 0; }
#section-locations .location-destination strong { display: block; font-size: .95rem; font-weight: 500; overflow-wrap: anywhere; }
#section-locations .location-point-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
#section-locations .locations-empty { color: var(--muted); padding: 1.5rem; margin: 0; }
@media(max-width:850px) { #section-locations .locations-columns { grid-template-columns: 1fr; } }

/* Dashboard tabs and shared branch/point filters share one desktop toolbar. */
.dashboard-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; }
.dashboard-toolbar .dash-tabs { flex: 0 0 auto; }
.dashboard-scope { display: flex; flex: 1 1 340px; gap: 1rem; max-width: 590px; margin-left: auto; min-width: 0; }
.dashboard-scope-field { display: flex; align-items: center; gap: .5rem; flex: 1 1 0; min-width: 0; margin: 0; }
.dashboard-scope-field > span { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.dashboard-scope-field .form-select { min-width: 0; text-overflow: ellipsis; }
.dashboard-toolbar .dash-clock { flex: 0 0 auto; margin-left: auto; }
@media (max-width: 1199px) {
    .dashboard-scope { order: 3; flex-basis: 100%; max-width: none; }
}
@media (max-width: 575px) {
    .dashboard-scope { flex-wrap: wrap; gap: .6rem; }
    .dashboard-scope-field { flex-basis: 100%; }
    .dashboard-scope-field > span { min-width: 4.5rem; }
}

/* r39: one scrolling region, with account actions kept in normal layout. */
.sidebar {
    height: 100vh; height: 100dvh; min-height: 0;
    overflow: hidden; align-self: flex-start;
}
.sidebar-brand, .sidebar-footer { flex: 0 0 auto; }
.sidebar-brand { padding: 1rem; }
.sidebar-brand .brand-box { font-size: 1.1rem; min-width: 0; }
.brand-dot, .brand-box img { flex-shrink: 0; }
.sidebar-brand .brand-box > span:last-child { overflow-wrap: anywhere; }
.sidebar-nav {
    min-height: 0; overflow-y: auto; overflow-x: hidden; flex: 1 1 0;
    overscroll-behavior-y: contain; scrollbar-width: thin;
    scrollbar-color: #8791a5 var(--sidebar-bg);
    padding: .65rem; gap: .2rem;
}
.sidebar-nav .nav-item { flex-shrink: 0; padding: .65rem .75rem; min-height: 44px; }
.sidebar .nav-label { min-width: 0; overflow-wrap: anywhere; }
.sidebar .nav-ico { flex-shrink: 0; }
.sidebar-footer {
    padding: .8rem;
    padding-bottom: max(.8rem, env(safe-area-inset-bottom, 0px));
    background: var(--sidebar-bg);
}
.sidebar-footer .btn { min-height: 40px; white-space: normal; }
.user-name { overflow-wrap: anywhere; }
.sidebar button:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }
.shell.collapsed .sidebar-brand { padding: 1rem .5rem; }
.shell.collapsed .sidebar-nav { padding-inline: .45rem; }
.shell.collapsed .sidebar-footer { padding-inline: .45rem; }
/* Short windows and zoom: scroll the entire sidebar, without nested scrollbars. */
@media (max-height: 40rem) {
    .sidebar {
        overflow-y: auto; overflow-x: hidden;
        overscroll-behavior-y: contain; scrollbar-width: thin;
        scrollbar-color: #8791a5 var(--sidebar-bg);
    }
    .sidebar-nav { flex: 1 0 auto; overflow: visible; }
}
#section-access .table { table-layout: auto; width: 100%; }
#section-access .table th, #section-access .table td { white-space: nowrap; width: auto; }
#section-devices td:last-child { white-space: nowrap; }

/* Shared action hints: same appearance across administration tables. */
.qmpc-action-tooltip {
    --bs-tooltip-bg: #25243d;
    --bs-tooltip-color: #fff;
    --bs-tooltip-opacity: 1;
    --bs-tooltip-border-radius: .5rem;
    --bs-tooltip-padding-x: .75rem;
    --bs-tooltip-padding-y: .5rem;
    --bs-tooltip-font-size: .8rem;
    --bs-tooltip-max-width: 240px;
    z-index: 1090;
}
.qmpc-action-tooltip .tooltip-inner {
    max-width: min(240px, calc(100vw - 16px));
    box-shadow: 0 4px 14px rgba(23, 23, 48, .18);
    line-height: 1.4;
}
.action-hint-disabled { display: inline-block; border-radius: .25rem; }
.action-hint-disabled > button { pointer-events: none; }
.action-hint-disabled:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* r36: adjacent edit/delete controls at the right edge of each branch. */
#section-locations .location-branch-actions { justify-content: flex-start; }
#section-locations .location-branch-buttons { display: flex; align-items: center; gap: .35rem; margin-left: auto; flex-shrink: 0; }
#section-locations .location-branch-buttons .btn-icon { margin-left: 0; }
.branch-delete-protected { position: relative; }
.branch-delete-prohibition { position: absolute; right: -.2rem; top: -.25rem; color: #dc3545; background: #fff; border-radius: 50%; font-size: .75rem; line-height: 1; padding: 1px; pointer-events: none; }

/* r42: horizontal metrics; wrap whole cards rather than their labels. */
#section-dashboard { container-type: inline-size; }
#section-dashboard .kpi-grid {
    display: flex; flex-wrap: wrap; gap: .75rem;
}
#section-dashboard .kpi-card {
    --metric-color: #4f46e5; --metric-tint: #eeedff;
    position: relative; display: grid;
    flex: 1 1 calc((100% - 2.25rem) / 4);
    grid-template-columns: 30px minmax(max-content, 1fr) auto;
    grid-template-rows: auto auto;
    align-content: center; align-items: center; column-gap: .5rem; row-gap: .2rem;
    min-width: max-content; padding: .8rem .75rem;
    border: 1px solid #e3e7f0; border-left: 3px solid var(--metric-color);
    border-radius: 12px; background: #fff;
    box-shadow: 0 2px 8px rgba(31, 36, 48, .025);
}
#section-dashboard .kpi-green { --metric-color: #22834a; --metric-tint: #eaf7ef; }
#section-dashboard .kpi-red { --metric-color: #cf3543; --metric-tint: #fff0f1; }
#section-dashboard .kpi-amber { --metric-color: #aa6a05; --metric-tint: #fff5df; }
#section-dashboard .kpi-blue { --metric-color: #2466d1; --metric-tint: #edf4ff; }
#section-dashboard .kpi-body { display: contents; }
#section-dashboard .kpi-ico {
    grid-column: 1; grid-row: 1 / 3; align-self: center; width: 30px; height: 34px;
    border-radius: 9px; font-size: 1rem;
    color: var(--metric-color); background: var(--metric-tint);
    border: 1px solid color-mix(in srgb, var(--metric-color) 12%, transparent);
}
#section-dashboard .kpi-label {
    grid-column: 2; grid-row: 1; align-self: end;
    color: #525e73; font-size: .78rem; font-weight: 600;
    text-transform: none; letter-spacing: 0; line-height: 1.3;
    white-space: nowrap;
}
#section-dashboard .kpi-value {
    grid-column: 3; grid-row: 1 / 3; align-self: center; text-align: right;
    font-size: 1.6rem; font-weight: 750;
    color: #202b40; line-height: 1.1; letter-spacing: -.035em;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
#section-dashboard .kpi-sub {
    grid-column: 2; grid-row: 2; align-self: start;
    color: #667287; font-size: .7rem; line-height: 1.4;
    white-space: nowrap;
}
#section-dashboard .kpi-grid-nps > .kpi-card {
    flex-basis: calc((100% - 3rem) / 5);
}
@container (max-width: 23rem) {
    #section-dashboard .kpi-card { flex-basis: 100%; }
}
