/* ==========================================================================
   DAG WORK ALLOCATION, PROGRESS TRACKING & REPORTING SYSTEM
   Office of the Principal Accountant General (A&E), MP, Gwalior
   Completely offline, self-contained CSS (Zero external CDN dependencies)
   ========================================================================== */

:root {
  --primary: #1e3a8a;          /* Deep Government Navy */
  --primary-hover: #172554;
  --primary-light: #eff6ff;
  --secondary: #0f766e;        /* Dark Teal */
  --accent: #b45309;           /* Amber/Gold */
  
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  --border-color: #cbd5e1;
  --border-light: #e2e8f0;
  
  --status-urgent: #dc2626;
  --status-high: #ea580c;
  --status-medium: #d97706;
  --status-low: #059669;
  
  --status-not-started: #64748b;
  --status-in-progress: #2563eb;
  --status-awaiting: #d97706;
  --status-submitted: #7c3aed;
  --status-returned: #dc2626;
  --status-closed: #16a34a;
  --status-cancelled: #475569;
  
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   TOP HEADER & BRANDING
   ========================================================================== */
.office-header {
  background: linear-gradient(180deg, #1e3a8a 0%, #172554 100%);
  color: #ffffff;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--accent);
}

.office-branding {
  display: flex;
  align-items: center;
  gap: 16px;
}

.office-emblem {
  width: 48px;
  height: 48px;
  background-color: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
  color: #fde047;
}

.office-emblem-img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  background-color: #ffffff;
  border-radius: 50%;
  padding: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.7);
  display: block;
}

.office-titles h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.office-titles h2 {
  font-size: 13px;
  font-weight: 500;
  color: #93c5fd;
}

