/* Visual bridge to the OA shell. Scope the overrides so ERPNext forms keep their layout. */
:root {
  --mixiya-primary: #1890ff;
  --mixiya-primary-hover: #0877df;
  --mixiya-surface: #fff;
  --mixiya-background: #f0f5ff;
  --mixiya-border: #e4ebf5;
  --mixiya-text: #243247;
  --mixiya-muted: #6e7e95;
  --mixiya-font: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

/* The stock login and the bridge's permission page share the OA login frame. */
body.mixiya-auth-page {
  min-height: 100vh;
  background: var(--mixiya-background) !important;
  color: var(--mixiya-text);
  font-family: var(--mixiya-font);
}

.mixiya-auth-banner {
  position: absolute;
  z-index: 1;
  inset: 0 0 auto;
  min-height: 220px;
  height: 40vh;
  background: linear-gradient(120deg, #0757d9 0%, #087cde 60%, #12b6be 100%);
  color: #fff;
}

.mixiya-auth-brand {
  width: min(1070px, calc(100% - 80px));
  margin: 36px auto 0;
}

.mixiya-auth-identity { display: flex; align-items: center; gap: 14px; }
.mixiya-auth-identity img { display: block; border-radius: 12px; }
.mixiya-auth-name { font-size: 30px; font-weight: 600; letter-spacing: 3px; }
.mixiya-auth-edition { padding: 3px 8px; border: 1px solid rgb(255 255 255 / 60%); border-radius: 4px; font-size: 12px; }
.mixiya-auth-slogan { margin: 18px 0 0; font-size: 28px; font-weight: 600; line-height: 1.4; }
.mixiya-auth-description { margin: 10px 0 0; color: rgb(255 255 255 / 85%); font-size: 15px; }

body.mixiya-auth-page #page-login,
body.mixiya-auth-page #page-erpnext-access {
  position: relative;
  min-height: 100vh;
  background: transparent;
}

body.mixiya-auth-page #page-login .page-content-wrapper,
body.mixiya-auth-page #page-erpnext-access .page-content-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 160px 24px 80px;
}

body.mixiya-auth-page #page-login main.container,
body.mixiya-auth-page #page-erpnext-access main.container {
  width: min(424px, 100%);
  max-width: none;
  margin: 0;
  padding: 0;
}

body.mixiya-auth-page #page-login .page-card,
body.mixiya-auth-page .erpnext-access-card {
  position: relative;
  z-index: 2;
  width: 100%;
  margin: 0;
  padding: 36px 40px 32px;
  border: 1px solid var(--mixiya-border);
  border-radius: 12px;
  background: var(--mixiya-surface);
  box-shadow: 0 2px 32px rgb(0 18 107 / 8%);
}

body.mixiya-auth-page #page-login .page-card-head { gap: 12px; }
body.mixiya-auth-page #page-login .app-logo { display: none; }
body.mixiya-auth-page #page-login .page-card-head h4 {
  color: var(--mixiya-primary);
  font-family: var(--mixiya-font);
  font-size: 18px;
  font-weight: 600;
}
body.mixiya-auth-page #page-login .page-card-subtitle,
body.mixiya-auth-page #page-login label,
body.mixiya-auth-page .erpnext-access-card p { color: var(--mixiya-muted); }
body.mixiya-auth-page #page-login .form-control {
  min-height: 36px;
  border: 1px solid #d9e1ed;
  border-radius: 4px;
  background: #fff;
  font-family: var(--mixiya-font);
}
body.mixiya-auth-page #page-login .form-control:focus {
  border-color: var(--mixiya-primary);
  box-shadow: 0 0 0 2px rgb(24 144 255 / 12%);
}
body.mixiya-auth-page #page-login .es-button[data-variant="solid"] {
  border: 1px solid var(--mixiya-primary);
  border-radius: 4px;
  background: var(--mixiya-primary);
  color: #fff;
  font-family: var(--mixiya-font);
  font-weight: 600;
}
body.mixiya-auth-page #page-login .es-button[data-variant="solid"]:hover { background: var(--mixiya-primary-hover); }
body.mixiya-auth-page #page-login .btn-login-option { background: #edf5ff; color: #2377d5; }
body.mixiya-auth-page #page-login a:hover { color: var(--mixiya-primary); }

