/* Replacement module — light: cool slate layers; dark: deep navy panels (flat, no heavy shadows) */

:root {
    --rs-bg: #e8ecf4;
    --rs-surface: #ffffff;
    --rs-border: #c5cedd;
    --rs-radius: 7px;
    --rs-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --rs-text: #111827;
    --rs-muted: #556376;
    --rs-sidebar-bg: #dde5f2;
    --rs-sidebar-text: #1e293b;
    --rs-sidebar-muted: #5c6b82;
    --rs-topbar-bg: #e4eaf6;
    --rs-primary: #a84343;
    --rs-primary-hover: #8f3535;
    --rs-secondary-bg: #5d6778;
    --rs-secondary-hover: #4a5363;
    --rs-focus: #c41e3a;
    --rs-link-active-bg: #c2daf7;
    --rs-link-active-border: #7fa3d4;
    --rs-hover-bg: rgba(30, 58, 95, 0.09);
    --rs-hover-bg-strong: rgba(30, 58, 95, 0.13);
    --rs-backdrop: rgba(15, 23, 42, 0.4);
    color-scheme: light;
}

body.dark-mode {
    --rs-bg: #0c0d14;
    --rs-surface: #181b28;
    --rs-border: #343a52;
    --rs-text: #f0f2fa;
    --rs-muted: #9aa6c4;
    --rs-sidebar-bg: #12141f;
    --rs-sidebar-text: #e6e9f5;
    --rs-sidebar-muted: #8b95b5;
    --rs-topbar-bg: #141722;
    --rs-primary: #d96868;
    --rs-primary-hover: #e88484;
    --rs-secondary-bg: #5a6278;
    --rs-secondary-hover: #6f7894;
    --rs-focus: #5ecfff;
    --rs-link-active-bg: #2a3352;
    --rs-link-active-border: #5b6fa8;
    --rs-hover-bg: rgba(255, 255, 255, 0.07);
    --rs-hover-bg-strong: rgba(255, 255, 255, 0.11);
    --rs-backdrop: rgba(0, 0, 0, 0.62);
    color-scheme: dark;
}

body {
    font-family: var(--rs-font);
    margin: 0;
    padding: 0;
    background-color: var(--rs-bg);
    color: var(--rs-text);
    min-height: 100vh;
}

.app-layout {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.app-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--rs-sidebar-bg);
    color: var(--rs-sidebar-text);
    padding: 0 0 20px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
    min-height: 100vh;
    z-index: 50;
    border-right: 1px solid var(--rs-border);
    box-sizing: border-box;
    transition: width 0.2s ease, opacity 0.2s ease, padding 0.2s ease, border-color 0.2s ease;
}

body.sidebar-collapsed .app-sidebar {
    width: 0;
    min-width: 0;
    opacity: 0;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    border-right-width: 0;
    pointer-events: none;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 14px 16px;
    border-bottom: 1px solid var(--rs-border);
    margin-bottom: 6px;
}

.sidebar-brand-logo-wrap {
    flex-shrink: 0;
    width: 58px;
    height: 58px;
    border-radius: var(--rs-radius);
    overflow: hidden;
    border: 1px solid var(--rs-border);
    background: var(--rs-surface);
}

.sidebar-brand-logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.sidebar-brand-text {
    min-width: 0;
    flex: 1;
}

.sidebar-brand-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--rs-text);
    line-height: 1.25;
}

.sidebar-brand-sub {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--rs-sidebar-muted);
    margin-top: 4px;
}

.sidebar-section {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--rs-sidebar-muted);
    padding: 14px 18px 6px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 10px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--rs-radius);
    color: var(--rs-sidebar-text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    border: 1px solid transparent;
}

.sidebar-link:hover {
    background: var(--rs-hover-bg-strong);
    color: var(--rs-text);
}

.sidebar-link.active {
    background: var(--rs-link-active-bg);
    border-color: var(--rs-link-active-border);
    color: var(--rs-text);
    font-weight: 700;
}

.sidebar-link svg {
    flex-shrink: 0;
    opacity: 0.9;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: calc(100% - 20px);
    margin: 0 10px 6px;
    padding: 10px 12px;
    border-radius: var(--rs-radius);
    border: 1px solid var(--rs-border);
    background: var(--rs-surface);
    color: var(--rs-text);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sidebar-btn:hover {
    background: var(--rs-hover-bg);
    border-color: var(--rs-border);
}

.sidebar-btn--block {
    width: calc(100% - 20px);
    margin-left: 10px;
    margin-right: 10px;
}

body.dark-mode .sidebar-btn {
    background: var(--rs-surface);
    color: var(--rs-text);
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 10px 0;
}

#darkModeToggle .dm-label-on {
    display: none;
}

body.dark-mode #darkModeToggle .dm-label-off {
    display: none;
}

body.dark-mode #darkModeToggle .dm-label-on {
    display: inline;
}

.app-main {
    flex: 1;
    min-width: 0;
    padding: 0 22px 40px;
    background: var(--rs-bg);
}

