/* PSE CRM shell. Colours are tokens; module screens should reuse them. */
:root {
    --side: #0f3d4c;
    --side-hover: #16566a;
    --side-active: #1f6f86;
    --side-text: #cfe3e9;
    --accent: #1a73e8;
    --accent-dark: #1559b3;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --line: #e1e5ea;
    --text: #1f2933;
    --muted: #66727f;
    --ok: #1e8e3e;
    --error: #c5221f;
    --info: #1a73e8;
    --radius: 6px;
    --side-w: 65px;
    --top-h: 48px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Khmer", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 12px; font-weight: 600; }
code { background: #eef1f4; padding: 2px 6px; border-radius: 4px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* Shell */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--side); display: flex; flex-direction: column; align-items: stretch; z-index: 10; }
.logo { height: var(--top-h); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; letter-spacing: .5px; font-size: 13px; }
.logo:hover { text-decoration: none; }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 2px; color: var(--side-text); font-size: 10px; text-align: center; }
.nav-item:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #fff; }
.nav-bottom { margin-top: auto; }
.main { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: var(--top-h); background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 16px; position: sticky; top: 0; z-index: 5; }
.search { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 18px; padding: 0 12px; height: 32px; flex: 0 1 380px; color: var(--muted); }
.search input { border: 0; background: transparent; outline: none; flex: 1; font: inherit; min-width: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn-plus { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; list-style: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--side-active); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; cursor: pointer; list-style: none; }
.menu { position: relative; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: 40px; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: 6px 0; }
.menu-list a, .menu-list button { display: block; width: 100%; text-align: left; padding: 8px 14px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.menu-list a:hover, .menu-list button:hover { background: var(--bg); text-decoration: none; }
.menu-list a ~ .menu-empty { display: none; }
.menu-empty { display: block; padding: 8px 14px; color: var(--muted); }
.menu-head { padding: 8px 14px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-weight: 600; }
.menu-head small { display: block; color: var(--muted); font-weight: 400; }
.content { padding: 20px 24px; flex: 1; }

/* Blocks */
.page-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 8px; }
.back { font-size: 13px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px; }
.panel.narrow { max-width: 460px; }
.panel.empty { color: var(--muted); }
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.flash-ok { color: var(--ok); background: #e6f4ea; border-color: #b7dfc2; }
.flash-error { color: var(--error); background: #fce8e6; border-color: #f3c1bd; }
.flash-info { color: var(--info); background: #e8f0fe; border-color: #c2d6fb; }

/* Settings tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.tile:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(26,115,232,.15); text-decoration: none; }
.tile-icon { width: 40px; height: 40px; border-radius: 8px; background: #e7f1f4; color: var(--side); display: flex; align-items: center; justify-content: center; }
.tile-title { font-weight: 600; font-size: 15px; }
.tile-text { color: var(--muted); font-size: 13px; }

/* Forms and buttons */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form small { color: var(--muted); font-weight: 400; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #c9d1d9; border-radius: var(--radius); background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #a8c7fa; border-color: var(--accent); }
.btn { display: inline-block; padding: 8px 16px; border-radius: var(--radius); border: 1px solid #c9d1d9; background: #fff; color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 8px 0; font: inherit; }
.filter { display: flex; gap: 8px; margin-bottom: 12px; }
.filter input { flex: 0 1 320px; }

/* Tables */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; background: #fafbfc; }
.table tr:hover td { background: #f8fafb; }
.details { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); max-width: 360px; word-break: break-word; }

/* Sign-in screens */
body.bare { display: flex; align-items: flex-start; justify-content: center; min-height: 100vh; background: linear-gradient(180deg, var(--side) 0 220px, var(--bg) 220px); }
.card-center { width: 100%; max-width: 420px; margin: 60px 16px; background: var(--panel); border-radius: 10px; padding: 28px; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.brand { font-weight: 700; color: var(--side); font-size: 18px; margin-bottom: 18px; }
.steps { padding-left: 20px; }
.qr { display: flex; justify-content: center; margin: 12px 0; min-height: 10px; }
.secret { font-size: 15px; letter-spacing: 1px; word-break: break-all; }

@media (max-width: 640px) {
    .content { padding: 16px; }
    .nav-item span { display: none; }
    .search { flex-basis: auto; }
}

/* Alerts settings */
.alert-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.alert-grid h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.alert-events { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.alert-events legend { font-weight: 500; padding: 0 4px; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.alert-test { margin-top: 10px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--line); color: var(--muted); }
.badge-on { background: #e6f4ea; color: var(--ok); }

/* Google sign-in */
.or-line { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 16px 0; }
.or-line::before, .or-line::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.btn-google { display: block; text-align: center; font-weight: 600; }
.form .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.choices { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.choices legend { font-weight: 500; padding: 0 4px; }

/* Backup */
.backup-top { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.backup-top h2 { font-size: 16px; margin: 0 0 6px; }
.badge-ok { background: #e6f4ea; color: var(--ok); }
.badge-failed { background: #fce8e6; color: var(--error); }
.badge-running, .badge-queued { background: #e8f0fe; color: var(--info); }
.steps code { word-break: break-all; }

/* Settings: Users and Roles */
.head-action { margin-left: auto; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge-ok { color: var(--ok); border-color: #b7dfc2; background: #e6f4ea; }
.badge-warn { color: #8a5a00; border-color: #f1d48a; background: #fef7e0; }
.badge-off { color: var(--error); border-color: #f3c1bd; background: #fce8e6; }
.filter select { font: inherit; }
.narrow-wide { max-width: 640px; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 500; }
.form label.check, label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
label.check input { margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.action-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.action-list form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.perm-matrix .center { text-align: center; }
.perm-matrix .group-row td { background: var(--bg); font-weight: 600; }
.perm-matrix input { width: 18px; height: 18px; }

/* Settings: audit log + data import */
.filter-wrap { flex-wrap: wrap; align-items: flex-end; }
.filter-wrap label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge-connected, .badge-ok { color: var(--ok); border-color: currentColor; }
.badge-error, .badge-failed { color: var(--error); border-color: currentColor; }
.badge-running, .badge-not_tested { color: var(--info); border-color: currentColor; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
