/* ============================================================
   Company Opportunities Tracker — Main Stylesheet
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #1a56db;
  --brand-dark:   #1341b0;
  --brand-light:  #e8f0fe;
  --text:         #1a1a2e;
  --text-muted:   #6b7280;
  --border:       #e5e7eb;
  --bg:           #f3f4f6;
  --card:         #ffffff;
  --sidebar-w:    240px;
  --topbar-h:     56px;
  --radius:       8px;
  --shadow:       0 1px 4px rgba(0,0,0,.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,.1);

  /* Status colours */
  --pending:      #6366f1;
  --inprogress:   #f59e0b;
  --submitted:    #22c55e;
  --ignored:      #9ca3af;
  --missed:       #ef4444;

  /* Relevance colours */
  --extreme:      #dc2626;
  --high:         #ea580c;
  --medium:       #d97706;
  --low:          #64748b;
  --notrelevant:  #9ca3af;
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

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

ul { list-style: none; }

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: #111827;
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid #1f2937;
}
.brand-icon { color: var(--brand); font-size: 1.4rem; }
.brand-icon.large { font-size: 2.5rem; display: block; text-align: center; margin-bottom: 8px; }
.brand-text { font-weight: 700; color: #fff; font-size: 1rem; }

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

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #9ca3af;
  font-size: .9rem;
  transition: background .15s, color .15s;
  border-radius: 0;
}
.nav-link:hover, .nav-link.active {
  background: #1f2937;
  color: #fff;
  text-decoration: none;
}
.nav-icon { width: 18px; text-align: center; font-size: .85rem; }

.nav-divider {
  padding: 12px 16px 4px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #4b5563;
}

