/* =========================================================
   YONGLI OPERATIONS PLATFORM
   Dashboard application styles
   ========================================================= */

/* ---------- Design variables ---------- */

:root {
  --primary: #005aa9;
  --primary-dark: #004783;
  --primary-light: #eaf4ff;
  --primary-soft: #f3f8fd;

  --background: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f9fafb;

  --text: #1f2937;
  --text-muted: #6b7280;
  --text-light: #9ca3af;

  --border: #e5e7eb;
  --border-dark: #d1d5db;

  --success: #15803d;
  --success-bg: #ecfdf3;

  --warning: #b45309;
  --warning-bg: #fff7ed;

  --danger: #b91c1c;
  --danger-bg: #fef2f2;

  --sidebar-width: 260px;
  --header-height: 72px;

  --radius-small: 8px;
  --radius-medium: 12px;
  --radius-large: 16px;

  --shadow-small: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-medium: 0 8px 24px rgba(15, 23, 42, 0.08);

  --transition: 180ms ease;
}

/* ---------- Reset ---------- */

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ---------- Main application ---------- */

.app {
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  display: flex;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition:
    transform var(--transition),
    width var(--transition);
}

.logo {
  display: flex;
  min-height: var(--header-height);
  align-items: center;
  justify-content: flex-start;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

.logo .horizontal-logo {
  width: 175px;
  height: auto;
  max-height: 52px;
  object-fit: contain;
  object-position: left center;
}

.sidebar nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 16px 12px calc(24px + env(safe-area-inset-bottom, 0px));
}

/* Permission-controlled sidebar links must be completely removed from layout.
   The normal .sidebar nav a rule uses display:flex, which can otherwise override
   the browser's default rendering for the hidden attribute. */
.sidebar nav a[hidden],
.sidebar nav a.permission-hidden {
    display: none !important;
}

.sidebar nav a {
  position: relative;
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  margin-bottom: 3px;
  padding: 10px 12px;
  color: #4b5563;
  border-radius: var(--radius-small);
  font-size: 14px;
  font-weight: 500;
  transition:
    color var(--transition),
    background var(--transition),
    transform var(--transition);
}

.sidebar nav a:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.sidebar nav a:active {
  transform: translateY(1px);
}

.sidebar nav a.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 650;
}

.sidebar nav a.active::before {
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: -12px;
  width: 4px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  content: "";
}

.menu-title {
  margin: 19px 12px 7px;
  color: var(--text-light);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.sidebar hr {
  width: calc(100% - 24px);
  margin: 13px auto 2px;
  border: 0;
  border-top: 1px solid var(--border);
}

/* ---------- Main panel ---------- */

.main {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition);
}

/* ---------- Header ---------- */

.main > header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  min-height: var(--header-height);
  align-items: center;
  gap: 20px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

#menuButton {
  display: none;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: var(--radius-small);
  transition: background var(--transition);
}

#menuButton:hover {
  background: var(--surface-soft);
}

.search {
  display: flex;
  width: min(520px, 48vw);
  height: 44px;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  color: var(--text-muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    background var(--transition);
}

.search:focus-within {
  background: var(--surface);
  border-color: rgba(0, 90, 169, 0.45);
  box-shadow: 0 0 0 4px rgba(0, 90, 169, 0.08);
}

.search input {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 14px;
}

.search input::placeholder {
  color: var(--text-light);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.icon-button {
  position: relative;
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  transition:
    color var(--transition),
    background var(--transition),
    border-color var(--transition);
}

.icon-button:hover {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #cfe3f5;
}

.icon-button.has-notifications::after {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  background: #dc2626;
  border: 2px solid var(--surface);
  border-radius: 50%;
  content: "";
}

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 5px;
  border-radius: 999px;
  transition: background var(--transition);
}

.profile:hover {
  background: var(--surface-soft);
}

.avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: #ffffff;
  background: var(--primary);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.profile strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}

.profile small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.25;
}

/* ---------- Content ---------- */

#content {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 32px;
}

#content > h1 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: clamp(26px, 3vw, 34px);
  line-height: 1.2;
  letter-spacing: -0.03em;
}

#content > p {
  margin: 0 0 26px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ---------- Dashboard cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  min-width: 0;
  padding: 22px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-small);
  transition:
    transform var(--transition),
    box-shadow var(--transition),
    border-color var(--transition);
}

.card:hover {
  transform: translateY(-2px);
  border-color: #d9e5ef;
  box-shadow: var(--shadow-medium);
}