.header-user-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.section-switcher-form select {
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.section-switcher-form select option {
  color: #0f172a;
  background-color: #ffffff;
}

.user-badge {
  display: flex;
  flex-direction: column;
  text-align: right;
  font-size: 12px;
}
.user-badge .user-name {
  font-weight: 600;
  color: #ffffff;
}
.user-badge .user-role {
  font-size: 11px;
  color: #bfdbfe;
}

.btn-header-logout {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.btn-header-logout:hover {
  background: #dc2626;
  border-color: #dc2626;
  text-decoration: none;
}

/* ==========================================================================
   NAVIGATION BAR
   ========================================================================== */
.main-nav {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 4px;
}

.nav-links li a {
  display: block;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
}

.nav-links li a:hover {
  color: var(--primary);
  background-color: var(--primary-light);
  text-decoration: none;
}

.nav-links li.active a {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
  background-color: var(--primary-light);
}

.nav-right-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notification-badge-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  font-size: 12px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.notification-badge-btn .badge {
  background-color: var(--status-urgent);
  color: #ffffff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: bold;
}

/* ==========================================================================
   MAIN LAYOUT & CONTAINERS
   ========================================================================== */
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

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

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

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

/* ==========================================================================
   CARDS & STATS GRID
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-card.urgent { border-left: 4px solid var(--status-urgent); }
.stat-card.urgent .stat-value { color: var(--status-urgent); }

.stat-card.warning { border-left: 4px solid var(--status-medium); }
.stat-card.warning .stat-value { color: var(--status-medium); }

.stat-card.success { border-left: 4px solid var(--status-closed); }
.stat-card.success .stat-value { color: var(--status-closed); }

.stat-card.info { border-left: 4px solid var(--primary); }
.stat-card.info .stat-value { color: var(--primary); }

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header {
  background-color: #ffffff;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 20px;
}

/* ==========================================================================
   TABLES
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

table.data-table th {
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

table.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

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

table.data-table tbody tr:nth-child(even) {
  background-color: #fcfdfe;
}

/* ==========================================================================
   BADGES & PILLS
   ========================================================================== */
.badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.badge-urgent { background: #fee2e2; color: #991b1b; border: 1px solid #f87171; }
.badge-high { background: #ffedd5; color: #9a3412; border: 1px solid #fb923c; }
.badge-medium { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.badge-low { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }

.badge-status-in-prog { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.badge-status-awaiting { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.badge-status-submitted { background: #f3e8ff; color: #6b21a8; border: 1px solid #d8b4fe; }
.badge-status-returned { background: #fee2e2; color: #991b1b; border: 1px solid #f87171; }
.badge-status-closed { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.badge-status-cancelled { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.badge-status-not-started { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

.badge-overdue {
  background: #dc2626;
  color: #ffffff;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  animation: pulse-border 2s infinite;
}

.badge-due-soon {
  background: #f59e0b;
  color: #ffffff;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }

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

.btn-secondary {
  background-color: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-secondary:hover { background-color: var(--bg-subtle); color: var(--text-primary); }

.btn-success {
  background-color: var(--status-closed);
  color: #ffffff;
}
.btn-success:hover { background-color: #15803d; }

.btn-danger {
  background-color: var(--status-urgent);
  color: #ffffff;
}
.btn-danger:hover { background-color: #b91c1c; }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ==========================================================================
   FORMS & INPUTS
   ========================================================================== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--status-urgent);
  margin-left: 2px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30, 58, 138, 0.15);
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.form-help {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Filter bar */
.filter-bar {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

/* ==========================================================================
   ALERTS & NOTICES
   ========================================================================== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* ==========================================================================
   TIMELINE (PROGRESS HISTORY)
   ========================================================================== */
.timeline {
  position: relative;
  padding-left: 28px;
  margin-top: 16px;
}
.timeline::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 10px;
  width: 2px;
  background-color: var(--border-light);
}

.timeline-item {
  position: relative;
  margin-bottom: 20px;
}

.timeline-marker {
  position: absolute;
  left: -28px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--primary);
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px var(--border-color);
}

.timeline-content {
  background-color: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ==========================================================================
   PROGRESS BAR
   ========================================================================== */
.progress-track {
  width: 100%;
  height: 10px;
  background-color: var(--bg-subtle);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.progress-fill {
  height: 100%;
  background-color: var(--primary);
  border-radius: 5px;
  transition: width 0.3s ease;
}

/* ==========================================================================
   WORK DETAIL RESPONSIVE GRID
   ========================================================================== */
.work-detail-grid {
  display: grid;
  grid-template-columns: 2.2fr 1fr;
  gap: 24px;
  align-items: start;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.app-footer {
  background-color: #ffffff;
  border-top: 1px solid var(--border-light);
  padding: 16px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 40px;
}

/* ==========================================================================
   MOBILE & TOUCH ERGONOMICS OPTIMIZATIONS (Tablets & Smartphones)
   ========================================================================== */

/* Coarse pointer (touchscreens): enforce minimum touch targets */
@media (pointer: coarse) {
  .btn, .btn-sm, button, a.badge {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
}

/* Tablets and small laptops (<= 992px) */
@media (max-width: 992px) {
  .work-detail-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* Mobile Devices (<= 768px) */
@media (max-width: 768px) {
  body {
    font-size: 13.5px;
  }

  .app-container {
    padding: 10px 12px !important;
  }

  /* Header Optimization for Mobile */
  .office-header {
    padding: 8px 12px !important;
    flex-wrap: wrap;
    position: relative;
  }

  .office-branding {
    gap: 8px !important;
    max-width: calc(100% - 44px);
  }

  .office-emblem-img {
    width: 36px !important;
    height: 36px !important;
    padding: 2px !important;
  }

  .office-titles h1 {
    font-size: 11.5px !important;
    letter-spacing: 0.2px;
    line-height: 1.25;
  }

  .office-titles h2 {
    font-size: 10.5px !important;
    line-height: 1.2;
  }

  /* Mobile Hamburger Toggle Button */
  .mobile-nav-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    border-radius: var(--radius-sm);
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
    margin-left: auto;
    transition: background 0.15s ease;
  }
  .mobile-nav-toggle:active {
    background: rgba(255, 255, 255, 0.3) !important;
  }

  /* Header User Controls in Mobile Dropdown Drawer */
  .header-user-controls {
    display: none !important;
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    background: rgba(15, 23, 42, 0.85);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .header-user-controls.active {
    display: flex !important;
  }

  .user-badge {
    text-align: left !important;
    background: rgba(255, 255, 255, 0.08);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
  }
  .user-badge .user-name {
    font-size: 13px;
  }
  .user-badge .user-role {
    font-size: 11px;
  }

  .section-switcher-form {
    width: 100%;
  }

  .section-switcher-form select {
    width: 100%;
    font-size: 14px !important;
    padding: 8px 10px !important;
    background: #1e293b !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.3);
  }

  .header-action-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
  }

  .btn-header-pwd, .btn-header-logout {
    flex: 1;
    text-align: center;
    padding: 8px 10px !important;
    font-size: 12.5px !important;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Horizontal Scrollable Nav Tabs on Mobile */
  .main-nav {
    padding: 0 8px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none;
    justify-content: flex-start !important;
    background: #ffffff;
    border-bottom: 2px solid var(--border-light);
  }
  .main-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-links {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 2px;
  }

  .nav-links li a {
    padding: 10px 12px !important;
    font-size: 12.5px !important;
    white-space: nowrap !important;
  }

  .nav-right-actions {
    margin-left: 6px;
    flex-shrink: 0;
  }

  /* Page Header & Actions on Mobile */
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    margin-bottom: 14px !important;
    padding-bottom: 10px !important;
  }

  .page-header h2 {
    font-size: 17px !important;
  }

  .page-header-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .page-header-actions .btn {
    flex: 1 !important;
    min-width: 120px !important;
    text-align: center !important;
    padding: 8px 10px !important;
    font-size: 12px !important;
    min-height: 40px;
  }

  /* Dashboard Stats Grid (Clean 2-Column Mobile Layout) */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 14px !important;
  }

  .stat-card {
    padding: 10px !important;
    border-radius: var(--radius-sm) !important;
  }

  .stat-card .stat-label {
    font-size: 10px !important;
    line-height: 1.25 !important;
    margin-bottom: 4px !important;
  }

  .stat-card .stat-value {
    font-size: 20px !important;
  }

  /* Form Elements: 16px Font Prevents iOS / Android Auto-Zoom */
  .form-control, 
  select.form-control, 
  textarea.form-control, 
  input.form-control {
    font-size: 16px !important;
    min-height: 44px !important;
    padding: 8px 12px !important;
    border-radius: var(--radius-sm);
  }

  .form-row {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Cards & Body on Mobile */
  .card {
    margin-bottom: 14px !important;
    border-radius: var(--radius-sm) !important;
  }

  .card-header {
    padding: 10px 12px !important;
    flex-wrap: wrap;
    gap: 6px;
  }

  .card-header h3 {
    font-size: 13.5px !important;
  }

  .card-body {
    padding: 12px !important;
  }

  /* Tables: Touch-friendly horizontal swipe */
  .table-responsive {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }

  table.data-table th, table.data-table td {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* Direct Allotment Quick Buttons in Dashboard */
  .card div[style*="display: flex; flex-wrap: wrap; gap: 10px;"] {
    gap: 6px !important;
  }

  .card div[style*="display: flex; flex-wrap: wrap; gap: 10px;"] .btn {
    width: 100% !important;
    justify-content: flex-start !important;
    font-size: 12px !important;
    padding: 8px 10px !important;
    min-height: 40px !important;
  }

  /* Modal Dialogs on Mobile */
  div[id$="Modal"] > div {
    width: 95% !important;
    margin: 10px !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }

  /* Footer */
  .app-footer {
    padding: 14px 10px !important;
    margin-top: 20px !important;
    font-size: 11px !important;
  }
}

/* Very Small Mobile Screens (<= 380px) */
@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
  .office-titles h1 {
    font-size: 10.5px !important;
  }
}
