/* ==========================================================================
   1. THEME, VARIABLES & GLOBAL RESET
   ========================================================================== */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #0f172a;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 0.5rem;
  --font: "Inter", sans-serif;
}

.cora-os {
  font-family: var(--font);
  color: var(--text);
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* ==========================================================================
   2. HEADER & SEARCH BAR
   ========================================================================== */
.cora-os .cora-header {
  display: flex !important;
  flex-wrap: nowrap !important;
  justify-content: space-between !important;
  align-items: center !important;
  margin-bottom: 32px !important;
  padding-bottom: 24px !important;
  border-bottom: 1px solid #e2e8f0 !important;
  gap: 24px !important;
}

.cora-os .cora-header-left {
  flex-shrink: 0;
  min-width: 200px;
}

.cora-os .cora-header-left h2 {
  margin: 0 0 4px 0 !important;
  font-size: 24px !important;
  letter-spacing: -0.5px !important;
  color: #0f172a !important;
  line-height: 1.2 !important;
}

/* --- Search Bar --- */
.header-search-wrap {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 18px;
  pointer-events: none;
  z-index: 2;
}

.header-search-inp {
  width: 100%;
  height: 44px !important;
  padding: 0 16px 0 42px !important;
  border: 1px solid transparent !important;
  border-radius: 10px !important;
  font-size: 14px !important;
  background: #f1f5f9 !important;
  box-sizing: border-box !important;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  color: #0f172a !important;
  box-shadow: none !important;
}

.header-search-inp:focus {
  background: #ffffff !important;
  border-color: #e2e8f0 !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
  outline: none !important;
}

.cora-os .cora-actions {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  flex-shrink: 0;
  min-width: 200px;
  justify-content: flex-end;
  flex-wrap: wrap !important;
}

/* ==========================================================================
   3. BUTTONS (Enhanced & Tactile)
   ========================================================================== */
.cora-os button.btn-pri,
.cora-os button.btn-sec,
.cora-os button.btn-inv {
  appearance: none !important;
  -webkit-appearance: none !important;
  border: none !important;
  background: transparent !important;
  box-sizing: border-box !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  height: 40px !important;
  padding: 0 20px !important;
  min-width: auto !important;
  border-radius: 8px !important;
  font-family: "Inter", system-ui, sans-serif !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  cursor: pointer !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1) !important;
  transform: translateY(0) !important;
}

.cora-os button:active {
  transform: translateY(1px) !important;
  box-shadow: none !important;
}

/* Primary (Dark) */
.cora-os button.btn-pri {
  background-color: #0f172a !important;
  color: #ffffff !important;
  border: 1px solid #0f172a !important;
}
.cora-os button.btn-pri:hover {
  background-color: #1e293b !important;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15) !important;
  transform: translateY(-1px) !important;
}

/* Secondary (White/Outline) */
.cora-os button.btn-sec {
  background-color: #ffffff !important;
  color: #475569 !important;
  border: 1px solid #e2e8f0 !important;
}
.cora-os button.btn-sec:hover {
  background-color: #f8fafc !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
  transform: translateY(-1px) !important;
}

/* ==========================================================================
   4. FILTER BAR & INPUTS
   ========================================================================== */
.filter-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  align-items: flex-end;
  margin-bottom: 25px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.filter-group {
  display: flex;
  flex-direction: column;
  flex: 1 1 160px; /* Responsive Flex Logic */
  min-width: 140px;
}

.filter-group.search-group {
  flex: 2;
  min-width: 220px;
}
.filter-group.fixed-small {
  flex: 0 0 130px;
}
.filter-group.fixed-medium {
  flex: 1 1 180px;
}
.filter-group.reset-group {
  flex: 0 0 auto;
  min-width: auto;
}
.filter-group.dual-group {
  flex-direction: row;
  gap: 10px;
  flex: 2 1 300px;
}

.f-lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
  display: block;
  white-space: nowrap;
}

.f-inp {
  height: 42px !important;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  width: 100%;
  box-sizing: border-box;
  transition: 0.2s;
  color: var(--text);
  min-width: 0;
}

.f-inp:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.1);
  outline: none;
}