body.mixiya-auth-page .erpnext-access-card { max-width: none; }
body.mixiya-auth-page .erpnext-access-icon { background: #eaf3ff; color: var(--mixiya-primary); }
body.mixiya-auth-page .erpnext-access-card h1 { color: var(--mixiya-text); font-family: var(--mixiya-font); }

/* Desk: align its chrome and business surfaces while retaining Frappe controls. */
body.desktop-page {
  --primary: var(--mixiya-primary);
  --desk-sidebar-bg: #fff;
  background: var(--mixiya-background);
  color: var(--mixiya-text);
  font-family: var(--mixiya-font);
}
body.desktop-page .desktop-navbar {
  border-bottom: 1px solid var(--mixiya-border);
  background: #edf5ff;
  font-family: var(--mixiya-font);
}
body.desktop-page .body-sidebar-container { border-right: 1px solid var(--mixiya-border); background: #fff; }
body.desktop-page #desk-dock { border-right: 1px solid var(--mixiya-border); background: #fff; }
/* Hide Frappe's technical dock while the business dock is being initialized. */
body.desktop-page #desk-dock:not(.mixiya-business-dock-ready) .dock-items { visibility: hidden; }
body.desktop-page .desktop-navbar #brand-logo,
body.desktop-page #desk-dock .dock-logo .header-logo img,
body.desktop-page .desktop-icon .app-icon {
  content: url("/assets/mixiya_oa_bridge/images/mixiya-logo.png");
  object-fit: cover;
  border-radius: 8px;
}
body.desktop-page .desktop-navbar #brand-logo { width: 32px; height: 32px; }
body.desktop-page #desk-dock .dock-logo .header-logo img { width: 32px; height: 32px; }
body.desktop-page #desk-dock .dock-logo .header-title { color: var(--mixiya-text); }
/* Notification preferences are managed centrally; keep the user-facing drawer focused on messages. */
body.desktop-page .notification-settings { display: none !important; }
/* Keep Frappe's unread visibility and count updates; render the bell indicator in OA red. */
body.desktop-page #desk-dock .sidebar-notification .notification-count,
body.desktop-page .desktop-notification-icon .notification-count:not(.es-badge) {
  background-color: #f56c6c;
}
body.desktop-page #desk-dock .dock-item.active,
body.desktop-page .body-sidebar .sidebar-item.active,
body.desktop-page .body-sidebar .sidebar-item.selected {
  border-radius: 8px;
  background: #eaf4ff;
  color: var(--mixiya-primary);
}
/* Hide the system-settings shortcut in the Settings sidebar. */
body.desktop-page .body-sidebar .sidebar-item-container:has(
  > .standard-sidebar-item > a.item-anchor[data-link-type="DocType"][href*="/system-settings/"]
) { display: none !important; }
/* Match the OA module rail: a visible name under each icon, with a blue active state. */
@media (min-width: 768px) {
  body.desktop-page {
    /* OA's two-level navigation is 76px + 204px. Keep the combined width stable. */
    --dock-width: 76px;
    --dock-tile: 64px;
    --sidebar-width: 204px;
  }
  body.desktop-page #desk-dock {
    padding: 8px 6px 12px;
    gap: 4px;
    box-shadow: none;
  }
  body.desktop-page #desk-dock .dock-logo {
    height: 64px;
    margin-top: -8px;
    border-bottom: none;
  }
  body.desktop-page #desk-dock .dock-logo .shell-header {
    width: 48px;
    height: 48px;
  }
  body.desktop-page #desk-dock .dock-logo .header-logo img { width: 44px; height: 44px; }
  body.desktop-page #desk-dock .dock-utilities {
    gap: 2px;
    margin: 0 0 4px;
    padding: 0 0 4px;
  }
  body.desktop-page #desk-dock .dock-items {
    gap: 2px;
  }
  body.desktop-page.dock-pinned #desk-dock .dock-items {
    width: 100%;
    margin-inline: 0;
    padding-block: 0;
  }
  body.desktop-page #desk-dock .dock-item {
    width: 64px;
    height: 62px;
    flex-direction: column;
    gap: 4px;
    color: #303133;
    font-size: 13px;
    line-height: 1.2;
  }
  body.desktop-page #desk-dock .dock-item:hover,
  body.desktop-page #desk-dock .dock-item:focus-visible {
    background: #eef6ff;
    color: var(--mixiya-primary);
  }
  body.desktop-page #desk-dock .dock-item.active {
    background: #eaf4ff;
    color: var(--mixiya-primary);
    font-weight: 600;
    box-shadow: none;
  }
  body.desktop-page #desk-dock .dock-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 24px;
  }
  body.desktop-page #desk-dock .dock-item-icon svg { width: 22px; height: 22px; }
  body.desktop-page #desk-dock .dock-item-label {
    display: block;
    max-width: 62px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body.desktop-page #desk-dock .dock-utilities .dock-item { height: 52px; }
  body.desktop-page #desk-dock .navbar-modal-search-mobile::after { content: "搜索"; }
  body.desktop-page #desk-dock .sidebar-notification::after { content: "通知"; }
  body.desktop-page #desk-dock .dock-utilities .dock-item::after { font-size: 12px; }
  body.desktop-page #desk-dock .dock-user-button { width: 48px; height: 48px; }

  body.desktop-page .body-sidebar .body-sidebar-top { padding: 8px 8px 24px; }
  body.desktop-page .body-sidebar .standard-sidebar-item { margin-bottom: 1px; padding: 0; }
  body.desktop-page .body-sidebar .standard-sidebar-item .item-anchor {
    height: 42px;
    padding: 0 10px;
    color: #303133;
    border-radius: 8px;
  }
  body.desktop-page .body-sidebar .standard-sidebar-item .sidebar-item-label { font-size: 13px; }
  body.desktop-page .body-sidebar .standard-sidebar-item:hover .item-anchor { background: #f2f7fc; }
  body.desktop-page .body-sidebar .standard-sidebar-item.active-sidebar .item-anchor,
  body.desktop-page .body-sidebar .standard-sidebar-item.selected .item-anchor {
    background: #eaf4ff;
    color: var(--mixiya-primary);
    font-weight: 600;
  }
}
body.desktop-page .main-section,
body.desktop-page .main-section #body { background: var(--mixiya-background); }
body.desktop-page .page-container {
  margin: 14px;
  border: 1px solid var(--mixiya-border);
  border-radius: 10px;
  background: #fff;
  color: var(--mixiya-text);
  font-family: var(--mixiya-font);
  /* Link suggestions and date/select menus must extend past short form cards. */
  overflow: visible;
}
/* Workspace home pages keep their header fixed and scroll the dashboard below it. */
body.desktop-page .page-container[data-page-route="Workspaces"] .page-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
body.desktop-page .page-container[data-page-route="Workspaces"] > .page-head .page-icon-group {
  display: none !important;
}
body.desktop-page .page-container[data-page-route^="List/"] .page-head .view-switcher,
body.desktop-page .page-container[data-page-route^="List/"] .filter-section .restricted-button {
  display: none !important;
}
body.desktop-page .page-head { border-color: var(--mixiya-border); }
body.desktop-page .page-head .page-title { color: var(--mixiya-text); }
/* Lead fields share a row grid while their original controls stay attached to
   Frappe's columns. Hidden controls and empty address/contact HTML take no space. */
