/* ============================================================
   Project Management System - Main Stylesheet
   Palette: Deep slate navy + warm white + amber accent
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --navy:       #1E2A3A;
  --navy-light: #2C3E52;
  --navy-dark:  #131D28;
  --amber:      #E8A020;
  --amber-light:#F5C355;
  --white:      #FFFFFF;
  --bg:         #F4F6F9;
  --surface:    #FFFFFF;
  --border:     #DDE3EC;
  --text:       #1E2A3A;
  --text-muted: #6B7A8D;
  --danger:     #D94040;
  --success:    #2E8B57;
  --warning:    #E8A020;
  --info:       #3A78C9;
  --sidebar-w:  240px;
  --radius:     8px;
  --shadow:     0 1px 4px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-md:  0 4px 16px rgba(0,0,0,.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
}

.sidebar-logo {
  padding: 24px 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.sidebar-logo .logo-image {
  width: 64px;
  height: auto;
  object-fit: contain;
  margin-bottom: 10px;
}

.sidebar-logo .logo-text {
  font-family: 'DM Sans', sans-serif;
  font-size: .95rem;
  font-weight: 700;
  color: var(--white);
  line-height: 1.4;
  letter-spacing: .01em;
}

.sidebar-logo .logo-text span {
  display: block;
  font-weight: 400;
  font-size: .7rem;
  color: rgba(255,255,255,.5);
}

.sidebar-nav { padding: 12px 0; flex: 1; overflow-y: auto; overflow-x: hidden; }

.nav-group { margin-bottom: 2px; }

.nav-section {
  padding: 10px 18px 4px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}

.nav-section:hover {
  color: rgba(255,255,255,.6);
}

.nav-section-caret {
  font-size: .65rem;
  transition: transform .18s ease;
  color: rgba(255,255,255,.3);
}

.nav-section.collapsed .nav-section-caret {
  transform: rotate(-90deg);
}

.nav-group-items {
  max-height: 1000px;
  overflow: hidden;
  transition: max-height .25s ease;
}

.nav-group-items.collapsed {
  max-height: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 400;
  border-left: 3px solid transparent;
  transition: all .15s;
}

.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: var(--white);
}

.nav-item.active {
  background: rgba(232,160,32,.12);
  color: var(--amber-light);
  border-left-color: var(--amber);
  font-weight: 500;
}

.nav-item .nav-icon { width: 18px; text-align: center; font-size: 1rem; flex-shrink: 0; }

.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--amber);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
  color: var(--navy-dark);
  flex-shrink: 0;
}

.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-size: .8rem; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: .7rem; color: rgba(255,255,255,.45); }

.sidebar-user a.logout { color: rgba(255,255,255,.4); font-size: .8rem; text-decoration: none; }
.sidebar-user a.logout:hover { color: var(--danger); }

/* MAIN CONTENT */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-logo-left {
  height: calc(100% - 14px);
  width: auto;
  max-height: 46px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.topbar-title-centered {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: 'DM Sans', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
  pointer-events: none;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* PAGE CONTENT */
.page-content { padding: 28px; flex: 1; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.card-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
}

.card-body { padding: 20px; }

/* ============================================================
   STATS ROW
   ============================================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 1200px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
  position: relative;
  cursor: grab;
  transition: box-shadow .15s, opacity .15s, transform .15s;
}

.stat-card:active { cursor: grabbing; }

.stat-card.dragging {
  opacity: .4;
  transform: scale(.97);
}

.stat-card:hover .stat-drag-handle {
  opacity: 1;
}

.stat-drag-handle {
  position: absolute;
  top: 8px;
  right: 8px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity .15s;
  font-size: .75rem;
  cursor: grab;
  padding: 4px;
}

.stat-label {
  font-size: .7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value {
  font-family: 'DM Sans', sans-serif;
  font-size: clamp(1rem, 1.6vw, 1.3rem);
  font-weight: 700;
  color: var(--navy);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value.amber { color: var(--amber); }
.stat-value.green { color: var(--success); }
.stat-value.red   { color: var(--danger); }
.stat-sub { font-size: .72rem; color: var(--text-muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; } /* Note: overflow-x blocks sticky — use table-scroll-wrap for sticky headers */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

table.data-table th {
  background: #F8FAFC;
  padding: 10px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #F8FAFC; }

.td-actions { display: flex; gap: 6px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn-primary   { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--navy-light); }

.btn-amber     { background: var(--amber); color: var(--navy-dark); border-color: var(--amber); font-weight: 600; }
.btn-amber:hover { background: var(--amber-light); }

.btn-outline   { background: transparent; color: var(--navy); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }

.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .88; }

.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }

.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-icon { padding: 6px 8px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
.form-grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 18px; }
.form-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--navy); }
.form-label .req { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(232,160,32,.15);
}

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