.btn-reset {
  height: 42px;
  padding: 0 20px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #475569;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
  transition: 0.2s;
  display: block;
  white-space: nowrap;
}
.btn-reset:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Mobile Filter Toggle */
.mob-filter-head {
  display: none;
}
.mob-toggle-wrap {
  display: none;
  margin-bottom: 15px;
}
.btn-mob-filter {
  background: #fff;
  border: 1px solid #cbd5e1;
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ==========================================================================
   5. LAYOUT GRIDS & CARDS
   ========================================================================== */
.cora-row {
  display: grid;
  gap: 20px;
  margin-bottom: 25px;
}
.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.grid-2 {
  grid-template-columns: 2fr 1fr;
}

.cora-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.stats-card {
  position: relative;
  z-index: 1; /* Stacking context for popups */
  overflow: visible !important;
}

.c-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.c-val {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.prog-wrap {
  height: 8px;
  background: #f1f5f9;
  border-radius: 4px;
  margin-top: 12px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  transition: width 0.6s ease;
}
.prog-text {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  color: #475569;
}

/* ==========================================================================
   6. FEATURE: TIMERS (Disciplined UI)
   ========================================================================== */
.timer-badge {
  font-family: "JetBrains Mono", "Roboto Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.3px;
  transition: all 0.3s ease;
}

.timer-icon {
  opacity: 0.5;
  font-size: 12px;
}
.timer-badge.critical {
  background: #fff7ed;
  color: #c2410c;
  border-color: #ffedd5;
}

/* ==========================================================================
   7. FEATURE: BREAKDOWN POPUPS (Hover + Click)
   ========================================================================== */
/* The Container */
.bk-hover-wrap {
  position: relative;
  display: inline-block;
  cursor: pointer;
  margin-bottom: 5px; /* Spacing */
}

/* The Trigger Text */
.bk-trigger {
  font-size: 11px;
  font-weight: 600;
  color: #3b82f6;
  padding: 4px 0;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.bk-trigger:hover {
  text-decoration: underline;
}

/* The Popup List (Hidden) */
.bk-list {
  display: none;
  position: absolute;
  top: 100%;
  left: -10px;
  min-width: 260px;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05),
    0 0 0 1px rgba(0, 0, 0, 0.02);
  border-radius: 8px;
  z-index: 9999;
  padding: 8px;
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
}

/* Visibility Logic */
.bk-hover-wrap:hover .bk-list,
.bk-hover-wrap.pinned .bk-list {
  display: block;
  animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Popup Arrow */
.bk-list::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 20px;
  width: 12px;
  height: 12px;
  background: #fff;
  transform: rotate(45deg);
  border-left: 1px solid #e2e8f0;
  border-top: 1px solid #e2e8f0;
}

/* List Items */
.bk-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 8px 10px;
  border-bottom: 1px dashed #f1f5f9;
  color: #334155;
  transition: background 0.1s;
  white-space: nowrap;
}
.bk-item:hover {
  background: #f8fafc;
}
.bk-item:last-child {
  border-bottom: none;
}
.bk-val {
  font-weight: 700;
  color: #0f172a;
  margin-left: 15px;
}
.bk-item.empty {
  color: #94a3b8;
  font-style: italic;
  justify-content: center;
  padding: 15px;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================================
   8. FEATURE: BIG CARD LAYOUT
   ========================================================================== */
.big-card-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0;
  align-items: stretch;
}

.big-col-left {
  display: flex;
  flex-direction: column;
  gap: 32px;
  border-right: 1px solid #f1f5f9;
  padding-right: 30px;
}

.big-col-right {
  padding-left: 30px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Anchor for popup positioning in big card */
.sub-stat-block {
  position: relative;
}

/* Override popup style for Big Card to float correctly */
.sub-stat-block .bk-list {
  z-index: 1000 !important;
  top: 110%;
  left: -10px;
}

/* ==========================================================================
   9. TABLES, BADGES & TABS
   ========================================================================== */
.c-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.c-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.c-table th {
  background: #f8fafc;
  padding: 16px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 1px solid var(--border);
}
.c-table td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.c-row:hover {
  background-color: #f8fafc;
  cursor: pointer;
}

/* Badges */
.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
  text-transform: uppercase;
}
.badge.prospect {
  background: #eff6ff;
  color: #3b82f6;
}
.badge.confirmed {
  background: #f0fdf4;
  color: #16a34a;
}
.badge.completed {
  background: #f0fdf4;
  color: #16a34a;
}

/* Tabs */
.view-tabs {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.v-tab {
  padding: 12px 20px;
  font-weight: 600;
  cursor: pointer;
  color: #64748b;
  border-bottom: 2px solid transparent;
}
.v-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ==========================================================================
   10. DRAWERS & MODALS
   ========================================================================== */
.c-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99998;
  visibility: hidden;
  opacity: 0;
  transition: 0.3s;
}
.c-drawer-overlay.open {
  visibility: visible;
  opacity: 1;
}

.c-drawer {
  position: fixed;
  bottom: -100%;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 900px;
  height: 85vh;
  background: #fff;
  z-index: 99999;
  border-radius: 20px 20px 0 0;
  transition: 0.4s;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
}
.c-drawer.open {
  bottom: 0;
}

.drawer-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.drawer-body {
  padding: 30px;
  overflow-y: auto;
  flex: 1;
}
.drawer-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: #fff;
  display: flex;
  gap: 10px;
}