.app-topbar {
    background: var(--rs-topbar-bg);
    border-bottom: 1px solid var(--rs-border);
    margin: 0 -22px 20px;
    padding: 0 22px;
    /* Stay above fixed sidebar (z-index 50) so the menu control always receives taps/clicks */
    position: sticky;
    top: 0;
    z-index: 60;
}

.app-topbar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
}

.app-page-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--rs-text);
    letter-spacing: -0.01em;
}

.app-topbar-spacer {
    flex: 1;
}

.app-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--rs-radius);
    border: 1px solid var(--rs-border);
    background: var(--rs-surface);
    color: var(--rs-text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    flex-shrink: 0;
}

.app-icon-btn:hover {
    background: var(--rs-hover-bg);
    border-color: var(--rs-border);
}

.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--rs-radius);
    border: 1px solid var(--rs-border);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    box-shadow: none;
    background: var(--rs-surface);
    color: var(--rs-text);
}

.app-btn:hover {
    background: var(--rs-hover-bg-strong);
}

.app-btn--primary {
    background: var(--rs-primary);
    border-color: var(--rs-primary);
    color: #fff;
}

.app-btn--primary:hover {
    background: var(--rs-primary-hover);
    border-color: var(--rs-primary-hover);
}

.app-btn--secondary {
    background: var(--rs-secondary-bg);
    border-color: var(--rs-secondary-bg);
    color: #fff;
}

.app-btn--secondary:hover {
    background: var(--rs-secondary-hover);
    border-color: var(--rs-secondary-hover);
}

.app-toolbar-back[hidden] {
    display: none;
}

/* Form controls inside replacement shell */
.app-main input[type="text"],
.app-main input[type="search"],
.app-main input[type="number"],
.app-main input[type="date"],
.app-main input[type="email"],
.app-main input[type="password"],
.app-main select,
.app-main textarea {
    font-family: inherit;
    font-size: 14px;
    padding: 10px 12px;
    border-radius: var(--rs-radius);
    border: 1px solid var(--rs-border);
    background: var(--rs-surface);
    color: var(--rs-text);
    box-shadow: none;
    outline: none;
    transition: border-color 0.15s;
}

.app-main input:focus,
.app-main select:focus,
.app-main textarea:focus {
    border-color: var(--rs-focus);
    box-shadow: none;
}

body.dark-mode .app-main input,
body.dark-mode .app-main select,
body.dark-mode .app-main textarea {
    background: var(--rs-surface);
    color: var(--rs-text);
    border-color: var(--rs-border);
}

.sr-only-triggers {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 900px) {
    body.sidebar-collapsed .app-sidebar {
        width: 260px;
        min-width: 260px;
        opacity: 1;
        padding: 0 0 20px;
        overflow: visible;
        pointer-events: auto;
        border-right-width: 1px;
    }

    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 100;
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: var(--rs-backdrop);
        z-index: 90;
        border: none;
        padding: 0;
        margin: 0;
    }

    .app-sidebar-backdrop.show {
        display: block;
    }

    .app-main {
        padding: 0 16px 32px;
    }

    .app-topbar {
        margin: 0 -16px 16px;
        padding: 0 16px;
        z-index: 110;
    }
}

/* Export data page */
.export-page-card {
    background: var(--rs-surface);
    border: 1px solid var(--rs-border);
    border-radius: var(--rs-radius);
    padding: 24px 26px 28px;
    max-width: 640px;
    box-shadow: none;
}

.export-lead {
    margin: 0 0 22px;
    color: var(--rs-muted);
    font-size: 0.95rem;
    line-height: 1.5;
}

.export-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 20px;
}

@media (max-width: 560px) {
    .export-form-grid {
        grid-template-columns: 1fr;
    }
}

.export-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--rs-muted);
    margin-bottom: 6px;
}

.export-field input[type="date"],
.export-field input[type="text"] {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--rs-border);
    border-radius: var(--rs-radius);
    background: var(--rs-surface);
    box-shadow: none;
}

.export-field input:focus {
    border-color: var(--rs-focus);
    outline: none;
}

.export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 26px;
    padding-top: 22px;
    border-top: 1px solid var(--rs-border);
}

.btn-export-excel,
.btn-export-pdf {
    padding: 10px 18px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    border-radius: var(--rs-radius);
    border: 1px solid var(--rs-border);
    box-shadow: none;
    transition: background 0.15s, border-color 0.15s;
}

.btn-export-excel {
    background: var(--rs-secondary-bg);
    border-color: var(--rs-secondary-bg);
    color: #fff;
}

.btn-export-excel:hover {
    background: var(--rs-secondary-hover);
    border-color: var(--rs-secondary-hover);
}

.btn-export-pdf {
    background: var(--rs-primary);
    border-color: var(--rs-primary);
    color: #fff;
}

.btn-export-pdf:hover {
    background: var(--rs-primary-hover);
    border-color: var(--rs-primary-hover);
}

