:root {
  --tea-green: #0f5132;
  --tea-green-dark: #0a3622;
  --leaf: #198754;
  --gold: #c9a227;
  --paper: #f5f7f2;
  --ink: #1f2a24;
  --muted: #66746d;
  --line: #dfe6dd;
}

html { font-size: 14px; }
body { margin: 0; color: var(--ink); background: var(--paper); }
a { color: var(--tea-green); }
.app-shell { display: grid; grid-template-columns: minmax(248px, 280px) minmax(0, 1fr); min-height: 100vh; }
.app-shell.no-sidebar { display: flex; flex-direction: column; }
.portal-shell { display: flex; flex-direction: column; }
.sidebar { --bs-offcanvas-width: 280px; background: var(--tea-green-dark); color: #fff; width: 280px; }
.brand-panel { min-height: 86px; display: flex; gap: 12px; align-items: center; padding: 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.app-logo-link { align-items: center; display: inline-flex; flex: 0 0 auto; justify-content: center; line-height: 1; text-decoration: none; }
.app-logo, .mpbl-logo { max-height: 52px; object-fit: contain; width: auto; }
.brand-panel .app-logo-link, .topbar > .app-logo-link { background: #fff; border: 1px solid #d8e5dc; border-radius: 8px; padding: 4px; }
.brand-panel img { max-width: 52px; }
.brand-panel strong, .brand-panel span { display: block; }
.brand-copy { min-width: 0; }
.brand-panel span { color: #d6e4dc; font-size: .86rem; }
.brand-panel .module-mini { color: #f4dfa1; font-size: .76rem; font-weight: 700; margin-top: 3px; }
.sidebar-nav { padding: 14px; display: grid; gap: 6px; }
.sidebar-nav a { color: #eef7f0; display: block; text-decoration: none; padding: 10px 12px; border-radius: 8px; transition: background .16s ease, color .16s ease, transform .16s ease; }
.sidebar-nav a:hover { background: rgba(255,255,255,.1); color: #fff; transform: translateX(1px); }
.sidebar-nav a.active { background: #fff; color: var(--tea-green); font-weight: 700; border-left: 4px solid var(--gold); padding-left: 10px; }
.main-area { display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
.topbar { min-height: 70px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 22px; position: sticky; top: 0; z-index: 10; }
.topbar-heading { min-width: 0; }
.topbar-title { font-weight: 800; color: var(--tea-green); font-size: 1.18rem; }
.company-name { color: var(--muted); font-size: .78rem; line-height: 1.2; }
.breadcrumb-line { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.breadcrumb-line a { font-weight: 700; text-decoration: none; }
.breadcrumb-line span { margin: 0 4px; }
.user-tools { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.content-area { flex: 1 0 auto; padding: 22px; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #1e271b; font-weight: 600; }
.btn-gold:hover { background: #b89120; border-color: #b89120; color: #111; }
.page-panel { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: 0 8px 24px rgba(15, 81, 50, .06); }
.page-panel.narrow { max-width: 560px; }
.page-panel h2 { font-size: 1rem; color: var(--tea-green); margin: 0 0 12px; }
.panel-actions { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.filter-bar { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)) auto auto; gap: 10px; align-items: center; margin-bottom: 16px; }
.data-table { min-width: 920px; }
.data-table th { color: var(--tea-green); font-size: .78rem; text-transform: uppercase; background: #f1f6ef; white-space: nowrap; }
.data-table td { vertical-align: middle; }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(140px, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric-card { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--leaf); border-radius: 8px; padding: 16px; box-shadow: 0 8px 20px rgba(15, 81, 50, .06); }
.metric-card.warning { border-left-color: var(--gold); }
.metric-card.danger { border-left-color: #b02a37; }
.metric-card span { display: block; color: var(--muted); font-size: .82rem; }
.metric-card strong { display: block; color: var(--tea-green); font-size: 1.8rem; line-height: 1.2; }
.quick-links { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.quick-links a { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; text-decoration: none; font-weight: 600; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #eff5ed, #ffffff); }
.login-card { width: min(430px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 32px; box-shadow: 0 20px 50px rgba(15, 81, 50, .14); text-align: center; }
.login-logo { width: 76px; height: 76px; object-fit: contain; margin-bottom: 10px; }
.login-card h1 { color: var(--tea-green); font-size: 1.6rem; margin: 0; }
.login-card h2 { color: var(--gold); font-size: 1rem; margin: 0 0 24px; }
.login-card p { color: var(--muted); margin-bottom: 4px; }
.login-card form { text-align: left; }
.portal-hero { background: linear-gradient(135deg, #ffffff 0%, #f3f8f0 62%, #fff8df 100%); border: 1px solid var(--line); border-radius: 8px; padding: 28px; margin-bottom: 18px; }
.portal-hero h1 { color: var(--tea-green); font-size: 2rem; margin: 0; }
.portal-hero p { color: var(--muted); margin: 4px 0 0; }
.eyebrow { color: var(--gold) !important; text-transform: uppercase; font-size: .8rem; font-weight: 700; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.module-card { background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--leaf); border-radius: 8px; box-shadow: 0 12px 30px rgba(15,81,50,.08); overflow: hidden; transition: transform .18s ease, box-shadow .18s ease; }
.module-card.gold { border-top-color: var(--gold); }
.module-card:hover { box-shadow: 0 18px 42px rgba(15,81,50,.13); transform: translateY(-2px); }
.module-card-click { color: inherit; display: grid; gap: 14px; min-height: 235px; padding: 22px; text-decoration: none; }
.module-card-click:hover { color: inherit; }
.module-icon { align-items: center; background: #edf7f1; border: 1px solid #cae3d4; border-radius: 8px; color: var(--tea-green); display: flex; height: 68px; justify-content: center; width: 68px; }
.module-card.gold .module-icon { background: #fff8df; border-color: #f1dfa0; color: #8a6908; }
.module-icon svg { fill: none; height: 40px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 3; width: 40px; }
.module-card-body strong { color: var(--tea-green); display: block; font-size: 1.18rem; margin-bottom: 6px; }
.module-card-body span { color: var(--muted); display: block; line-height: 1.45; }
.module-card-link { align-self: end; background: var(--tea-green); border-radius: 8px; color: #fff; display: inline-flex; font-weight: 700; justify-content: center; max-width: 120px; min-height: 40px; padding: 9px 16px; }
.module-card.gold .module-card-link { background: var(--gold); color: #1e271b; }
.calendar-list { display: grid; gap: 12px; }
.calendar-item { display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-left: 4px solid var(--leaf); border-radius: 8px; padding: 14px; background: #fff; }
.calendar-item.completed { border-left-color: var(--leaf); }
.calendar-item.cancelled { border-left-color: #6c757d; }
.calendar-item.follow-up-required { border-left-color: var(--gold); }
.calendar-item h2 { margin: 0 0 2px; font-size: 1rem; color: var(--tea-green); }
.calendar-item p { margin: 0 0 6px; color: var(--muted); }
.date-tile { width: 56px; height: 62px; border-radius: 8px; background: #f1f6ef; display: grid; place-items: center; color: var(--tea-green); }
.date-tile strong { font-size: 1.4rem; line-height: 1; }
.date-tile span { font-size: .75rem; text-transform: uppercase; }
.status-badge { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #e6f4ec; color: var(--tea-green); font-size: .78rem; font-weight: 700; }
.status-badge.gold { background: #fbf3d0; color: #735a00; }
.factory-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 14px; }
.factory-summary div, .detail-grid div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.factory-summary span, .detail-grid span { display: block; color: var(--muted); font-size: .78rem; }
.factory-summary strong, .detail-grid strong { color: var(--tea-green); }
.visit-accordion .accordion-button { color: var(--tea-green); font-weight: 700; }
textarea.tall { min-height: 130px; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(245,247,242,.94); border-top: 1px solid var(--line); padding: 14px 0; display: flex; gap: 10px; justify-content: flex-end; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-list a { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-decoration: none; background: #fff; }
.detail-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.detail-header h2 { font-size: 1.3rem; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.print-surface h3 { color: var(--tea-green); font-size: 1rem; margin-top: 18px; }
.audit-strip { color: var(--muted); border-top: 1px solid var(--line); margin-top: 18px; padding-top: 10px; }
.review-filter { grid-template-columns: repeat(5, minmax(130px, 1fr)) auto auto; }
.review-metrics { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.app-footer { background: #fff; border-top: 1px solid var(--line); color: var(--muted); flex-shrink: 0; font-size: .86rem; line-height: 1.5; padding: 16px 22px; text-align: center; }
.pager-bar { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; margin-top: 12px; }
.pager-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.data-table th a { color: var(--tea-green); text-decoration: none; }
.data-table th a:hover { text-decoration: underline; }
.status-badge.muted { background: #eef1ee; color: #59655f; }
.admin-actions, .quick-links { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.admin-actions a, .quick-links a { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--leaf); border-radius: 8px; color: var(--tea-green); font-weight: 700; padding: 10px 14px; text-decoration: none; }
.assignment-toolbar { display: grid; gap: 14px; margin-bottom: 16px; }
.assignment-section-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(15,81,50,.05); overflow: hidden; }
.assignment-section-card .card-header { background: #f8fbf7; border-bottom: 1px solid var(--line); padding: 12px 14px; }
.assignment-section-card .card-header h2 { color: var(--tea-green); font-size: .98rem; margin: 0; }
.assignment-section-card .card-header p { color: var(--muted); font-size: .82rem; margin: 2px 0 0; }
.assignment-section-card .card-body { padding: 14px; }
.assignment-bulk-card { border-left: 4px solid var(--leaf); }
.assignment-bulk-card .card-header { background: #f1f8f4; }
.assignment-filter-card .filter-bar { margin-bottom: 0; }
.clickable-assignment-row { cursor: pointer; }
.clickable-assignment-row:hover { background: #f1f6ef; }
.clickable-assignment-row.manufacture-type-ctc-row { background: #fffaf0; box-shadow: inset 3px 0 0 #d4a62a; }
.clickable-assignment-row.manufacture-type-ctc-row:hover { background: #f8f1df; }
.manufacture-type-badge { display: inline-block; min-width: 72px; padding: 4px 8px; border-radius: 999px; background: #eef1ee; color: #59655f; font-size: .78rem; font-weight: 700; text-align: center; }
.manufacture-type-badge-ctc { background: #fbf3d0; color: #735a00; }
.factory-summary-trigger { color: inherit; text-decoration: none; font-weight: 600; }
.factory-summary-trigger:hover { color: var(--tea-green); text-decoration: none; }
.factory-search-results { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 28px rgba(15,81,50,.12); margin-top: 6px; max-height: 280px; overflow: auto; position: absolute; width: min(680px, calc(100% - 32px)); z-index: 20; }
.factory-search-option { align-items: center; background: #fff; border: 0; border-bottom: 1px solid var(--line); color: inherit; display: flex; gap: 10px; justify-content: space-between; padding: 10px 12px; text-align: left; width: 100%; }
.factory-search-option:hover { background: #f1f6ef; }
.factory-search-option span { display: grid; gap: 2px; }
.factory-search-option small { color: var(--muted); display: block; }
.factory-search-option em { background: #fbf3d0; border-radius: 999px; color: #735a00; font-size: .76rem; font-style: normal; font-weight: 700; padding: 4px 8px; white-space: nowrap; }
.factory-search-option.has-pending { box-shadow: inset 3px 0 0 var(--gold); }
.factory-search-empty { color: var(--muted); padding: 12px; }
.schedule-section-card .schedule-section-header { background: var(--tea-green); border-bottom: 1px solid #0b3d28; color: #fff; }
.schedule-section-card .schedule-section-header h2 { color: #fff; font-weight: 800; }
.schedule-section-card .schedule-section-header p { color: rgba(255,255,255,.78); font-weight: 600; }
.schedule-section-card .schedule-section-header .status-badge { background: rgba(255,255,255,.16); color: #fff; }

@media print {
  .sidebar, .topbar, .sticky-actions, .btn { display: none !important; }
  .app-shell { display: block; }
  .content-area { padding: 0; }
  .page-panel { box-shadow: none; border: 0; }
}

@media (min-width: 992px) {
  .has-sidebar .sidebar.offcanvas {
    bottom: auto;
    height: 100vh;
    left: auto;
    position: sticky;
    right: auto;
    top: 0;
    transform: none !important;
    visibility: visible !important;
    z-index: 1;
  }
  .has-sidebar .sidebar.offcanvas-start { border-right: 0; }
  .has-sidebar .sidebar .btn-close { display: none; }
  .has-sidebar .offcanvas-backdrop { display: none; }
}

@media (max-width: 991.98px) {
  .app-shell { display: flex; flex-direction: column; min-height: 100vh; }
  .portal-shell { display: flex; }
  .sidebar { width: var(--bs-offcanvas-width); }
  .main-area { min-height: 100vh; width: 100%; }
  .content-area { padding: 16px; }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .topbar-heading { order: 3; width: 100%; }
  .filter-bar { grid-template-columns: 1fr; }
  .review-filter { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-item { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 575.98px) {
  .topbar { padding: 12px; flex-wrap: wrap; }
  .app-logo, .mpbl-logo { max-height: 42px; }
  .topbar-title { order: 3; width: 100%; font-size: 1.05rem; }
  .user-tools { margin-left: auto; }
  .metric-grid { grid-template-columns: 1fr; }
  .page-panel { padding: 12px; }
}
