﻿/* Assessment Toolkit Shell: dark sidebar + header layout, wraps all tool pages */

/* ---------- Design tokens ---------- */
:root {
    --bg: #0a0a0c;
    --surface: #141417;
    --surface-2: #1c1c21;
    --surface-3: #26262c;
    --border: #2c2c33;
    --border-strong: #3a3a44;
    --text: #f5f5f7;
    --text-muted: #8e8e99;
    --text-dim: #5a5a66;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: rgba(37, 99, 235, 0.12);
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.12);
    --yellow: #eab308;
    --yellow-bg: rgba(234, 179, 8, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --purple: #a855f7;
    --purple-bg: rgba(168, 85, 247, 0.12);
    --orange: #f97316;
    --orange-bg: rgba(249, 115, 22, 0.12);
    --sidebar-w: 240px;
    --header-h: 56px;
    --radius: 10px;
    --radius-sm: 8px;
}

[data-theme="light"] {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --surface-3: #e4e6eb;
    --border: #dcdce2;
    --border-strong: #c0c0ca;
    --text: #17181c;
    --text-muted: #63636e;
    --text-dim: #9494a0;
    --accent-bg: rgba(37, 99, 235, 0.08);
    --green-bg: rgba(34, 197, 94, 0.08);
    --yellow-bg: rgba(234, 179, 8, 0.08);
    --red-bg: rgba(239, 68, 68, 0.08);
    --purple-bg: rgba(168, 85, 247, 0.08);
    --orange-bg: rgba(249, 115, 22, 0.08);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { overflow-x: hidden; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    overflow-x: hidden;
    max-width: 100vw;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Prevent any child from pushing past the viewport on small screens */
.main-area, .content, .card, .stat-card, .action-card { min-width: 0; max-width: 100%; }
img, svg, canvas, video, iframe { max-width: 100%; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.25s ease;
}
.sidebar-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-header .menu-label { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.sidebar-header .collapse-btn {
    background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); cursor: pointer;
    padding: 7px; border-radius: var(--radius-sm); font-size: 1.1rem; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    transition: background 0.15s, border-color 0.15s;
}
.sidebar-header .collapse-btn:hover { background: var(--surface-3); border-color: var(--accent); }
.sidebar-header .collapse-btn svg { width: 18px; height: 18px; stroke: currentColor; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-section-label {
    font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-dim); padding: 12px 12px 4px; margin-top: 6px;
    border-top: 1px solid var(--border);
}
.nav-item.nav-tool { font-size: 0.78rem; opacity: 0.85; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; margin: 2px 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted); text-decoration: none;
    font-size: 0.85rem; font-weight: 500;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
.nav-item .nav-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* Sidebar collapsed (desktop): icons only with tooltips */
body.sidebar-collapsed .sidebar { width: 64px; }
body.sidebar-collapsed .sidebar-header { justify-content: center; padding: 0; }
body.sidebar-collapsed .sidebar-header .menu-label,
body.sidebar-collapsed .nav-section-label { display: none; }
body.sidebar-collapsed .sidebar-nav .nav-item {
    justify-content: center;
    padding: 10px 0;
    position: relative;
}
body.sidebar-collapsed .sidebar-nav .nav-item .icon { margin: 0; }
body.sidebar-collapsed .sidebar-nav .nav-item .nav-text { display: none; }
body.sidebar-collapsed .main-area { margin-left: 64px; }

/* Collapse button always visible in both states */
.sidebar-header .collapse-btn {
    flex-shrink: 0;
    min-width: 34px;
    min-height: 34px;
    visibility: visible;
    opacity: 1;
}

/* Tooltip on hover when collapsed */
body.sidebar-collapsed .sidebar-nav .nav-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface-3);
    color: var(--text);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
body.sidebar-collapsed .sidebar-nav .nav-item:hover::after {
    opacity: 1;
}

/* Main area */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* Header */
.top-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
}
.mobile-menu-btn {
    display: none;
    background: none; border: none; color: var(--text);
    font-size: 1.3rem; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.mobile-menu-btn:hover { background: var(--surface-2); }
.header-brand {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: var(--text);
}
.header-brand .logo-badge {
    width: 32px; height: 32px; border-radius: 8px;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.header-brand .brand-name { font-size: clamp(0.8rem, 1vw + 0.55rem, 0.9rem); font-weight: 700; line-height: 1.2; }
.header-brand .brand-sub { font-size: clamp(0.62rem, 0.8vw + 0.4rem, 0.7rem); color: var(--text-muted); font-weight: 400; }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.region-badge {
    background: var(--accent-bg); color: var(--accent);
    border: 1px solid rgba(37, 99, 235, 0.25); border-radius: 999px;
    padding: 4px 10px; font-size: 0.7rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 220px;
}
.theme-toggle {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.1rem; cursor: pointer; padding: 6px 8px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.sign-in-btn {
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 8px;
    padding: 7px 14px; font-size: 0.8rem; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: background 0.15s, border-color 0.15s;
}
.sign-in-btn:hover { background: var(--surface-3); border-color: var(--text-dim); }

/* Content */
.content { flex: 1; padding: 20px 24px; width: 100%; }
.page-title { font-size: clamp(1.15rem, 2.5vw + 0.6rem, 1.5rem); font-weight: 700; margin-bottom: 4px; overflow-wrap: anywhere; }
.page-subtitle { font-size: clamp(0.78rem, 1vw + 0.55rem, 0.85rem); color: var(--text-muted); margin-bottom: 20px; overflow-wrap: anywhere; }
.section-title { font-size: clamp(0.92rem, 1.2vw + 0.65rem, 1.05rem); font-weight: 700; margin-bottom: 12px; }

/* ---------- Components ---------- */

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.stat-card .stat-icon {
    width: 42px; height: 42px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem; flex-shrink: 0;
}
.stat-card .stat-label { font-size: clamp(0.65rem, 0.8vw + 0.45rem, 0.72rem); color: var(--text-muted); margin-bottom: 2px; overflow-wrap: anywhere; }
.stat-card .stat-value { font-size: clamp(1.05rem, 1.6vw + 0.7rem, 1.35rem); font-weight: 700; line-height: 1.1; }

.icon-bg-blue { background: var(--accent-bg); color: var(--accent); }
.icon-bg-green { background: var(--green-bg); color: var(--green); }
.icon-bg-purple { background: var(--purple-bg); color: var(--purple); }
.icon-bg-orange { background: var(--orange-bg); color: var(--orange); }
.icon-bg-yellow { background: var(--yellow-bg); color: var(--yellow); }
.icon-bg-red { background: var(--red-bg); color: var(--red); }

/* Quick actions */
.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.action-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    display: flex; flex-direction: column; gap: 8px;
    transition: border-color 0.15s, transform 0.15s;
}
.action-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.action-card .action-icon { font-size: 1.2rem; }
.action-card .action-label { font-size: clamp(0.78rem, 1vw + 0.5rem, 0.85rem); font-weight: 600; overflow-wrap: anywhere; }

/* Cards / panels */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: clamp(0.9rem, 1.1vw + 0.62rem, 1rem); font-weight: 700; }
.view-all { font-size: 0.78rem; color: var(--accent); text-decoration: none; font-weight: 600; }
.view-all:hover { text-decoration: underline; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.data-table th {
    text-align: left; padding: 8px 10px;
    color: var(--text-muted); font-weight: 600; font-size: 0.72rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.data-table td { overflow-wrap: anywhere; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }

/* On phones, allow table cells to wrap so no horizontal scroll needed */
@media (max-width: 640px) {
    .data-table { min-width: 0; }
    .data-table th, .data-table td { white-space: normal; padding: 8px 8px; font-size: 0.78rem; }
    .data-table th { font-size: 0.68rem; }
}

/* Badges */
.badge {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 0.7rem; font-weight: 600; white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--accent-bg); color: var(--accent); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: var(--surface-3); color: var(--text-muted); }

.grade-pill {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 26px; height: 22px; border-radius: 6px;
    font-size: 0.72rem; font-weight: 700;
    background: var(--surface-3); color: var(--text);
}
.grade-A, .grade-EE { background: var(--green-bg); color: var(--green); }
.grade-B, .grade-ME { background: var(--accent-bg); color: var(--accent); }
.grade-C, .grade-AE { background: var(--yellow-bg); color: var(--yellow); }
.grade-D, .grade-BE { background: var(--orange-bg); color: var(--orange); }
.grade-F { background: var(--red-bg); color: var(--red); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    font-size: 0.82rem; font-weight: 600; cursor: pointer;
    text-decoration: none; transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: transparent; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.2); }
.btn-sm { padding: 6px 12px; font-size: 0.75rem; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-group label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 9px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--accent);
}
.form-group textarea { resize: vertical; min-height: 70px; }