.sidebar-user {
  padding: 16px;
  border-top: 1px solid #1f2937;
  font-size: .85rem;
}
.user-name { font-weight: 600; color: #fff; }
.user-role { color: #6b7280; font-size: .8rem; margin-bottom: 8px; }
.logout-link { color: #9ca3af; font-size: .8rem; }
.logout-link:hover { color: #fff; }

/* ---------- Main area ---------- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title { font-size: 1rem; font-weight: 600; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--text);
  padding: 4px;
}

.content { padding: 24px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; }
.card > p,
.card > .table-wrap,
.card > ul,
.card > form { padding: 16px 20px; }
.card > .table-wrap { padding: 0; }

/* ---------- Stats grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-number { font-size: 2.2rem; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.stat-label  { font-size: .8rem; color: var(--text-muted); }

.stat-card.status-pending    { border-top: 3px solid var(--pending); }
.stat-card.status-inprogress { border-top: 3px solid var(--inprogress); }
.stat-card.status-submitted  { border-top: 3px solid var(--submitted); }
.stat-card.status-ignored    { border-top: 3px solid var(--ignored); }
.stat-card.status-missed     { border-top: 3px solid var(--missed); }

/* ---------- Dashboard grid ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.card-full { grid-column: 1 / -1; }

/* ---------- Chart bar ---------- */
.chart-list { padding: 16px 20px; }
.chart-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: .875rem;
}
.chart-label { width: 160px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-bar-wrap { flex: 1; background: var(--border); border-radius: 4px; height: 8px; overflow: hidden; }
.chart-bar { height: 100%; background: var(--brand); border-radius: 4px; min-width: 2px; }
.chart-value { width: 30px; text-align: right; font-weight: 600; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Status badges */
.status-pending    { background: #ede9fe; color: #5b21b6; }
.status-inprogress { background: #fef3c7; color: #92400e; }
.status-submitted  { background: #dcfce7; color: #166534; }
.status-ignored    { background: #f3f4f6; color: #374151; }
.status-missed     { background: #fee2e2; color: #991b1b; }

/* Relevance badges */
.rel-extreme     { background: #fee2e2; color: #991b1b; }
.rel-high        { background: #ffedd5; color: #9a3412; }
.rel-medium      { background: #fef9c3; color: #854d0e; }
.rel-low         { background: #f1f5f9; color: #475569; }
.rel-notrelevant { background: #f3f4f6; color: #9ca3af; }

/* Deadline urgency */
.badge-missed   { background: #fee2e2; color: #991b1b; }
.badge-critical { background: #fef2f2; color: #dc2626; border: 1px solid #fca5a5; }
.badge-urgent   { background: #fffbeb; color: #d97706; border: 1px solid #fcd34d; }
.badge-normal   { background: #f0f9ff; color: #0369a1; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th,
.data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #f9fafb;
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  white-space: nowrap;
}
.data-table th a { color: var(--text-muted); }
.data-table th a:hover { color: var(--brand); text-decoration: none; }
.data-table tbody tr:hover { background: #f9fafb; }
.data-table .td-title { max-width: 240px; }
.data-table .td-biz   { max-width: 160px; font-size: .8rem; color: var(--text-muted); }
.data-table .td-deadline { white-space: nowrap; }
.data-table .td-actions { white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary  { background: var(--brand); color: #fff; }
.btn-primary:hover  { background: var(--brand-dark); color: #fff; text-decoration: none; }
.btn-outline  { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-outline:hover  { background: #f3f4f6; text-decoration: none; }
.btn-danger   { background: #ef4444; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #dc2626; text-decoration: none; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm   { padding: 6px 12px; font-size: .8rem; }
.btn-xs   { padding: 3px 8px; font-size: .75rem; }

/* ---------- Forms ---------- */
.form-card { padding: 24px; }
.form-card-narrow { max-width: 540px; }
.form-section { margin-bottom: 28px; }
.form-section h3 { margin-bottom: 16px; font-size: .95rem; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: 8px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="url"],
.form-group input[type="tel"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="datetime-local"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-hint { font-size: .78rem; color: var(--text-muted); margin-top: 4px; display: block; }

.req { color: var(--missed); }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .875rem;
  cursor: pointer;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: background .1s;
}
.checkbox-label:hover { background: var(--brand-light); }
.checkbox-label input[type="checkbox"] { accent-color: var(--brand); width: 15px; height: 15px; }

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.form-group-actions { display: flex; align-items: flex-end; gap: 8px; }

/* ---------- Filters ---------- */
.filter-card { padding: 16px 20px; }
.filter-form .form-group { margin-bottom: 0; }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
}
.filter-row .form-group { flex: 1; min-width: 140px; }
.filter-row:last-child { margin-bottom: 0; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: .875rem;
}
.alert ul { margin-top: 6px; padding-left: 18px; list-style: disc; }
.alert-success { background: #dcfce7; border-left: 4px solid #22c55e; color: #166534; }
.alert-error   { background: #fee2e2; border-left: 4px solid #ef4444; color: #991b1b; }
.alert-warning { background: #fffbeb; border-left: 4px solid #f59e0b; color: #92400e; }
.alert-info    { background: #eff6ff; border-left: 4px solid #3b82f6; color: #1d4ed8; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  gap: 6px;
  padding: 16px 20px;
  flex-wrap: wrap;
}
.page-link {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: .8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .1s;
}
.page-link:hover  { background: var(--brand-light); color: var(--brand); text-decoration: none; }
.page-link.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Empty state ---------- */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ---------- Opportunity detail ---------- */
.opp-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.opp-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.opp-actions { display: flex; gap: 8px; }

.opp-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
.opp-sidebar { display: flex; flex-direction: column; gap: 16px; }

.detail-group {
  display: flex;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}
.detail-group:last-child { border-bottom: none; }
.detail-label { width: 140px; flex-shrink: 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 500; padding-top: 2px; }
.detail-value { flex: 1; font-size: .9rem; }
.detail-multiline { white-space: pre-wrap; word-break: break-word; }
.detail-notes { background: #fffbeb; padding: 10px; border-radius: 4px; border: 1px solid #fcd34d; }

.tag {
  display: inline-block;
  padding: 2px 10px;
  background: var(--brand-light);
  color: var(--brand);
  border-radius: 999px;
  font-size: .78rem;
  margin: 2px 2px 2px 0;
  font-weight: 500;
}

/* ---------- Activity log ---------- */
.activity-list { padding: 12px 20px; }
.activity-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-action { font-weight: 600; font-size: .8rem; text-transform: capitalize; display: block; }
.activity-detail { font-size: .8rem; color: var(--text-muted); display: block; }
.activity-meta   { font-size: .75rem; color: #9ca3af; display: block; margin-top: 2px; }

/* ---------- Danger zone ---------- */
.danger-zone { border-color: #fee2e2; }
.danger-zone .card-header { background: #fef2f2; }

/* ---------- Login page ---------- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a56db 0%, #0f3a8a 100%);
  min-height: 100vh;
}
.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 1.4rem; color: var(--text); margin-top: 8px; }
.login-logo p  { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ---------- Text utilities ---------- */
.text-muted   { color: var(--text-muted); }
.text-success { color: #16a34a; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .opp-grid { grid-template-columns: 1fr; }
  .opp-sidebar { order: -1; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .filter-row { flex-direction: column; }
  .filter-row .form-group { min-width: unset; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .opp-detail-header { flex-direction: column; align-items: flex-start; }
  .form-actions { flex-direction: column; }
  .toolbar { flex-direction: column; }
}

@media (max-width: 480px) {
  .login-card { padding: 24px; margin: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .data-table { font-size: .8rem; }
  .data-table th, .data-table td { padding: 8px; }
}

/* ============================================================
   Asset Management — Badge styles
   ============================================================ */

/* --- Asset condition badges --- */
.asset-cond-new      { background: #dcfce7; color: #166534; }   /* positive */
.asset-cond-good     { background: #dcfce7; color: #166534; }   /* positive */
.asset-cond-fair     { background: #fef9c3; color: #854d0e; }   /* neutral  */
.asset-cond-damaged  { background: #fee2e2; color: #991b1b; }   /* serious  */
.asset-cond-repair   { background: #ffedd5; color: #9a3412; }   /* serious  */
.asset-cond-broken   { background: #fee2e2; color: #991b1b; }   /* serious  */
.asset-cond-missing  { background: #fce7f3; color: #9d174d; }   /* serious  */
.asset-cond-disposed { background: #f3f4f6; color: #6b7280; }   /* muted    */

/* --- Asset operational status badges --- */
.asset-stat-available    { background: #dcfce7; color: #166534; }  /* positive */
.asset-stat-inuse        { background: #dbeafe; color: #1e40af; }  /* active   */
.asset-stat-storage      { background: #fef9c3; color: #854d0e; }  /* neutral  */
.asset-stat-repair       { background: #ffedd5; color: #9a3412; }  /* active   */
.asset-stat-transferred  { background: #e0f2fe; color: #0369a1; }  /* neutral  */
.asset-stat-replaced     { background: #f3f4f6; color: #6b7280; }  /* muted    */
.asset-stat-retired      { background: #f3f4f6; color: #6b7280; }  /* muted    */
.asset-stat-missing      { background: #fce7f3; color: #9d174d; }  /* serious  */
.asset-stat-disposed     { background: #f3f4f6; color: #9ca3af; }  /* muted    */

/* --- Issue status badges --- */
.issue-open     { background: #fee2e2; color: #991b1b; }
.issue-review   { background: #fef9c3; color: #854d0e; }
.issue-resolved { background: #dcfce7; color: #166534; }
.issue-rejected { background: #f3f4f6; color: #6b7280; }

/* --- Asset detail page layout (mirrors .opp-grid) --- */
.asset-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
.asset-sidebar { display: flex; flex-direction: column; gap: 16px; }

/* Asset photo */
.asset-photo {
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  margin: 12px 20px;
}

/* History trail */
.event-list { padding: 12px 20px; }
.event-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.event-item:last-child { border-bottom: none; }
.event-type  { font-weight: 600; font-size: .8rem; text-transform: capitalize; display: block; }
.event-vals  { font-size: .8rem; color: var(--text-muted); display: block; }
.event-notes { font-size: .8rem; font-style: italic; color: var(--text-muted); display: block; }
.event-meta  { font-size: .75rem; color: #9ca3af; display: block; margin-top: 2px; }

/* Import results table */
.import-summary { padding: 16px 20px; }
.import-summary .stat-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.import-stat { text-align: center; }
.import-stat .num { font-size: 2rem; font-weight: 700; line-height: 1; }
.import-stat .lbl { font-size: .75rem; color: var(--text-muted); }
.import-stat.ok  .num { color: #16a34a; }
.import-stat.err .num { color: #dc2626; }
.import-stat.wrn .num { color: #d97706; }
.import-stat.ski .num { color: #6b7280; }

/* Asset file link */
.asset-file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .875rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 8px 20px;
}

/* Archived asset row */
.data-table tr.row-archived td { opacity: .55; }

@media (max-width: 1024px) {
  .asset-grid { grid-template-columns: 1fr; }
  .asset-sidebar { order: -1; }
}
