:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --border: #e5e7eb;
    --ok-bg: #ecfdf5; --ok-text: #065f46;
    --err-bg: #fef2f2; --err-text: #991b1b;
    --warn-bg: #fffbeb; --warn-text: #92400e;
}
* { box-sizing: border-box; }
body {
    margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top navigation */
.topnav {
    display: flex; align-items: center; gap: 4px;
    background: #111827; padding: 0 16px; height: 48px;
    position: sticky; top: 0; z-index: 10;
}
.topnav a { color: #d1d5db; padding: 14px 12px; display: inline-block; }
.topnav a:hover { color: #fff; text-decoration: none; }
.topnav a.active { color: #fff; background: #1f2937; }
.topnav .spacer { flex: 1; }
.topnav .who { color: #9ca3af; margin-right: 8px; font-size: 13px; }

/* Layout */
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.panel {
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 16px 20px; margin-bottom: 20px;
}
.panel h2 { margin-top: 0; font-size: 16px; }
h1 { font-size: 20px; }
.muted { color: var(--muted); }
.wrap { word-break: break-all; }
.mt { margin-top: 16px; }

/* Cards */
.cards { display: flex; gap: 16px; flex-wrap: wrap; margin: 16px 0; }
.card {
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 16px 24px; min-width: 140px; text-align: center; color: var(--muted);
}
.card .num { font-size: 28px; font-weight: 700; color: var(--text); }

/* Auth */
.auth-wrap { display: flex; justify-content: center; padding: 48px 16px; }
.auth-card {
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 28px 32px; width: 100%; max-width: 400px;
}
.auth-card.wide { max-width: 560px; }
.auth-card h1 { margin-top: 0; font-size: 18px; }

/* Forms */
label { display: block; margin: 12px 0; font-weight: 500; }
label.inline { font-weight: 400; }
input[type=text], input[type=password], input[type=url], input[type=number], select {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
    margin-top: 4px; font-size: 14px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
legend { padding: 0 6px; color: var(--muted); }

.btn {
    display: inline-block; background: #e5e7eb; color: #111827; border: 0;
    padding: 8px 16px; border-radius: 6px; font-size: 14px; cursor: pointer;
}
.btn:hover { background: #d1d5db; text-decoration: none; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.inline-form { display: inline-block; margin: 4px 8px 0 0; }

/* Flash messages */
.flash { border-radius: 6px; padding: 10px 14px; margin: 12px 0; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.err { background: var(--err-bg); color: var(--err-text); }
.flash.warn { background: var(--warn-bg); color: var(--warn-text); }
.topnav + .flash { max-width: 1100px; margin: 12px auto; padding: 10px 14px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.actions { white-space: nowrap; }

/* TOTP */
.totp-secret {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px;
    letter-spacing: .15em; background: #f3f4f6; padding: 10px; border-radius: 6px;
    display: inline-block; user-select: all;
}

/* Code block */
pre.code {
    background: #111827; color: #d1d5db; padding: 12px 16px; border-radius: 6px;
    overflow-x: auto; font-size: 13px;
}

/* Block 4: reports & dashboard */
.container.wide { max-width: 1400px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.filterbar {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px 16px; margin-bottom: 20px;
}
.filterbar label { margin: 0; font-size: 13px; color: var(--muted); }
.filterbar select { width: auto; min-width: 120px; margin-top: 2px; }
.filterbar .btn { margin-bottom: 1px; }

.chartbox { position: relative; height: 300px; margin: 12px 0 20px; }
.chartbox canvas { width: 100% !important; height: 100% !important; }

.scrollx { overflow-x: auto; }

/* ABC class colouring (tables rendered with class="abc") */
table.abc td:last-child { font-weight: 600; }
table.abc td.cA, table.matrix td.mxa { background: #dcfce7; color: #166534; }
table.abc td.cB, table.matrix td.mxb { background: #fef9c3; color: #854d0e; }
table.abc td.cC, table.matrix td.mxc { background: #fee2e2; color: #991b1b; }

/* ABC+XYZ matrix */
table.matrix { border-collapse: collapse; }
table.matrix th, table.matrix td {
    border: 1px solid var(--border); text-align: center; padding: 10px 14px; min-width: 90px;
}
table.matrix td.mx { position: relative; font-size: 18px; font-weight: 600; cursor: default; }
table.matrix td.mx.zero { background: #f3f4f6; color: #9ca3af; font-weight: 400; }
.mxhint {
    display: none; position: absolute; z-index: 5; left: 50%; bottom: 105%; transform: translateX(-50%);
    background: #111827; color: #f9fafb; font-size: 12px; font-weight: 400; line-height: 1.4;
    padding: 8px 10px; border-radius: 6px; width: 220px; box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
td.mx:hover .mxhint { display: block; }

/* product × store heat matrix */
td.mx.h1 { background: #dbeafe; }
td.mx.h2 { background: #93c5fd; }
td.mx.h3 { background: #2563eb; color: #fff; }

/* nav dropdown */
.dropdown { position: relative; }
.dropbtn {
    background: none; border: 0; color: #d1d5db; font-size: 14px; padding: 14px 12px; cursor: pointer;
    font-family: inherit;
}
.dropbtn:hover { color: #fff; }
.dropdown-content {
    display: none; position: absolute; background: #1f2937; min-width: 180px;
    border-radius: 0 0 8px 8px; box-shadow: 0 8px 16px rgba(0,0,0,.3); z-index: 20;
}
.dropdown-content a { display: block; padding: 10px 16px; color: #d1d5db; }
.dropdown-content a:hover { background: #374151; color: #fff; text-decoration: none; }
.dropdown:hover .dropdown-content { display: block; }

td.mx .mxamount { font-size: 11px; font-weight: 400; color: var(--muted); }