/* Empty state */
.empty-state {
    text-align: center; padding: 40px 20px;
    color: var(--text-muted); font-size: 0.85rem;
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.4; }

/* Status/error messages */
.status-msg {
    padding: 8px 14px; border-radius: 8px; font-size: 0.8rem; margin-bottom: 12px;
}
.status-msg.error { background: var(--red-bg); color: var(--red); }
.status-msg.success { background: var(--green-bg); color: var(--green); }
.status-msg.info { background: var(--accent-bg); color: var(--accent); }

/* Tool iframe embed */
.content:has(.tool-frame-page) { padding: 0; }
.tool-frame-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-h));
    margin: 0;
    max-width: 100%;
}
.tool-frame-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.back-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
}
.back-link:hover { text-decoration: underline; }
.tool-frame-title {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}
.tool-frame-wrap {
    flex: 1;
    min-height: 0;
    background: var(--bg);
    overflow: hidden;
    position: relative;
}
.tool-frame-wrap iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: var(--bg);
}

/* Embedded tools: fill frame height, adapt to frame width */
html.embedded, html.embedded body {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}
html.embedded .wb-app,
html.embedded .xl-app { height: 100%; }

/* Inside a narrow iframe, compact the tool's own header */
@media (max-width: 640px) {
    html.embedded .xl-header h1,
    html.embedded .wb-header h1 { font-size: 0.82rem; }
}