/* Drawer Forms */
.inp-group {
  margin-bottom: 15px;
}
.lbl {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 5px;
}
.inp {
  width: 100%;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
}
.inp-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.btn-save {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-del {
  background: #fee2e2;
  color: #dc2626;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.btn-next {
  background: #3b82f6;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  float: right;
}
.btn-back {
  background: #f1f5f9;
  color: #475569;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
}

/* File Upload & Ledger */
.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  background: #f8fafc;
}
.drop-zone:hover {
  border-color: #3b82f6;
  background: #f0f9ff;
}
.inp-file {
  display: none;
}
.dz-txt {
  font-size: 13px;
  color: #64748b;
  font-weight: 500;
}
.fv a {
  color: #3b82f6;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  display: block;
  margin-bottom: 8px;
}

.step-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.step-tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #94a3b8;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.step-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.step-content {
  display: none;
}
.step-content.active {
  display: block;
}

.ledger-block {
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 10px;
}
.add-box {
  background: #fff;
  padding: 15px;
  border-radius: 8px;
  margin-top: 10px;
}
.grid-3-mini {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 5px;
}
.inp-mini {
  width: 100%;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 12px;
}
.hist-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
  padding: 5px 0;
  align-items: center;
}

/* ==========================================================================
   11. MOBILE RESPONSIVENESS (CONSOLIDATED)
   ========================================================================== */

/* Tablet & Smaller (1024px) */
@media (max-width: 1024px) {
  /* Header Stack */
  .cora-os .cora-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 15px !important;
  }
  .cora-os .cora-header-left {
    order: 1;
  }
  .header-search-wrap {
    width: 100% !important;
    max-width: none !important;
    margin: 5px 0 10px 0 !important;
    order: 2;
  }
  .cora-os .cora-actions {
    width: 100% !important;
    flex-wrap: wrap !important;
    order: 3;
  }
  .cora-os .btn-pri,
  .cora-os .btn-sec {
    flex: 1 !important;
  }

  /* Basic Grids */
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .inp-row {
    grid-template-columns: 1fr;
  }

  /* Filter Sidebar (Mobile Drawer) */
  .mob-toggle-wrap {
    display: block !important;
    margin-bottom: 20px;
  }
  .filter-wrapper {
    display: flex;
    flex-direction: column;
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px !important;
    max-width: 85vw !important;
    background: #fff !important;
    z-index: 99999 !important;
    padding: 25px !important;
    border-left: 1px solid #e2e8f0;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.15) !important;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  .filter-wrapper.open {
    transform: translateX(0);
    display: flex !important;
  }
  .mob-filter-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 15px;
  }
  .mob-filter-title {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
  }
  .mob-filter-close {
    font-size: 24px;
    color: #64748b;
    cursor: pointer;
  }

  /* Reset Drawer Items */
  .filter-group {
    width: 100% !important;
    margin-bottom: 15px;
    min-width: auto;
    flex: none;
  }
  .filter-group.fixed-small {
    flex: none;
  }
  .btn-reset {
    width: 100%;
    margin-top: auto;
  }
}

/* Mobile Phones (768px) */
@media (max-width: 768px) {
  /* Stack Big Card Columns */
  .big-card-grid {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }

  .big-col-left {
    border-right: none !important;
    border-bottom: 1px solid #f1f5f9;
    padding-right: 0 !important;
    padding-bottom: 24px;
    margin-bottom: 24px;
    gap: 24px;
  }
  .big-col-right {
    padding-left: 0 !important;
    padding-top: 10px;
  }

  /* Font Adjustments */
  #val_pipe {
    font-size: 28px !important;
  }
  #val_real,
  #val_conf {
    font-size: 20px !important;
  }
}

/* Small Screens (600px) */
@media (max-width: 600px) {
  /* Full screen main drawers */
  .c-drawer {
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-width: none;
  }
}
