:root {
  --pmis-primary: #0c7195;
  --pmis-primary-dark: #075875;
  --pmis-bg: #f4f7fb;
  --pmis-card: #ffffff;
  --pmis-text: #1f2937;
  --pmis-muted: #6b7280;
  --pmis-border: #e5e7eb;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--pmis-bg); color: var(--pmis-text); font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { text-decoration: none; }

.app-shell { display: grid; grid-template-columns: 285px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #0b1721; color: #d8e7ee; padding: 20px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand-box { display: flex; align-items: center; gap: 12px; padding: 12px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); border-radius: 18px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--pmis-primary), #25b5cc); color: white; font-size: 20px; }
.brand-mark.large { width: 64px; height: 64px; font-size: 30px; }
.brand-title { font-weight: 800; line-height: 1.1; color: #fff; }
.sidebar small { color: #9fb6c2; }
.sidebar .nav-link { color: #c8d6dd; padding: 10px 12px; border-radius: 12px; display: flex; align-items: center; gap: 10px; }
.sidebar .nav-link:hover, .sidebar .nav-link.active { background: rgba(12,113,149,.22); color: #fff; }
.sidebar .nav-link i { width: 20px; text-align: center; }
.main-content { padding: 24px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 28px; font-weight: 800; }

.pmis-card { border: 1px solid var(--pmis-border); border-radius: 20px; box-shadow: 0 10px 30px rgba(15, 23, 42, .05); overflow: hidden; }
.toolbar-card { background: white; border: 1px solid var(--pmis-border); border-radius: 18px; padding: 16px; box-shadow: 0 10px 25px rgba(15,23,42,.04); }
.btn-primary { background: var(--pmis-primary); border-color: var(--pmis-primary); }
.btn-primary:hover { background: var(--pmis-primary-dark); border-color: var(--pmis-primary-dark); }
.text-primary { color: var(--pmis-primary) !important; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.stat-card { position: relative; overflow: hidden; background: white; border: 1px solid var(--pmis-border); border-radius: 20px; padding: 22px; box-shadow: 0 10px 25px rgba(15,23,42,.05); }
.stat-card span { color: var(--pmis-muted); display: block; margin-bottom: 8px; }
.stat-card strong { font-size: 34px; line-height: 1; }
.stat-card i { position: absolute; right: 18px; bottom: 12px; color: rgba(12,113,149,.14); font-size: 52px; }

.progress.mini { height: 8px; min-width: 100px; }
.detail-box { border: 1px solid var(--pmis-border); border-radius: 16px; padding: 14px; background: #fbfdff; height: 100%; }
.detail-box span { display: block; color: var(--pmis-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.detail-box strong { font-size: 15px; }

.tree-list { list-style: none; margin: 0; padding-left: 22px; position: relative; }
.tree-list > li { margin: 10px 0; position: relative; }
.tree-list > li::before { content: ""; position: absolute; left: -14px; top: 18px; width: 14px; border-top: 1px dashed #b7c4ce; }
.tree-list > li::after { content: ""; position: absolute; left: -14px; top: -10px; bottom: 18px; border-left: 1px dashed #b7c4ce; }
.tree-list > li:first-child::after { top: 18px; }
.tree-node { display: flex; gap: 12px; align-items: flex-start; padding: 12px; background: #fff; border: 1px solid var(--pmis-border); border-radius: 16px; }
.tree-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: rgba(12,113,149,.1); color: var(--pmis-primary); }

.module-icon, .report-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; background: rgba(12,113,149,.1); color: var(--pmis-primary); font-size: 22px; }
.feature-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--pmis-border); border-radius: 12px; padding: 10px; background: #fbfdff; }

.approval-step { display: flex; gap: 12px; padding: 12px; border-left: 3px solid #d1d5db; }
.approval-step.approved { border-left-color: #198754; }
.approval-step.pending { border-left-color: #ffc107; }
.approval-step.rejected { border-left-color: #dc3545; }
.approval-dot { width: 14px; height: 14px; border-radius: 50%; background: #d1d5db; margin-top: 5px; }
.approval-step.approved .approval-dot { background: #198754; }
.approval-step.pending .approval-dot { background: #ffc107; }
.approval-step.rejected .approval-dot { background: #dc3545; }

.photo-thumb { height: 220px; object-fit: cover; background: #eef2f7; }
.photo-placeholder { height: 220px; display: grid; place-items: center; background: #eef2f7; color: #94a3b8; font-size: 48px; }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dff6fb, transparent 35%), linear-gradient(135deg, #0c7195, #0b1721); }
.auth-card { width: min(1000px, 100%); display: grid; grid-template-columns: 1fr 1fr; border-radius: 28px; overflow: hidden; background: white; }
.auth-hero { padding: 54px; background: linear-gradient(135deg, #0b1721, #0c7195); color: white; display: flex; flex-direction: column; justify-content: center; }
.auth-hero h1 { font-size: 42px; font-weight: 900; margin: 18px 0 10px; }
.auth-hero p { color: #d7edf4; font-size: 18px; }
.auth-form { padding: 54px; }
.auth-form h2 { font-weight: 800; }
.mini-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.mini-pills span { border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 8px 12px; background: rgba(255,255,255,.08); }
.security-note { color: var(--pmis-muted); font-size: 14px; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .stats-grid, .auth-card { grid-template-columns: 1fr; }
  .auth-hero, .auth-form { padding: 32px; }
  .main-content { padding: 16px; }
}
.topbar-actions { display:flex; align-items:center; gap:12px; flex-wrap:wrap; justify-content:flex-end; }
.global-search-wrap { position:relative; width:min(420px, 48vw); }
.global-search-results { position:absolute; z-index:999; left:0; right:0; top:110%; background:#fff; border:1px solid var(--pmis-border); border-radius:14px; overflow:hidden; max-height:420px; overflow-y:auto; }
.global-search-item { display:block; padding:10px 12px; border-bottom:1px solid var(--pmis-border); color:var(--pmis-text); }
.global-search-item:hover { background:#f3f8fb; }
.module-card { transition: transform .15s ease, box-shadow .15s ease; }
.module-card:hover { transform: translateY(-2px); box-shadow:0 16px 32px rgba(15,23,42,.08); }
.view-toggle .btn.active { background:var(--pmis-primary); border-color:var(--pmis-primary); color:#fff; }
.tree-panel { display:none; }
.tree-panel.active { display:block; }
.dynamic-tree ul { list-style:none; padding-left:20px; }
.dynamic-tree li { margin:8px 0; }
.dynamic-tree details { border:1px solid var(--pmis-border); border-radius:12px; background:#fff; padding:8px 10px; }
.dynamic-tree summary { cursor:pointer; font-weight:700; }
.tree-meta { font-size:12px; color:var(--pmis-muted); display:flex; flex-wrap:wrap; gap:6px; margin-top:5px; }
.tree-badge { font-size:11px; border-radius:999px; padding:2px 8px; background:#eef7fb; color:#0c7195; }
.timeline { position:relative; }
.timeline-item { display:flex; gap:12px; position:relative; padding-bottom:16px; }
.timeline-dot { width:14px; height:14px; border-radius:999px; background:var(--pmis-primary); margin-top:5px; flex:none; box-shadow:0 0 0 4px rgba(12,113,149,.12); }
.timeline-content { flex:1; border:1px solid var(--pmis-border); border-radius:14px; padding:12px; background:#fff; }
.meta-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; }
.filter-card { background:#fff; border:1px solid var(--pmis-border); border-radius:18px; padding:14px; margin-bottom:16px; }
.record-card { border:1px solid var(--pmis-border); border-radius:18px; padding:14px; background:#fff; height:100%; }
.record-card .title { font-weight:800; }
.record-meta { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.record-meta .badge { font-weight:500; }
@media (max-width: 992px) { .global-search-wrap { width:100%; } .meta-grid { grid-template-columns:repeat(2,minmax(0,1fr)); } }
@media (max-width: 576px) { .meta-grid { grid-template-columns:1fr; } }
.timeline-attachments { display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.attachment-chip { display:inline-flex; align-items:center; gap:6px; border:1px solid var(--pmis-border); border-radius:999px; padding:6px 10px; background:#f8fafc; font-size:12px; color:var(--pmis-text); }
.timeline-img { width:100%; max-height:180px; object-fit:cover; border-radius:12px; border:1px solid var(--pmis-border); margin-top:8px; }

.ajax-select-wrapper { position: relative; }
.ajax-select-results {
  position: absolute;
  z-index: 1080;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 0.75rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  padding: 0.35rem;
}
.ajax-select-result {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-radius: 0.55rem;
  font-size: 0.9rem;
}
.ajax-select-result:hover { background: rgba(12, 113, 149, 0.1); }
.ajax-select-empty { padding: 0.65rem; color: #64748b; font-size: 0.875rem; }
.sidebar .nav-link { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.sidebar .nav-link span:first-child { min-width:0; }
.module-pending-badge { min-width:22px; height:22px; display:inline-flex; align-items:center; justify-content:center; border-radius:999px; background:#dc3545; color:#fff; font-size:12px; font-weight:800; padding:0 7px; box-shadow:0 0 0 3px rgba(220,53,69,.12); }
.sidebar .nav-link.active .module-pending-badge { background:#fff; color:#dc3545; }
.pending-panel-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:12px; }
.pending-panel-item { border:1px solid var(--pmis-border); border-radius:16px; padding:12px; background:#fff; display:flex; justify-content:space-between; gap:12px; align-items:start; }
.auto-locked-field { background:#f8fafc !important; border-style:dashed; }
.lock-note { font-size:12px; color:#64748b; margin-top:4px; }

.pending-for-me {
  border: 1px solid rgba(245, 158, 11, 0.55) !important;
  box-shadow: 0 12px 28px rgba(245, 158, 11, 0.15) !important;
  background: linear-gradient(180deg, rgba(255, 251, 235, 0.92), #fff) !important;
}
.pending-for-me::before {
  content: 'Pending for you';
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-size: 11px;
  font-weight: 700;
}

.master-project-form {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-width: 260px;
}
.master-project-form .form-select {
  min-width: 230px;
  border-radius: 999px;
  border-color: rgba(13, 110, 253, .25);
  background-color: #f8fbff;
  font-weight: 600;
}
.project-scope-banner {
  border: 1px solid rgba(13, 110, 253, .16);
  background: linear-gradient(90deg, #eef6ff, #ffffff);
  color: #12467a;
  border-radius: 16px;
  padding: .65rem .9rem;
  margin-bottom: 1rem;
  box-shadow: 0 6px 18px rgba(13, 110, 253, .06);
}
.admin-pending-banner {
  border: 1px solid rgba(255, 193, 7, .25);
  background: #fffaf0;
  color: #7a5200;
  border-radius: 12px;
  padding: .55rem .75rem;
  margin-top: .75rem;
}
@media (max-width: 992px) {
  .master-project-form { width: 100%; min-width: 100%; }
  .master-project-form .form-select { min-width: 0; width: 100%; }
}

/* v3.1 mobile navigation + project/branch tree enhancements */
.topbar-title-wrap { display:flex; align-items:center; gap:12px; min-width:0; }
.mobile-menu-btn, .sidebar-close { display:none; }
.sidebar-backdrop { display:none; }
.project-tree-list details { border:0; background:transparent; padding:0; }
.project-tree-list summary { list-style:none; }
.project-tree-list summary::-webkit-details-marker { display:none; }
.project-tree-node { cursor:pointer; align-items:center; }
.project-tree-node:hover { border-color:rgba(12,113,149,.35); background:#f8fcff; }
.project-tree-item.has-pending > details > .project-tree-node { border-color:rgba(245,158,11,.45); box-shadow:0 10px 24px rgba(245,158,11,.10); }
.tree-node-main { flex:1; min-width:0; }
.tree-node-badges { display:flex; flex-wrap:wrap; gap:6px; justify-content:flex-end; margin-left:auto; }
.dynamic-tree details[data-pending="true"], .dynamic-tree li:has(.tree-badge-pending) details { border-color:rgba(245,158,11,.45); }
.tree-badge-pending { background:#fff3cd; color:#8a5a00; }

@media (max-width: 1100px) {
  .app-shell { display:block; }
  .sidebar {
    position:fixed;
    left:0;
    top:0;
    bottom:0;
    width:min(86vw, 330px);
    height:100vh;
    z-index:1200;
    transform:translateX(-105%);
    transition:transform .22s ease;
    box-shadow:18px 0 45px rgba(15,23,42,.22);
  }
  body.sidebar-open .sidebar { transform:translateX(0); }
  .sidebar-backdrop {
    display:none;
    position:fixed;
    inset:0;
    z-index:1190;
    background:rgba(15,23,42,.48);
    backdrop-filter:blur(2px);
  }
  body.sidebar-open .sidebar-backdrop { display:block; }
  .mobile-menu-btn, .sidebar-close { display:inline-flex; align-items:center; justify-content:center; }
  .sidebar-close { margin-left:auto; border-color:rgba(255,255,255,.3); color:#fff; }
  .main-content { width:100%; }
  .topbar { align-items:flex-start; }
  .topbar-actions { width:100%; justify-content:flex-start; }
}

@media (max-width: 768px) {
  .topbar-title-wrap { width:100%; align-items:flex-start; }
  .topbar-title-wrap h1 { font-size:22px; line-height:1.15; }
  .topbar-actions { gap:8px; }
  .global-search-wrap { width:100%; order:3; }
  .topbar-actions > .badge { max-width:100%; white-space:normal; }
  .filter-card .btn, .toolbar-card .btn { width:100%; }
  .view-toggle { width:100%; display:flex; }
  .view-toggle .btn { flex:1; }
  .tree-node { flex-wrap:wrap; }
  .tree-node-badges { width:100%; justify-content:flex-start; padding-left:46px; }
  .tree-list { padding-left:12px; }
  .project-tree-list .project-tree-list { padding-left:16px; }
  .table-responsive { font-size:13px; }
}

/* Backup & Restore module */
.feature-icon {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 110, 253, .10);
  color: #0d6efd;
  font-size: 1.35rem;
  flex: 0 0 auto;
}
.empty-state {
  border: 1px dashed rgba(15, 23, 42, .16);
  border-radius: 18px;
  background: rgba(248, 250, 252, .7);
}

/* v3.9 interactive walkthrough tutorial */
.tutorial-setting-row {
  border: 1px solid rgba(12,113,149,.12);
  border-radius: 14px;
  padding: 14px 14px 14px 52px;
  background: linear-gradient(180deg, rgba(12,113,149,.04), rgba(255,255,255,.9));
}
.tutorial-setting-row .form-check-input { margin-left: -38px; width: 2.4rem; height: 1.25rem; }
.tutorial-setting-row .form-check-label { display:flex; flex-direction:column; gap:2px; }
.tutorial-setting-row .form-check-label span { color:#64748b; font-size:13px; }
.tutorial-module-switches {
  border:1px solid rgba(15,23,42,.10);
  border-radius:18px;
  padding:16px;
  background:#f8fafc;
}
.module-toggle-card {
  display:flex;
  align-items:flex-start;
  gap:10px;
  border:1px solid rgba(15,23,42,.10);
  border-radius:14px;
  padding:12px;
  background:#fff;
  cursor:pointer;
  min-height:74px;
  transition:all .18s ease;
}
.module-toggle-card:hover { border-color:rgba(12,113,149,.35); box-shadow:0 8px 24px rgba(15,23,42,.08); }
.module-toggle-card.active { border-color:rgba(12,113,149,.55); background:linear-gradient(180deg, rgba(12,113,149,.07), #fff); }
.module-toggle-card span { display:flex; flex-direction:column; gap:3px; }
.module-toggle-card small { color:#64748b; }

.pmis-tour-layer.d-none { display:none !important; }
.pmis-tour-layer {
  position:fixed;
  inset:0;
  z-index:2147483000;
  pointer-events:none;
}
.pmis-tour-backdrop {
  position:absolute;
  inset:0;
  background:rgba(15,23,42,.38);
  backdrop-filter:blur(1px);
  pointer-events:none;
  z-index:2147483001;
}
.pmis-tour-card {
  position:fixed;
  width:min(470px, calc(100vw - 24px));
  border:1px solid rgba(255,255,255,.65);
  background:#fff;
  border-radius:20px;
  box-shadow:0 28px 96px rgba(15,23,42,.42);
  overflow:hidden;
  pointer-events:auto;
  z-index:2147483005;
}
.pmis-tour-card-head { display:flex; justify-content:space-between; gap:16px; align-items:flex-start; padding:16px 18px 10px; border-bottom:1px solid #eef2f7; }
.pmis-tour-kicker { color:#0c7195; font-weight:800; font-size:11px; text-transform:uppercase; letter-spacing:.08em; }
.pmis-tour-title { font-weight:800; color:#0f172a; }
.pmis-tour-body { padding:14px 18px; color:#475569; line-height:1.55; }
.pmis-tour-body p { margin-bottom:10px; }
.pmis-tour-action-note {
  border:1px dashed rgba(12,113,149,.35);
  background:rgba(12,113,149,.06);
  color:#0f5168;
  border-radius:12px;
  padding:9px 10px;
  font-size:13px;
}
.pmis-tour-footer { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:12px 18px 16px; background:#f8fafc; }
.pmis-tour-progress { white-space:nowrap; }
.pmis-tour-highlight {
  position:relative !important;
  z-index:2147483004 !important;
  outline:4px solid rgba(12,113,149,.98) !important;
  outline-offset:5px !important;
  border-radius:12px !important;
  box-shadow:0 0 0 9999px rgba(15,23,42,.04), 0 18px 60px rgba(12,113,149,.34) !important;
  background-color:rgba(255,255,255,.98) !important;
  pointer-events:auto !important;
}
body.pmis-tour-active .topbar,
body.pmis-tour-active .sidebar,
body.pmis-tour-active .main-content,
body.pmis-tour-active .card,
body.pmis-tour-active .pmis-card { overflow:visible !important; }
@media (max-width: 768px) {
  .pmis-tour-card { border-radius:16px; }
  .pmis-tour-footer { flex-wrap:wrap; }
  .pmis-tour-progress { order:-1; width:100%; text-align:center; }
  .pmis-tour-footer .d-flex { width:100%; justify-content:flex-end; }
}