.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--amber); cursor: pointer; }
.form-check label { font-size: .875rem; cursor: pointer; }

.form-section {
  margin-bottom: 24px;
}

.form-section-title {
  font-family: 'DM Sans', sans-serif;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--amber);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--amber);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Tab navigation for forms */
.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  padding: 8px 14px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.3;
}
.tab-btn .tab-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.tab-btn .tab-amount { font-size: 1.1rem; font-weight: 700; color: var(--navy); font-family: 'DM Sans', sans-serif; }
.tab-btn.active .tab-amount { color: var(--amber); }

.tab-btn:hover { color: var(--navy); }
.tab-btn.active { color: var(--amber); border-bottom-color: var(--amber); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================
   BADGES / STATUS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .73rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-active    { background: #E6F4ED; color: #2E7D50; }
.badge-pending   { background: #FFF3CD; color: #856404; }
.badge-completed { background: #D1ECF1; color: #0C5460; }
.badge-cancelled { background: #F8D7DA; color: #721C24; }
.badge-hold      { background: #E2E3E5; color: #383D41; }
.badge-approved  { background: #E6F4ED; color: #2E7D50; }
.badge-submitted { background: #FFF3CD; color: #856404; }
.badge-reviewed  { background: #D1ECF1; color: #0C5460; }

/* ============================================================
   FLASH MESSAGES
   ============================================================ */
.flash {
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: .875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}

.flash-success { background: #E6F4ED; color: #2E7D50; border-left: 4px solid var(--success); }
.flash-error   { background: #FDE8E8; color: #9B1C1C; border-left: 4px solid var(--danger); }
.flash-warning { background: #FFF3CD; color: #856404; border-left: 4px solid var(--warning); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  width: min(600px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title { font-family: 'DM Sans', sans-serif; font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--amber); }
.breadcrumb .sep { color: var(--border); }
.breadcrumb .current { color: var(--navy); font-weight: 500; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ============================================================
   FINANCIAL SUMMARY GRID
   ============================================================ */
.fin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.fin-cell {
  background: var(--surface);
  padding: 14px 16px;
}

.fin-cell .fin-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 4px; }
.fin-cell .fin-value { font-family: 'DM Sans', sans-serif; font-size: 1.1rem; font-weight: 700; color: var(--navy); }
.fin-cell .fin-value.green { color: var(--success); }
.fin-cell .fin-value.red   { color: var(--danger); }
.fin-cell .fin-value.amber { color: var(--amber); }

/* ============================================================
   SEARCH & FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-box input {
  padding-left: 34px;
}

.search-box .search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: .9rem;
  pointer-events: none;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  background: var(--navy-dark) url('../assets/login_bg.svg') center center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px 36px;
  width: min(420px, 95vw);
  box-shadow: var(--shadow-md);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  justify-content: center;
}

.login-logo .logo-icon {
  width: 42px; height: 42px;
  background: var(--amber);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: var(--navy-dark);
}

.login-logo .logo-text {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.05rem; font-weight: 700; color: var(--navy);
  line-height: 1.3;
}

.login-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.3rem; font-weight: 700; color: var(--navy);
  margin-bottom: 4px;
}
.login-sub { font-size: .85rem; color: var(--text-muted); margin-bottom: 24px; }

/* ============================================================
   UTILITIES
   ============================================================ */
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: .875rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-amber { color: var(--amber); }
.fw-600 { font-weight: 600; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 10px; }
.gap-3 { gap: 16px; }
.flex-1 { flex: 1; }
.w-100 { width: 100%; }

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

.page-header-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}

.page-header-sub {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Sticky table column headers */
.table-scroll-wrap {
  /* No overflow here — would block position:sticky on th */
}
.sticky-thead th {
  position: sticky;
  top: 60px;
  z-index: 10;
  background: #F8FAFC;
  box-shadow: inset 0 -2px 0 var(--border);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
  .sidebar-toggle-btn { display: inline-flex !important; }

  /* The title is normally centered on the whole topbar via absolute
     positioning, which works fine on desktop (plenty of room beside the
     sidebar) but overlaps the logo/hamburger on a narrow mobile topbar.
     Drop it back into normal flow — left-aligned after the logo, truncated
     with an ellipsis instead of wrapping into the actions on the right. */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title-centered {
    position: static;
    transform: none;
    left: auto; top: auto;
    flex: 1;
    min-width: 0;
    margin-left: 8px;
    font-size: 1rem;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Hamburger button that opens the sidebar on mobile — hidden on desktop,
   where the sidebar is already always visible. */
.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  margin-right: 10px;
  color: var(--navy);
  font-size: 1.2rem;
}

/* Dims/blocks the page behind the sidebar while it's open on mobile —
   tapping it closes the sidebar again. */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}
.sidebar-backdrop.open { display: block; }
