* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f4f6f8;
  color: #1f2937;
  font-size: 13px;
}
.appWrap { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 230px;
  background: #1e3a5f;
  color: white;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar h2 { font-size: 14px; padding: 16px; margin: 0; border-bottom: 1px solid #2a4a73; }
.sidebar .navItem {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #2a4a73;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar .navItem:hover { background: #2a4a73; }
.sidebar .navItem.active { background: #2a4a73; border-left: 3px solid #4fc3f7; }
.sidebar .navItem .badge {
  background: #4fc3f7;
  color: #1e3a5f;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
}
.sidebar .navItem.locked { opacity: 0.4; cursor: not-allowed; }
.sidebar .userInfo {
  padding: 12px 16px;
  background: rgba(0,0,0,0.2);
  font-size: 11px;
}
.sidebar .userInfo .name { font-weight: 600; margin-bottom: 4px; }
.sidebar .logout {
  display: block;
  width: 100%;
  background: #c0392b;
  color: white;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 12px;
}
.sidebar .logout:hover { background: #e74c3c; }

/* Main */
.main { flex: 1; padding: 16px; overflow: hidden; }
.headerBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.headerBar h1 { font-size: 18px; margin: 0; color: #1e3a5f; }
.statusBar { font-size: 11px; color: #6b7280; }

/* KPI cards */
.kpiRow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.kpiCard {
  background: white;
  padding: 12px;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  border-left: 4px solid #1e3a5f;
}
.kpiCard.kpiAlert { border-color: #dc2626; }
.kpiCard.kpiWarn { border-color: #f59e0b; }
.kpiCard.kpiOk { border-color: #10b981; }
.kpiCard .label { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; }
.kpiCard .value { font-size: 24px; font-weight: 700; color: #1f2937; margin-top: 4px; }
.kpiCard .sub { font-size: 11px; color: #9ca3af; margin-top: 2px; }

/* Filter bar */
.filterBar {
  background: white;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.filterBar label { font-size: 12px; font-weight: 600; color: #4b5563; }
.filterBar select, .filterBar input {
  padding: 5px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
}
.filterBar input.search { min-width: 200px; }
.filterBar .saveBtn {
  margin-left: auto;
  background: #1e3a5f;
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.filterBar .saveBtn:hover { background: #2a4a73; }
.filterBar .countDisplay { font-size: 11px; color: #6b7280; margin-left: 8px; }

/* Table */
.tableWrap {
  background: white;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  overflow: auto;
  max-height: calc(100vh - 280px);
}
table.dataTable {
  border-collapse: collapse;
  width: max-content;
  table-layout: fixed;
  font-size: 11px;
}
.dataTable th {
  background: #1e3a5f;
  color: white;
  padding: 8px 6px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 5;
  font-weight: 600;
  font-size: 10px;
  white-space: normal;
  word-wrap: break-word;
  vertical-align: top;
  border-right: 1px solid #2a4a73;
}
.dataTable td {
  padding: 6px;
  border-bottom: 1px solid #e5e7eb;
  border-right: 1px solid #f3f4f6;
  vertical-align: top;
  word-wrap: break-word;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.dataTable tr:hover td { background: #f9fafb; }
.dataTable tr.dimmed td { background: #fef9c3; color: #713f12; font-style: italic; }
.dataTable tr.dimmed:hover td { background: #fef08a; }
.dataTable tr.dimmed td:first-child + td { font-weight: 600; }
.dataTable .editableCell {
  background: #fefce8;
  cursor: text;
  min-height: 22px;
}
.dataTable .editableCell:focus {
  outline: 2px solid #4fc3f7;
  background: white;
}
.dataTable select.cellSelect {
  width: 100%;
  border: 1px solid transparent;
  background: #fefce8;
  padding: 3px;
  font-size: 11px;
}
.dataTable select.cellSelect:focus { outline: 2px solid #4fc3f7; background: white; }
.dataTable input.cellDate {
  width: 100%;
  border: 1px solid transparent;
  background: #fefce8;
  padding: 3px;
  font-size: 11px;
}
.dataTable input.cellDate:focus { outline: 2px solid #4fc3f7; background: white; }

/* Badges */
.badgeRow { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 2px; }
.badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.badgeRBI { background: #fee2e2; color: #991b1b; }
.badge.badgeMA { background: #fef3c7; color: #92400e; }
.badge.badgeNew { background: #d1fae5; color: #065f46; }
.badge.badgeOpen { background: #f3f4f6; color: #6b7280; }
.badge.badgeDup { background: #e0e7ff; color: #3730a3; }

/* Expand button */
.expandBtn {
  background: none;
  border: 1px solid #d1d5db;
  padding: 1px 6px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 10px;
  color: #4b5563;
}
.expandBtn:hover { background: #f3f4f6; }
.expandRow td {
  background: #f9fafb !important;
  padding: 12px 16px;
}
.expandRow .expandPanel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
}
.expandRow .expandField {
  border-left: 3px solid #1e3a5f;
  padding-left: 8px;
}
.expandRow .expandField .lbl { font-size: 10px; color: #6b7280; text-transform: uppercase; font-weight: 600; }
.expandRow .expandField .val { font-size: 11px; color: #1f2937; margin-top: 2px; white-space: pre-wrap; word-wrap: break-word; }

/* Login overlay */
.loginOverlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1e3a5f 0%, #2a4a73 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.loginCard {
  background: white;
  border-radius: 12px;
  padding: 32px;
  width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  text-align: center;
}
.loginCard .logo {
  width: 60px;
  height: 60px;
  background: #1e3a5f;
  border-radius: 12px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}
.loginCard h2 { font-size: 18px; color: #1e3a5f; margin: 0 0 4px; }
.loginCard .subtitle { font-size: 12px; color: #6b7280; margin-bottom: 24px; }
.loginCard .msBtn {
  width: 100%;
  background: white;
  border: 1px solid #d1d5db;
  padding: 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.loginCard .msBtn:hover { background: #f9fafb; }
.loginCard .msIcon {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: 18px;
  height: 18px;
  gap: 1px;
}
.loginCard .msIcon span { display: block; }
.loginCard .msIcon span:nth-child(1) { background: #f25022; }
.loginCard .msIcon span:nth-child(2) { background: #7fba00; }
.loginCard .msIcon span:nth-child(3) { background: #00a4ef; }
.loginCard .msIcon span:nth-child(4) { background: #ffb900; }
.loginCard hr { margin: 20px 0; border: none; border-top: 1px solid #e5e7eb; }
.loginCard .footer { font-size: 11px; color: #6b7280; }
.loginCard .errorMsg { color: #dc2626; font-size: 12px; margin: 12px 0; min-height: 18px; }
.loginCard .jsReady { color: #10b981; font-size: 11px; margin-top: 8px; display: none; }
.loginCard .jsReady.visible { display: block; }

/* Toast */
.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: #1f2937;
  color: white;
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 10000;
  font-size: 13px;
  max-width: 350px;
  display: none;
}
.toast.success { background: #047857; }
.toast.error { background: #b91c1c; }
.toast.show { display: block; }

/* Misc */
.hidden { display: none !important; }
.diagBanner {
  background: #fee2e2;
  color: #991b1b;
  padding: 8px 12px;
  font-size: 11px;
  border-radius: 4px;
  margin-bottom: 8px;
  display: none;
}
.diagBanner.visible { display: block; }
.dupNote {
  font-size: 10px;
  color: #6366f1;
  font-style: italic;
}
.adminPanel {
  background: white;
  border-radius: 6px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 12px;
}
.adminPanel h3 { font-size: 14px; margin: 0 0 12px; color: #1e3a5f; }
.adminPanel .adminGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.adminPanel .adminGrid > div {
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 10px;
}
.adminPanel button {
  background: #1e3a5f;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  margin-top: 6px;
}