.card::after {
  position: absolute;
  top: 0;
  right: 0;
  width: 78px;
  height: 78px;
  background:
    radial-gradient(
      circle at top right,
      rgba(0, 90, 169, 0.1),
      transparent 70%
    );
  content: "";
  pointer-events: none;
}

.card h3 {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.card h2 {
  margin: 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.03em;
}

/* ---------- Reusable page elements ---------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0;
  font-size: 29px;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.page-header p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  font-size: 14px;
  font-weight: 650;
  transition:
    transform var(--transition),
    background var(--transition),
    border-color var(--transition),
    color var(--transition),
    box-shadow var(--transition);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 6px 16px rgba(0, 90, 169, 0.18);
}

.btn-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-dark);
}

.btn-secondary:hover {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #bad6ee;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-small);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 17px;
}

.panel-body {
  padding: 20px;
}

/* ---------- Tables ---------- */

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--text-muted);
  background: #f8fafc;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table td {
  color: #374151;
  font-size: 13px;
}

.data-table tbody tr:hover {
  background: #fafcff;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

/* ---------- Status badges ---------- */

.badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.badge-success {
  color: var(--success);
  background: var(--success-bg);
}

.badge-warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.badge-danger {
  color: var(--danger);
  background: var(--danger-bg);
}

.badge-neutral {
  color: #4b5563;
  background: #f3f4f6;
}

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.form-group {
  min-width: 0;
}

.form-group label {
  display: block;
  margin-bottom: 7px;
  color: #374151;
  font-size: 12px;
  font-weight: 650;
}

.form-control {
  width: 100%;
  min-height: 43px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-small);
  outline: none;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}

.form-control:focus {
  border-color: rgba(0, 90, 169, 0.65);
  box-shadow: 0 0 0 4px rgba(0, 90, 169, 0.08);
}

textarea.form-control {
  min-height: 110px;
  resize: vertical;
}

/* ---------- Loading and empty states ---------- */

.loading-state,
.empty-state,
.error-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  padding: 32px;
  text-align: center;
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: dashboard-spin 700ms linear infinite;
}

@keyframes dashboard-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Mobile overlay ---------- */

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: none;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
  display: block;
}

/* ---------- Large tablets and smaller laptops ---------- */

@media (max-width: 1180px) {
  :root {
    --sidebar-width: 232px;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #content {
    padding: 28px;
  }

  .main > header {
    padding-inline: 22px;
  }

  .search {
    width: min(420px, 43vw);
  }
}

/* ---------- Tablets ---------- */

@media (max-width: 900px) {
  .sidebar {
    width: 270px;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateX(-100%);
    box-shadow: var(--shadow-medium);
  }

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

  .main {
    margin-left: 0;
  }

  #menuButton {
    display: inline-flex;
  }

  .main > header {
    gap: 12px;
    padding-inline: 18px;
  }

  .search {
    width: auto;
    flex: 1;
  }

  #content {
    padding: 24px;
  }

  .profile strong,
  .profile small {
    display: none;
  }

  .profile {
    padding: 0;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  :root {
    --header-height: 64px;
  }

  .main > header {
    padding: 0 12px;
  }

  #menuButton,
  .icon-button {
    width: 40px;
    height: 40px;
  }

  .search {
    height: 40px;
    padding-inline: 11px;
  }

  .search input {
    font-size: 13px;
  }

  .search input::placeholder {
    color: transparent;
  }

  .header-right {
    gap: 8px;
  }

  .avatar {
    width: 38px;
    height: 38px;
  }

  #content {
    padding: 20px 14px 32px;
  }

  #content > h1 {
    font-size: 25px;
  }

  #content > p {
    margin-bottom: 20px;
  }

  .cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    padding: 18px;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions .btn {
    flex: 1;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .panel-body {
    padding-inline: 16px;
  }
}

/* ---------- Very small devices ---------- */

@media (max-width: 400px) {
  .icon-button {
    display: none;
  }

  .sidebar {
    width: min(88vw, 300px);
  }

  .search input::placeholder {
    font-size: 0;
  }

  .card h2 {
    font-size: 25px;
  }
}

/* ---------- Accessibility ---------- */