/* --- Office work (embedded officework app) --- */
html.office-fullbleed {
    height: 100%;
}

html.office-fullbleed body {
    height: 100%;
    max-height: 100dvh;
    margin: 0;
    overflow: hidden;
}

html.office-fullbleed .app-layout {
    height: 100%;
    min-height: 0;
    width: 100%;
    align-items: stretch;
}

html.office-fullbleed .app-sidebar {
    align-self: stretch !important;
    min-height: 0;
    max-height: 100dvh;
    overflow-y: auto;
}

html.office-fullbleed .app-main.app-main--office {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 100dvh;
    padding: 0;
}

html.office-fullbleed .office-embed-shell {
    position: fixed;
    z-index: 5;
    top: 0;
    left: 260px;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    background: var(--rs-surface);
    transition: left 0.2s ease;
}

html.office-fullbleed body.sidebar-collapsed .office-embed-shell {
    left: 0;
}

.office-embed-frame {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    display: block;
}

html.office-fullbleed .office-helpers-details.office-helpers-pop {
    position: fixed;
    z-index: 25;
    left: 272px;
    right: auto;
    bottom: 14px;
    max-width: min(420px, calc(100vw - 288px));
    margin: 0;
    padding: 10px 12px;
    background: var(--rs-surface);
    border: 1px solid var(--rs-border);
    border-radius: var(--rs-radius);
    font-size: 0.82rem;
    color: var(--rs-muted);
    box-shadow: none;
    transition: left 0.2s ease;
}

html.office-fullbleed body.sidebar-collapsed .office-helpers-details.office-helpers-pop {
    left: 12px;
    max-width: min(420px, calc(100vw - 24px));
}

html.office-fullbleed .office-helpers-details summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--rs-text);
}

html.office-fullbleed .office-helpers-intro {
    margin: 10px 0 6px;
    font-size: 0.84rem;
    color: var(--rs-muted);
}

html.office-fullbleed .office-helpers-details .office-tools-list {
    margin: 0;
    padding-left: 1.15rem;
    color: var(--rs-muted);
    font-size: 0.82rem;
    line-height: 1.65;
}

html.office-fullbleed .office-tools-list code {
    font-size: 0.8rem;
    background: var(--rs-bg);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--rs-border);
}

@media (max-width: 900px) {
    html.office-fullbleed body {
        overflow: auto;
        max-height: none;
        height: auto;
        min-height: 100dvh;
    }

    html.office-fullbleed .office-embed-shell {
        left: 0;
        top: 56px;
        bottom: 0;
    }

    html.office-fullbleed .office-helpers-details.office-helpers-pop {
        left: 12px;
        right: 12px;
        max-width: none;
        bottom: 12px;
    }

    html.office-fullbleed .app-main.app-main--office {
        min-height: calc(100dvh - 56px);
    }
}

/* --- Wide data tables: horizontal scroll in main content (mobile + desktop narrow) --- */
.app-main .table-wrapper {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 900px) {
    .app-main .table-wrapper table {
        min-width: 560px;
    }
}

/**
 * Capacitor APK / native WebView — `replacement-native-app` is set on <html> and <body>
 * by replacement-shell.js (or login.php). Customize mobile layout here.
 */
html.replacement-native-app {
    /* Tweak density / brand without affecting desktop browser */
    --replacement-apk-font-bump: 0.02rem;
}

html.replacement-native-app body {
    font-size: calc(1rem + var(--replacement-apk-font-bump, 0rem));
}

html.replacement-native-app .app-topbar {
    padding-top: max(0px, env(safe-area-inset-top, 0px));
}

html.replacement-native-app .app-main {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-bottom: max(28px, env(safe-area-inset-bottom, 0px));
}

html.replacement-native-app .app-sidebar.open {
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
}

/* 16px+ inputs reduce unwanted zoom on focus in many mobile WebViews */
html.replacement-native-app .app-main input[type="text"],
html.replacement-native-app .app-main input[type="search"],
html.replacement-native-app .app-main input[type="number"],
html.replacement-native-app .app-main input[type="date"],
html.replacement-native-app .app-main input[type="email"],
html.replacement-native-app .app-main input[type="password"],
html.replacement-native-app .app-main select,
html.replacement-native-app .app-main textarea {
    font-size: 16px;
}

html.replacement-native-app .login-card input[type="text"],
html.replacement-native-app .login-card input[type="password"] {
    font-size: 16px;
}

html.replacement-native-app .app-icon-btn,
html.replacement-native-app .sidebar-link {
    min-height: 44px;
}

/* Login page (no app shell): respect notch / home indicator */
html.replacement-native-app body.replacement-login-page {
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
        max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
}

/* ShrInath Stock — browser print (e.g. stock entry) */
@media print {
    .app-sidebar,
    #appSidebar,
    .app-sidebar-backdrop,
    .app-topbar {
        display: none !important;
    }

    .app-layout {
        display: block !important;
    }

    .app-main {
        padding: 0 !important;
        margin: 0 !important;
        background: #fff !important;
    }
}
