/* M360 shared color themes. Loaded after all page-level styles. */
html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1210;
    --bg-alt: #111a17;
    --card: #111a17;
    --text: #eef5f1;
    --muted: #a8b5ae;
    --border-subtle: #2d3a35;
    --shadow-soft: 0 14px 35px rgba(0, 0, 0, .32);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .page-shell,
html[data-theme="dark"] main,
html[data-theme="dark"] .content {
    background: #0b1210 !important;
    color: #eef5f1 !important;
}

html[data-theme="dark"] header,
html[data-theme="dark"] footer {
    border-color: #2d3a35 !important;
    background: rgba(11, 18, 16, .96) !important;
    color: #eef5f1 !important;
}

html[data-theme="dark"] .preloader-overlay {
    background: rgba(11, 18, 16, .94) !important;
}

html[data-theme="dark"] .nav-island {
    border: 1px solid #2f6b55;
    background: #102a21 !important;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .35) !important;
}

html[data-theme="dark"] .nav-dashboard-link,
html[data-theme="dark"] .nav-login-icon {
    color: #e7f7ef !important;
}

html[data-theme="dark"] .nav-login-icon {
    border-color: #4b695d !important;
    background: #163b2e !important;
}

html[data-theme="dark"] .nav-login-icon:hover,
html[data-theme="dark"] .nav-login-icon.active,
html[data-theme="dark"] .nav-dashboard-link:hover {
    border-color: #34d399 !important;
    background: #047857 !important;
}

html[data-theme="dark"] .theme-toggle {
    cursor: pointer;
}

html[data-theme="dark"] .footer-inner,
html[data-theme="dark"] .footer-inner a {
    color: #a8b5ae !important;
}

/* Shared surfaces */
html[data-theme="dark"] :is(
    .panel, .card, .ph-card, .ph-top, .ph-panel, .admin-card, .account-panel,
    .login-card, .password-card, .invoice-form-container, .invoice-list-container,
    .invoice-table-wrapper, .invoice-container, .pos-container, .scan-card,
    .package-card, .hero-section, .packages-section, .contact-section, .content-box,
    .summary-item, .stat-card, .stat-box, .ph-stat, .pos-metric, .modal-card,
    .choice-card, .staff-entry, .profile-fact, .settings-profile-card,
    .settings-section, .stock-browser, .report-card, .report-body, .table-wrapper,
    .table-wrap, .data-table-wrap, .account-header, .scanned-item, .scanned-items,
    .form-section, .section-content, .invoice-body, .invoice-header, .invoice-info,
    .payment-section, .payment-verification, .notes-section, .totals-section,
    .history-note, .renewal-form, .invoice-detail-container, .invoice-card-body,
    .invoice-card-header, .report-block, .stock-section, .stock-path, .check-card,
    .bulk-item-row, .permission-option, .audit-row, .settings-profile, .generated-id-note
) {
    border-color: #2d3a35 !important;
    background: #111a17 !important;
    background-image: none !important;
    color: #eef5f1 !important;
    box-shadow: 0 10px 26px rgba(0, 0, 0, .22) !important;
}

html[data-theme="dark"] :is(
    .panel-title, .admin-title, .owner-title, .page-title, .pos-title,
    .scan-card-title, .modal-title, .ph-title, .card-title, .perf-title,
    .account-info h1, .business-name, .summary-value, .stat-value,
    .ph-stat strong, .pos-metric strong, .report-title, .invoice-number,
    .form-section-title, .section-title, .invoice-card-title, .invoice-card-number,
    .total-amount, .total-display, h1, h2, h3, h4
) {
    color: #f3faf6 !important;
}

html[data-theme="dark"] .medicine-name {
    color: #ffffff !important;
}

html[data-theme="dark"] :is(
    p, .muted, .owner-subtitle, .ph-sub, .account-code, .summary-label,
    .stat-label, .field-help, .help-text, .empty-state, .row-count,
    .workspace-brand-copy span, .audit-row span, small
) {
    color: #a8b5ae !important;
}