:focus-visible {
  outline: 3px solid rgba(0, 90, 169, 0.28);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.profile{
    display:flex;
    align-items:center;
    gap:12px;
    cursor:pointer;
    position:relative;
}

.profile-details{
    display:flex;
    flex-direction:column;
}

.profile-arrow{
    width:18px;
    height:18px;
    color:#6b7280;
}

.header-right{
    position:relative;
}

.profile-dropdown{

    position:absolute;

    top:65px;
    right:20px;

    width:220px;

    background:#fff;

    border-radius:12px;

    box-shadow:0 10px 25px rgba(0,0,0,.15);

    display:none;

    overflow:hidden;

    z-index:1000;

}

.profile-dropdown.show{
    display:block;
}

.profile-dropdown button{

    width:100%;

    border:none;

    background:none;

    padding:14px 18px;

    text-align:left;

    cursor:pointer;

    font-size:14px;

}

.profile-dropdown button:hover{

    background:#f3f4f6;

}

.profile-dropdown hr{

    border:none;

    border-top:1px solid #e5e7eb;

    margin:0;

}

.sidebar nav a.sidebar-link-disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.coming-soon-badge {
    margin-left: auto;
    padding: 2px 6px;
    border-radius: 999px;
    background: #e7edf5;
    color: #667085;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .5px;
    text-transform: uppercase;
}


/* Mobile viewport/safe-area fix: keep the bottom of the sidebar reachable
   above browser chrome / gesture navigation on phones. */
@media (max-width: 900px) {
  .sidebar nav {
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar::after {
    content: "";
    display: block;
    flex: 0 0 env(safe-area-inset-bottom, 0px);
  }
}


/* ---------- Embedded dashboard pages ---------- */
#content.embedded-page-mode {
  max-width: none;
  margin: 0;
  padding: 0;
  height: calc(100dvh - var(--header-height));
  overflow: hidden;
}

.embedded-page-shell {
  width: 100%;
  height: 100%;
  background: var(--background);
}

.dashboard-page-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.profile-dropdown .admin-settings-menu[hidden] {
  display: none !important;
}

/* ==========================================================
   Mobile/PWA shell hardening
   ========================================================== */
.nav-load-error {
  margin: 18px 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  background: var(--surface-soft);
  font-size: 12px;
  line-height: 1.45;
}
.nav-load-error strong,
.nav-load-error span { display: block; }
.nav-load-error button {
  margin-top: 10px;
  padding: 8px 12px;
  border: 0;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
.mobile-admin-nav { display: none; }

@media (max-width: 900px) {
  html, body, .app, .main { min-height: 100dvh; }

  .sidebar {
    width: min(86vw, 320px);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff;
  }

  .sidebar .logo {
    flex: 0 0 auto;
    min-height: 62px;
    padding: 8px 16px;
  }

  .sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 10px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar nav a {
    min-height: 48px;
    padding: 12px 13px;
    font-size: 15px;
  }

  .menu-title { margin-top: 16px; }
  .mobile-admin-nav { display: block; }

  .main > header {
    min-height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    gap: 8px;
  }

  .profile-dropdown {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px) + 6px);
    right: max(10px, env(safe-area-inset-right, 0px));
    width: min(270px, calc(100vw - 20px));
    max-height: calc(100dvh - var(--header-height) - env(safe-area-inset-top, 0px) - 16px);
    overflow-y: auto;
    z-index: 2000;
  }

  .profile-dropdown button {
    min-height: 48px;
    padding: 14px 18px;
    font-size: 15px;
  }

  #content.embedded-page-mode {
    height: calc(100dvh - var(--header-height) - env(safe-area-inset-top, 0px));
  }
}

@media (max-width: 520px) {
  .main > header { gap: 7px; }
  .search { display: none; }
  .header-right { margin-left: auto; gap: 7px; }
  .profile-arrow { display: none; }
  #content { padding: 16px 12px calc(24px + env(safe-area-inset-bottom, 0px)); }
  #content > h1 { font-size: 24px; }
  .cards { gap: 10px; }
  .card { padding: 16px; }
}


/* ==========================================================
   Mobile viewport lock / true phone sizing
   ========================================================== */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y;
}

.app,
.main,
#content {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 900px) {
  html,
  body {
    width: 100vw;
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .app {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .main {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-left: 0;
    overflow-x: hidden;
  }

  .main > header {
    width: 100%;
    max-width: 100vw;
  }

  #content {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
  }

  #content.embedded-page-mode,
  .embedded-page-shell,
  .dashboard-page-frame {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .dashboard-page-frame {
    overflow: hidden;
  }
}