body.desktop-page .mixiya-lead-compact > .section-body:not(.hide) {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--margin-lg);
  align-items: start;
  padding-inline: var(--padding-md);
}
body.desktop-page .mixiya-lead-compact > .section-body > .form-column:not(.hide-control),
body.desktop-page .mixiya-lead-compact > .section-body > .form-column:not(.hide-control) > form {
  display: contents;
}
body.desktop-page .mixiya-lead-compact > .section-body > .form-column > form > .frappe-control {
  min-width: 0;
  max-width: none;
}
body.desktop-page .mixiya-lead-compact > .section-body > .form-column > form > .frappe-control[data-fieldtype="HTML"]:empty {
  display: none;
}
/* Address and contact cards can be taller than an input. Keep city/state
   together in their column so a card cannot push state into the next row. */
body.desktop-page .mixiya-lead-compact[data-fieldname="address_section"] > .section-body > .form-column:not(.hide-control),
body.desktop-page .mixiya-lead-compact[data-fieldname="address_section"] > .section-body > .form-column:not(.hide-control) > form {
  display: block;
}
body.desktop-page .mixiya-lead-compact[data-fieldname="address_section"] > .section-body > .form-column {
  min-width: 0;
  width: 100%;
  max-width: none;
  padding-inline: 0;
}
body.desktop-page .mixiya-lead-compact[data-fieldname="address_section"] > .section-body > .form-column:has(> form > .frappe-control[data-fieldtype="HTML"]:empty) {
  display: none;
}
@media (max-width: 767px) {
  body.desktop-page .mixiya-lead-compact > .section-body:not(.hide) {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* Compact ordinary input sections throughout the Desk. Frappe's hidden
   controls remain in the form model but take no layout space. */
body.desktop-page .mixiya-form-compact > .section-body:not(.hide) {
  display: grid;
  grid-template-columns: repeat(var(--mixiya-compact-cols, 3), minmax(0, 1fr));
  column-gap: var(--margin-lg);
  align-items: start;
  padding-inline: var(--padding-md);
}
body.desktop-page .mixiya-form-compact > .section-body > .form-column:not(.hide-control),
body.desktop-page .mixiya-form-compact > .section-body > .form-column:not(.hide-control) > form {
  display: contents;
}
body.desktop-page .mixiya-form-compact > .section-body > .form-column > form > .frappe-control {
  min-width: 0;
  max-width: none;
}
@media (max-width: 767px) {
  body.desktop-page .mixiya-form-compact > .section-body:not(.hide) {
    grid-template-columns: minmax(0, 1fr);
  }
}
body.desktop-page .mixiya-invoice-address-empty {
  display: none !important;
}
body.desktop-page .btn-primary,
body.desktop-page .primary-action {
  border-color: var(--mixiya-primary);
  background: var(--mixiya-primary);
  color: #fff;
}
body.desktop-page .btn-primary:hover,
body.desktop-page .primary-action:hover { border-color: var(--mixiya-primary-hover); background: var(--mixiya-primary-hover); }
body.desktop-page .list-row-head,
body.desktop-page .list-row-container.list-row-head,
body.desktop-page .list-header { background: #f1f8ff; }
body.desktop-page .list-row-container { border-color: var(--mixiya-border); }
body.desktop-page .list-row-container:hover { background: #f8fbff; }
body.desktop-page .list-row-container a,
body.desktop-page .list-row-container .level-item a { color: var(--mixiya-primary); }
body.desktop-page .list-row-head > .mixiya-list-operation-header,
body.desktop-page .list-row > .mixiya-list-operation-row {
  flex: 0 0 92px;
  width: 92px;
  justify-content: center;
  text-align: center;
}
body.desktop-page .mixiya-list-operation-header .list-count,
body.desktop-page .mixiya-list-operation-header .list-liked-by-me,
body.desktop-page .mixiya-list-operation-row .list-row-activity { display: none !important; }
body.desktop-page .mixiya-list-operation-label { font-weight: 600; color: var(--mixiya-text); }
body.desktop-page .mixiya-list-view-link {
  color: var(--mixiya-primary) !important;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
body.desktop-page .mixiya-list-view-link:hover,
body.desktop-page .mixiya-list-view-link:focus-visible {
  color: var(--mixiya-primary-hover) !important;
  text-decoration: underline;
}
/* Frappe DataTable sizes report rows from the sum of fixed column widths.
   Expand accounting report rows to the available panel width, while retaining
   horizontal scrolling when a report genuinely has too many columns. */
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-scrollable {
  width: 100% !important;
  scrollbar-gutter: stable;
}
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-row {
  width: 100% !important;
}
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-header .dt-row {
  width: calc(100% - 10px) !important;
}
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-row .dt-cell:not(.dt-cell--col-0) {
  flex: 1 0 0;
  min-width: 120px;
}
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-row .dt-cell.dt-cell--col-0 {
  flex: 0 0 40px;
  min-width: 40px;
}
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-row .dt-cell.dt-cell--col-1 {
  flex: 1.5 0 0;
  min-width: 300px;
}
body.desktop-page:has(#desk-dock .dock-item.active[aria-label="会计"])
  .page-container[data-page-route="query-report"] .datatable .dt-cell__content {
  width: 100% !important;
}
body.desktop-page .empty-state,
body.desktop-page .list-empty-state,
body.desktop-page .no-result { color: var(--mixiya-muted); }
/* Prevent the English upstream manual link from flashing before Desk renders. */
body.desktop-page a[href*="docs.frappe.io/"],
body.desktop-page a[href*="docs.erpnext.com/"],
body.desktop-page a[href*="frappeframework.com/docs/"] { display: none !important; }
/* Frappe's child table is wider than the form at 1280px. Keep its amounts
   reachable and show the scroll track instead of silently cropping them. */
body.desktop-page .form-grid {
  overflow-x: scroll !important;
  scrollbar-width: auto !important;
  scrollbar-color: #a7bfd9 #edf5ff;
}
body.desktop-page .form-grid::-webkit-scrollbar { display: block !important; height: 10px !important; }
body.desktop-page .form-grid::-webkit-scrollbar-track { background: #edf5ff; border-radius: 6px; }
body.desktop-page .form-grid::-webkit-scrollbar-thumb { background: #a7bfd9; border-radius: 6px; }
@media (min-width: 768px) and (max-width: 1350px) {
  body.desktop-page .form-section[data-fieldname="items_section"] .form-grid .grid-row .col[data-fieldname="item_code"] {
    flex: 1 0 130px !important;
    width: 130px !important;
  }
  body.desktop-page .form-section[data-fieldname="items_section"] .form-grid .grid-row .col[data-fieldname="delivery_date"] {
    flex: 1 0 95px !important;
    width: 95px !important;
  }
  body.desktop-page .form-section[data-fieldname="items_section"] .form-grid .grid-row .col[data-fieldname="qty"] {
    flex: 1 0 90px !important;
    width: 90px !important;
  }
}

/* The first Desk screen is an app launcher; give it an understandable entry point. */
body.desktop-page .desktop-wrapper { background: var(--mixiya-background); }
body.desktop-page .desktop-container {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  box-sizing: border-box;
  width: min(980px, calc(100% - 48px));
  height: auto !important;
  min-height: 320px;
  margin: 70px auto 0;
  padding: 32px;
  border: 1px solid var(--mixiya-border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 24px rgb(0 18 107 / 5%);
}
body.desktop-page .desktop-container::before {
  content: "米西亚业务工作台";
  display: block;
  margin-bottom: 20px;
  color: var(--mixiya-text);
  font-size: 22px;
  font-weight: 600;
}
body.desktop-page .desktop-container::after {
  content: "进入销售、采购、库存与财务业务";
  display: block;
  margin-top: 20px;
  color: var(--mixiya-muted);
  font-size: 14px;
}
body.desktop-page .desktop-icon {
  border: 1px solid var(--mixiya-border);
  border-radius: 10px;
  background: #f8fbff;
  transition: border-color .15s, box-shadow .15s;
}
body.desktop-page .desktop-container .icons-container {
  display: block !important;
  flex: none;
  width: 100%;
  height: auto !important;
  min-height: 0 !important;
  padding: 0 !important;
}
body.desktop-page .desktop-container .icons {
  justify-content: start;
  height: auto !important;
  min-height: 0 !important;
  grid-template-rows: none !important;
}
body.desktop-page .desktop-icon:hover { border-color: #a9d4ff; box-shadow: 0 4px 14px rgb(24 144 255 / 12%); }

/* Number cards do not expose per-card menus on any ERP dashboard. */
body.desktop-page .number-widget-box .card-actions,
body.desktop-page .number-widget-box .widget-control {
  display: none !important;
}

/* Cards denied by permission render as empty Editor.js columns. Collapse
   those columns across workspaces so the remaining cards keep their order. */
body.desktop-page .page-container[data-page-route="Workspaces"]
  .codex-editor__redactor > .ce-block.col-sm-6:has(> .ce-block__content > div:empty) {
  display: none;
}

/* Summary workspaces keep their live charts and number cards. Their generic
   shortcut/link lists still advertise modules removed from this ERP scope. */
body.desktop-page .page-container[data-page-route="Workspaces"]
  .codex-editor__redactor:has(> .ce-block .dashboard-widget-box, > .ce-block .number-widget-box)
  > .ce-block:has(.links-widget-box, .shortcut-widget-box) {
  display: none !important;
}

/* Keep chart tools such as refresh, reset and export, but omit editing. */
body.desktop-page .dashboard-widget-box .chart-actions .dropdown-menu li:has(> a[data-action="action-edit"]) {
  display: none !important;
}

/* The dashboard page itself has no user-facing customization menu. */
body.desktop-page #page-dashboard-view .page-head .menu-btn-group {
  display: none !important;
}

/* Print preview keeps the download and print actions only. */
#page-print .print-preview-sidebar .frappe-control[data-fieldname="language"],
#page-print .print-preview-sidebar .frappe-control[data-fieldname="letterhead"],
#page-print .page-head .page-icon-group .icon-btn:not(.btn-download-pdf),
#page-print .page-head .custom-actions .es-button:not(.btn-download-pdf),
#page-print .page-head .menu-btn-group {
  display: none !important;
}

/* Country and language master data are managed outside the business menu. */
body.desktop-page .body-sidebar .sidebar-item-container:has(> .standard-sidebar-item > a.item-anchor[href$="/geo/country"]),
body.desktop-page .body-sidebar .sidebar-item-container:has(> .standard-sidebar-item > a.item-anchor[href$="/geo/language"]) {
  display: none !important;
}

@media (max-width: 767px) {
  .mixiya-auth-banner { display: none; }
  body.mixiya-auth-page #page-login .page-content-wrapper,
  body.mixiya-auth-page #page-erpnext-access .page-content-wrapper { padding: 32px 16px; }
  body.mixiya-auth-page #page-login .page-card,
  body.mixiya-auth-page .erpnext-access-card { padding: 28px 24px; }
  body.desktop-page .desktop-container { width: calc(100% - 24px); margin-top: 24px; padding: 24px; }
}
/* Single-company controls retain their model/filter values without a visible selector. */
.mixiya-company-control {
  display: none !important;
}