html[data-theme="dark"] a:not(.workspace-action):not(.workspace-tool):not(.nav-login-icon):not(.nav-dashboard-link):not(.btn-primary):not(.btn-create):not(.btn-gradient):not(.command-button):not(.segment) {
    color: #6ee7b7;
}

/* Forms */
html[data-theme="dark"] :is(
    input[type="text"], input[type="password"], input[type="email"],
    input[type="number"], input[type="date"], input[type="month"],
    input[type="search"], input[type="tel"], input[type="file"],
    select, textarea, .field-group input, .field-group select,
    .field-group textarea, .form-group input, .form-group textarea
) {
    border-color: #405149 !important;
    background: #0e1714 !important;
    color: #eef5f1 !important;
    box-shadow: none !important;
}

html[data-theme="dark"] :is(input, select, textarea)::placeholder {
    color: #78877f !important;
    opacity: 1;
}

html[data-theme="dark"] :is(input, select, textarea):focus {
    border-color: #34d399 !important;
    background: #101d19 !important;
    box-shadow: 0 0 0 3px rgba(52, 211, 153, .16) !important;
    outline: none;
}

html[data-theme="dark"] :is(label, .field-group label, .form-label, .filter-label, .choice-heading) {
    color: #c5d2cb !important;
}

html[data-theme="dark"] input[type="checkbox"],
html[data-theme="dark"] input[type="radio"] {
    accent-color: #10b981;
}

html[data-theme="dark"] input:-webkit-autofill {
    -webkit-text-fill-color: #eef5f1;
    box-shadow: 0 0 0 1000px #0e1714 inset !important;
}

/* Tables and data lists */
html[data-theme="dark"] :is(
    table, .table, .ph-table, .admin-table, .account-table,
    .invoice-table, .items-table
) {
    background: #111a17 !important;
    color: #e5eee9 !important;
}

html[data-theme="dark"] :is(
    .table th, .ph-table th, .admin-table th, .account-table th,
    .invoice-table th, .items-table th
) {
    border-color: #33433c !important;
    background: #17241f !important;
    color: #9fd6bd !important;
}

html[data-theme="dark"] :is(
    .table td, .ph-table td, .admin-table td, .account-table td,
    .invoice-table td, .items-table td
) {
    border-color: #27352f !important;
    background: transparent !important;
    color: #dbe7e0 !important;
}

html[data-theme="dark"] tbody tr:hover,
html[data-theme="dark"] .staff-entry summary:hover {
    background: #16231e !important;
}

html[data-theme="dark"] .staff-entry summary,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .card-head,
html[data-theme="dark"] .ph-card-header,
html[data-theme="dark"] .report-head {
    border-color: #2d3a35 !important;
    background: #15211d !important;
    color: #eef5f1 !important;
}

/* Pharmacy workspace */
html[data-theme="dark"] .pharmacy-workspace-header,
html[data-theme="dark"] .pharmacy-workspace-nav {
    border-color: #2d3a35 !important;
    background: #0e1714 !important;
}

html[data-theme="dark"] .workspace-brand-copy strong {
    color: #f3faf6 !important;
}

html[data-theme="dark"] .workspace-brand-copy small {
    color: #6ee7b7 !important;
}

html[data-theme="dark"] .workspace-brand-logo,
html[data-theme="dark"] .settings-profile-logo,
html[data-theme="dark"] .logo-preview {
    border-color: #2f6b55 !important;
    background: #15251f !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] .workspace-action,
html[data-theme="dark"] .workspace-tool,
html[data-theme="dark"] .ph-btn,
html[data-theme="dark"] .btn-chip,
html[data-theme="dark"] .btn-outline,
html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .btn-scan,
html[data-theme="dark"] .edit-button,
html[data-theme="dark"] .password-toggle,
html[data-theme="dark"] .close-btn,
html[data-theme="dark"] .modal-close {
    border-color: #405149 !important;
    background: #15211d !important;
    color: #dce8e1 !important;
    box-shadow: none !important;
}

html[data-theme="dark"] :is(
    .btn-action, .btn-add-item, .btn-delete, .btn-download, .btn-payment,
    .btn-remove, .btn-remove-item, .btn-submit, .btn-view, .back-link,
    .filter-pill, .role-option
) {
    border-color: #405149 !important;
    background: #15211d !important;
    color: #dce8e1 !important;
    box-shadow: none !important;
}

html[data-theme="dark"] :is(
    .btn-action, .btn-add-item, .btn-download, .btn-payment, .btn-submit, .btn-view
):hover {
    border-color: #34d399 !important;
    background: #1b3028 !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] :is(.btn-delete, .btn-remove, .btn-remove-item, .bulk-remove, .delete-button) {
    border-color: #7f1d1d !important;
    background: #351718 !important;
    color: #fecaca !important;
}

html[data-theme="dark"] .workspace-action:hover,
html[data-theme="dark"] .workspace-tool:hover,
html[data-theme="dark"] .ph-btn:hover,
html[data-theme="dark"] .btn-chip:hover,
html[data-theme="dark"] .btn-outline:hover,
html[data-theme="dark"] .btn-secondary:hover,
html[data-theme="dark"] .btn-scan:hover {
    border-color: #34d399 !important;
    background: #1b3028 !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] .workspace-action.active,
html[data-theme="dark"] .segment.active,
html[data-theme="dark"] .tab-btn.active,
html[data-theme="dark"] .command-button.primary,
html[data-theme="dark"] .primary-action,
html[data-theme="dark"] .btn-primary,
html[data-theme="dark"] .btn-create {
    border-color: #10b981 !important;
    background: #047857 !important;
    color: #fff !important;
}

html[data-theme="dark"] .workspace-action.command {
    border-color: #2f6b55 !important;
    background: #143d2e !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] .workspace-tools,
html[data-theme="dark"] .dashboard-nav,
html[data-theme="dark"] .segmented,
html[data-theme="dark"] .filter-bar,
html[data-theme="dark"] .download-box {
    border-color: #2d3a35 !important;
}

html[data-theme="dark"] .dashboard-nav,
html[data-theme="dark"] .segmented,
html[data-theme="dark"] .download-box {
    background: #101a16 !important;
}

html[data-theme="dark"] .download-box strong {
    color: #f8fafc !important;
}

html[data-theme="dark"] .download-actions .ph-btn {
    border-color: #2f6b55 !important;
    background: #143d2e !important;
    color: #d1fae5 !important;
}

html[data-theme="dark"] .download-actions .ph-btn:hover,
html[data-theme="dark"] .download-actions .ph-btn:focus-visible {
    border-color: #6ee7b7 !important;
    background: #065f46 !important;
    color: #fff !important;
}

html[data-theme="dark"] .dashboard-nav a,
html[data-theme="dark"] .segment,
html[data-theme="dark"] .tab-btn {
    color: #a8b5ae !important;
}

html[data-theme="dark"] .dashboard-nav a.active,
html[data-theme="dark"] .dashboard-nav a:hover,
html[data-theme="dark"] .segment:hover,
html[data-theme="dark"] .tab-btn:hover {
    color: #a7f3d0 !important;
}

/* Home, authentication, legal, console and invoice screens */
html[data-theme="dark"] :is(.home-container, .login-wrapper, .legal-shell, .owner-console) {
    color: #eef5f1 !important;
}

html[data-theme="dark"] .hero-section,
html[data-theme="dark"] .packages-section,
html[data-theme="dark"] .package-card {
    border-color: #2d3a35 !important;
    background: #111a17 !important;
    background-image: none !important;
}

html[data-theme="dark"] .legal-hero,
html[data-theme="dark"] .legal-layout,
html[data-theme="dark"] .legal-content,
html[data-theme="dark"] .legal-toc {
    border-color: #2d3a35 !important;
    background: transparent !important;
    color: #dbe7e0 !important;
}

html[data-theme="dark"] .legal-content section {
    border-color: #2d3a35 !important;
}

html[data-theme="dark"] .choice-input:checked + .choice-card {
    border-color: #34d399 !important;
    background: #143d2e !important;
}

html[data-theme="dark"] :is(
    .password-card-header, .reset-icon, .legal-callout, .settings-profile,
    .generated-id-note, .report-metric, .report-footer, .pos-clinical-summary
) {
    border-color: #2f6b55 !important;
    background: #143d2e !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] :is(.stock-path.selected, .check-card:hover, .filter-pill.active, .role-option.selected) {
    border-color: #34d399 !important;
    background: #17392c !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] .report-block h3 {
    border-color: #2d3a35 !important;
    background: #17241f !important;
    color: #c5d2cb !important;
}

html[data-theme="dark"] .report-net,
html[data-theme="dark"] .pos-total {
    background: #064e3b !important;
    color: #fff !important;
}

html[data-theme="dark"] .hero-logo img,
html[data-theme="dark"] .report-logo {
    background: #fff !important;
}

html[data-theme="dark"] .invoice-summary,
html[data-theme="dark"] .invoice-totals,
html[data-theme="dark"] .invoice-card,
html[data-theme="dark"] .mobile-invoice-card,
html[data-theme="dark"] .customer-info,
html[data-theme="dark"] .company-info {
    border-color: #2d3a35 !important;
    background: #111a17 !important;
    color: #e5eee9 !important;
}

/* Semantic states retain meaning and contrast. */
html[data-theme="dark"] :is(.msg, .notice, .alert-card, .settings-intro, .role-guide, .pos-clinical-summary) {
    box-shadow: none !important;
}

html[data-theme="dark"] :is(.msg.success, .notice.success, .alert-card.success) {
    border-color: #166534 !important;
    background: #0f2f22 !important;
    color: #a7f3d0 !important;
}

html[data-theme="dark"] :is(.msg.error, .notice.error, .alert-card.danger, .pill.bad) {
    border-color: #7f1d1d !important;
    background: #351718 !important;
    color: #fecaca !important;
}

html[data-theme="dark"] :is(.msg.warning, .notice.warning, .alert-card.warning, .pill.warn, .prescription-panel) {
    border-color: #854d0e !important;
    background: #322610 !important;
    color: #fde68a !important;
}

html[data-theme="dark"] :is(.msg, .notice, .alert-card.info, .settings-intro, .role-guide) {
    border-color: #1d4f6d !important;
    background: #102735 !important;
    color: #bae6fd !important;
}

html[data-theme="dark"] :is(.badge, .pill, .chip, .status, .dashboard-nav .nav-count) {
    border-color: #405149 !important;
}

html[data-theme="dark"] .chip,
html[data-theme="dark"] .badge:not(.pharmacy):not(.retail):not(.basic):not(.premium),
html[data-theme="dark"] .pill:not(.warn):not(.bad) {
    background: #1a2822 !important;
    color: #c6d5cd !important;
}

html[data-theme="dark"] .modal-backdrop {
    background: rgba(0, 0, 0, .72) !important;
}

html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:white"],
html[data-theme="dark"] [style*="background: white"] {
    border-color: #2d3a35 !important;
    background: #111a17 !important;
    color: #eef5f1 !important;
}

html[data-theme="dark"] [style*="color: #64748b"],
html[data-theme="dark"] [style*="color:#64748b"] {
    color: #a8b5ae !important;
}

html[data-theme="dark"] ::selection {
    background: #047857;
    color: #fff;
}

@media (max-width: 760px) {
    html[data-theme="dark"] .modal-header {
        background: #111a17 !important;
    }
}

@media print {
    html[data-theme="dark"] {
        color-scheme: light;
    }

    html[data-theme="dark"] body,
    html[data-theme="dark"] main,
    html[data-theme="dark"] .content,
    html[data-theme="dark"] .invoice-container,
    html[data-theme="dark"] .report-card {
        background: #fff !important;
        color: #111827 !important;
    }
}