/* ---------- Responsive ---------- */

/* Large desktop: full-width fluid layout */
@media (min-width: 1600px) {
    .content { max-width: none; }
    .tool-frame-page { max-width: none; margin: 0; }
}

/* Desktop: wider stat and action grids */
@media (min-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .action-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Tablet and below: drawer sidebar */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: 4px 0 20px rgba(0,0,0,0.4); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main-area { margin-left: 0 !important; }
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: var(--surface-2);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-sm);
        cursor: pointer;
    }
    .mobile-menu-btn:hover { background: var(--surface-3); border-color: var(--accent); }
    .mobile-menu-btn svg { width: 20px; height: 20px; stroke: var(--text); }
    /* Hide the sidebar collapse button on mobile - use the header menu button instead */
    .sidebar-header .collapse-btn { display: none; }
    /* Sidebar header in mobile shows a close button */
    .sidebar-header { justify-content: space-between; padding: 0 12px; }
    .content { padding: 14px 14px 40px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .action-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    /* Drawer mode always shows full labels regardless of collapsed state */
    body.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
    body.sidebar-collapsed .sidebar-header { justify-content: space-between; padding: 0 12px; }
    body.sidebar-collapsed .sidebar-header .menu-label { display: block; }
    body.sidebar-collapsed .nav-section-label { display: block; }
    body.sidebar-collapsed .sidebar-nav .nav-item { justify-content: flex-start; padding: 9px 12px; }
    body.sidebar-collapsed .sidebar-nav .nav-item .nav-text { display: inline; }
    body.sidebar-collapsed .sidebar-nav .nav-item::after { display: none; }
}

/* Phones */
@media (max-width: 640px) {
    .content { padding: 12px 10px 40px; }
    .page-title { font-size: 1.25rem; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; gap: 10px; }
    .stat-card .stat-icon { width: 36px; height: 36px; font-size: 1rem; }
    .stat-card .stat-value { font-size: 1.1rem; }
    .action-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .action-card { padding: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .header-brand .brand-sub { display: none; }
    .sign-in-btn span.signin-text { display: none; }
    .sign-in-btn { padding: 8px 10px; }
    /* Header: keep theme toggle and region badge fully visible on mobile */
    .top-header { padding: 0 10px; gap: 8px; }
    .header-actions { gap: 4px; flex-shrink: 0; }
    .theme-toggle {
        flex-shrink: 0;
        min-width: 38px;
        min-height: 38px;
        background: var(--surface-2);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-sm);
    }
    .theme-toggle:hover { background: var(--surface-3); border-color: var(--accent); }
    .theme-toggle svg { width: 18px; height: 18px; }
    .region-badge { display: none; }
    .header-brand .brand-name { font-size: 0.82rem; }
    /* Bigger touch targets */
    .btn { min-height: 42px; }
    .nav-item { padding: 11px 12px; }
    .data-table td, .data-table th { padding: 8px 8px; }
}

/* Small phones */
@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr; }
    .action-grid { grid-template-columns: 1fr; }
    .content { padding: 10px 8px 40px; }
    .page-title { font-size: 1.15rem; }
    .card { padding: 14px; }
    .header-brand .brand-name { font-size: 0.82rem; }
    .sidebar { width: 210px; }
    .nav-item { font-size: 0.8rem; padding: 9px 10px; }
    /* Buttons wrap text instead of clipping */
    .btn, .action-card .action-label { white-space: normal; }
}

/* Landscape phones (short height) */
@media (max-height: 500px) and (orientation: landscape) {
    .top-header { height: 44px; }
    .sidebar-header { height: 44px; }
    .content { padding-top: 10px; }
    .stat-card { padding: 10px; }
}

/* Touch devices: no hover-dependent tooltips needed */
@media (hover: none) {
    body.sidebar-collapsed .sidebar-nav .nav-item::after { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }


