/* LabDesk LIS - Unified Responsive Stylesheet
 *
 * One UI for all surfaces:
 *   - Web browser (online portal)
 *   - WebView2 desktop app (.exe)
 *   - Mobile browser (phone/tablet)
 *
 * Mobile-first: base styles target phones (<640px).
 * Media queries progressively enhance for tablet and desktop.
 * No CSS framework. Per AGENTS.md -4.
 */

/* === Reset === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* === Design tokens === */
:root {
    /* Colors */
    --c-primary: #1a5276;
    --c-primary-hover: #154360;
    --c-primary-light: #ebf5fb;
    --c-secondary: #5d6d7e;
    --c-success: #27ae60;
    --c-warning: #e67e22;
    --c-danger: #c0392b;
    --c-bg: #f0f3f5;
    --c-surface: #ffffff;
    --c-surface-alt: #f8f9fa;
    --c-text: #2c3e50;
    --c-text-muted: #7f8c8d;
    --c-text-light: #bdc3c7;
    --c-border: #d5d8dc;
    --c-focus: #3498db;
    --c-sidebar-bg: #1c2833;
    --c-sidebar-text: #bdc3c7;
    --c-sidebar-active: #1a5276;

    /* Spacing */
    --sp-xs: 4px;
    --sp-sm: 8px;
    --sp-md: 16px;
    --sp-lg: 24px;
    --sp-xl: 32px;

    /* Typography */
    --fs-xs: 12px;
    --fs-sm: 14px;
    --fs-base: 15px;
    --fs-md: 16px;
    --fs-lg: 18px;
    --fs-xl: 22px;
    --fs-2xl: 28px;

    /* Layout */
    --sidebar-w: 240px;
    --sidebar-w-collapsed: 56px;
    --topbar-h: 56px;
    --statusbar-h: 32px;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);

    /* Transitions */
    --t-fast: 0.15s ease;
    --t-normal: 0.25s ease;
}

/* === Base === */
html {
    font-size: var(--fs-base);
}

body {
    font-family: -apple-system, BlinkMacSystem-ont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    color: var(--c-text);
    background: var(--c-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === -ocus indicators (accessibility) === */
:focus-visible {
    outline: 3px solid var(--c-focus);
    outline-offset: 1px;
}

/* === App shell layout === */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* mobile dynamic viewport */
    overflow: hidden;
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === Top bar === */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
    padding: 0 var(--sp-sm);
    gap: var(--sp-xs);
    background: var(--c-primary);
    color: #fff;
    flex-shrink: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    min-width: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    flex-shrink: 1;
    min-width: 0;
    justify-content: flex-end;
}

/* Hamburger toggle - hidden on desktop */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--t-fast);
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,0.15);
}

.topbar-logo {
    font-size: var(--fs-lg);
    font-weight: 700;
    white-space: nowrap;
}

.topbar-user {
    font-size: var(--fs-sm);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-w);
    background: var(--c-sidebar-bg);
    color: var(--c-sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--t-normal), transform var(--t-normal);
    z-index: 90;
}

.sidebar-nav {
    list-style: none;
    padding: var(--sp-sm) 0;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: var(--sp-sm) var(--sp-md);
    color: var(--c-sidebar-text);
    text-decoration: none;
    font-size: var(--fs-sm);
    white-space: nowrap;
    border-left: 3px solid transparent;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
    cursor: pointer;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-link.active {
    background: var(--c-sidebar-active);
    color: #fff;
    border-left-color: var(--c-focus);
    font-weight: 600;
}

.sidebar-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.sidebar-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Collapsed sidebar (desktop) === */
/* When .sidebar has .collapsed class, shrink to icon-only width */
.sidebar.collapsed {
    width: var(--sidebar-w-collapsed);
    overflow-x: clip;
}

.sidebar.collapsed .sidebar-label {
    display: none;
}

.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: var(--sp-sm) 0;
    border-left: none;
    border-right: 3px solid transparent;
}

.sidebar.collapsed .sidebar-link.active {
    border-right-color: var(--c-focus);
}

.sidebar.collapsed .sidebar-link:hover .sidebar-icon,
.sidebar.collapsed .sidebar-link.active .sidebar-icon {
    opacity: 1;
}

/* Tooltip on hover when collapsed - shows the label name */
.sidebar.collapsed .sidebar-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(var(--sidebar-w-collapsed) + 4px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--c-sidebar-bg);
    color: #fff;
    padding: var(--sp-xs) var(--sp-sm);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-fast);
    z-index: 200;
    box-shadow: var(--shadow);
}

.sidebar.collapsed .sidebar-link:hover::after {
    opacity: 1;
}

/* Make sidebar-link positioned for tooltip */
.sidebar-link {
    position: relative;
}

/* === Main content area === */
.main-area {
    flex: 1;
    /* overflow: auto on both axes - this is the SOLE scroll container for
       the content area. position:sticky on table headers (top:0) sticks to
       the top of this element regardless of table size. */
    overflow: auto;
    padding: var(--sp-md);
    -webkit-overflow-scrolling: touch;
}

/* === Status bar === */
.statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--statusbar-h);
    padding: 0 var(--sp-md);
    background: var(--c-sidebar-bg);
    color: var(--c-text-light);
    font-size: var(--fs-xs);
    flex-shrink: 0;
    z-index: 80;
}

.statusbar-left, .statusbar-right {
    display: flex;
    align-items: center;
    gap: var(--sp-md);
}

/* === Connectivity indicator === */
.conn-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-xs);
}

.conn-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.conn-dot.online { background: var(--c-success); }
.conn-dot.offline { background: var(--c-danger); }
.conn-dot.syncing { background: var(--c-warning); animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === Overlay (mobile sidebar backdrop) === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 85;
}

.sidebar-overlay.visible {
    display: block;
}

/* === Views === */
.view { display: none; }
.view.active { display: block; }

.view-header {
    margin-bottom: var(--sp-md);
}

.view-title {
    font-size: var(--fs-xl);
    color: var(--c-text);
}

.view-subtitle {
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
    margin-top: var(--sp-xs);
}

/* === Cards === */
.card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--sp-md);
    margin-bottom: var(--sp-md);
}

.card-title {
    font-size: var(--fs-md);
    color: var(--c-primary);
    margin-bottom: var(--sp-sm);
    font-weight: 600;
}

.card-text {
    font-size: var(--fs-sm);
    color: var(--c-text);
    margin-bottom: var(--sp-sm);
    line-height: 1.6;
}

