/* KCOAA Finance — Custom Styles */

/* ============================================
   Typography
   ============================================ */

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  background-color: #f4f6f9;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;
  background-color: #212529;
  color: #adb5bd;
  z-index: 1040;
  transition: width 200ms ease;
  overflow-x: hidden;
}

.sidebar-brand {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand a {
  color: #ffffff;
  font-size: 1.1rem;
}

.sidebar-nav {
  padding: 8px 0;
  overflow-y: auto;
}

.sidebar-nav .nav {
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: #adb5bd;
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background-color 150ms ease, color 150ms ease;
  white-space: nowrap;
}

.sidebar-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: #ffffff;
}

.sidebar-link.active {
  background-color: rgba(255, 255, 255, 0.05);
  color: #ffffff;
  border-left-color: #0d6efd;
  font-weight: 500;
}

.sidebar-link.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.sidebar-link > i:first-child {
  font-size: 1.15rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-section-header {
  padding: 16px 16px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #6c757d;
  list-style: none;
}

/* ============================================
   Sidebar submenu (은행 → 일반/장기/퇴직, 보고서 → 엑셀 대조/주간 헌금)
   Opens on hover; .submenu-open pins it while one
   of its pages is active (also the touch path:
   tapping the parent lands on 일반, which pins it).
   ============================================ */

.sidebar-submenu {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-has-submenu:hover > .sidebar-submenu,
.sidebar-submenu.submenu-open {
  display: block;
}

.sidebar-sublink {
  padding: 7px 16px 7px 48px;
  font-size: 0.85rem;
}

.sidebar-submenu-caret {
  font-size: 0.7rem;
  transition: transform 150ms ease;
}

.sidebar-has-submenu:hover .sidebar-submenu-caret {
  transform: rotate(180deg);
}

/* Icon-only sidebar modes have no room for labels — no submenu */
.sidebar-collapsed .sidebar-submenu {
  display: none !important;
}

@media (min-width: 768px) and (max-width: 991.98px) {
  body:not(.sidebar-expanded) .sidebar .sidebar-submenu {
    display: none !important;
  }
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px 0;
}

.sidebar-user .dropdown-toggle::after {
  margin-left: auto;
}

.sidebar-toggle {
  color: #6c757d;
  font-size: 0.85rem;
}

.sidebar-toggle:hover {
  color: #adb5bd;
}

/* ============================================
   Sidebar Collapsed — shared rules
   (applied by .sidebar-collapsed on desktop,
    and by tablet media query via :not(.sidebar-expanded))
   ============================================ */

.sidebar-collapsed .sidebar {
  width: 64px;
}

.sidebar-collapsed .sidebar-label {
  display: none;
}

.sidebar-collapsed .sidebar-section-header {
  height: 0;
  padding: 0;
  margin: 0;
  visibility: hidden;
}

.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding: 10px 0;
  gap: 0;
  border-left: none;
}

.sidebar-collapsed .sidebar-brand a {
  justify-content: center;
}

.sidebar-collapsed .sidebar-collapse-icon {
  transform: rotate(180deg);
}

.sidebar-collapsed .content-wrapper {
  margin-left: 64px;
}

/* Hide dropdown caret when collapsed */
.sidebar-collapsed .sidebar-user .dropdown-toggle::after {
  display: none;
}

/* Dropdown menu pops out to the right when collapsed */
.sidebar-collapsed .sidebar-footer .dropdown-menu {
  position: fixed !important;
  left: 64px !important;
  bottom: 40px;
  top: auto !important;
  transform: none !important;
}

/* ============================================
   Content Wrapper
   ============================================ */

.content-wrapper {
  margin-left: 240px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 200ms ease;
}

/* ============================================
   Top Bar
   ============================================ */

.topbar {
  height: 48px;
  padding: 0 24px;
  background-color: #ffffff;
  border-bottom: 1px solid #dee2e6;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.topbar-title {
  font-size: 1rem;
  color: #212529;
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
  flex-grow: 1;
  padding: 24px;
}

.main-footer {
  padding: 12px 24px;
  border-top: 1px solid #dee2e6;
  font-size: 0.8rem;
}

/* ============================================
   Cards
   ============================================ */

.card {
  transition: box-shadow 0.15s ease-in-out;
}

.card:hover {
  box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.08);
}

/* ============================================
   Login Page
   ============================================ */

.login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

/* ============================================
   Sidebar Overlay (Mobile)
   ============================================ */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1035;
}

/* ============================================
   Responsive: Tablet (768–991px)
   Auto-collapse, expandable via toggle.
   Lower bound matters: these high-specificity selectors would otherwise
   override the mobile (<768px) slide-drawer rules below.
   ============================================ */

@media (min-width: 768px) and (max-width: 991.98px) {
  body:not(.sidebar-expanded) .sidebar {
    width: 64px;
  }

  body:not(.sidebar-expanded) .sidebar .sidebar-label {
    display: none;
  }

  body:not(.sidebar-expanded) .sidebar .sidebar-section-header {
    height: 0;
    padding: 0;
    margin: 0;
    visibility: hidden;
  }

  body:not(.sidebar-expanded) .sidebar .sidebar-link {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
    border-left: none;
  }

  body:not(.sidebar-expanded) .sidebar .sidebar-brand a {
    justify-content: center;
  }

  body:not(.sidebar-expanded) .content-wrapper {
    margin-left: 64px;
  }

  body:not(.sidebar-expanded) .sidebar-collapse-icon {
    transform: rotate(180deg);
  }

  body:not(.sidebar-expanded) .sidebar-user .dropdown-toggle::after {
    display: none;
  }

  body:not(.sidebar-expanded) .sidebar-footer .dropdown-menu {
    position: fixed !important;
    left: 64px !important;
    bottom: 40px;
    top: auto !important;
    transform: none !important;
  }
}

/* ============================================
   Responsive: Mobile (<768px)
   Hidden off-screen, slide-in overlay
   ============================================ */

@media (max-width: 767.98px) {
  .sidebar {
    width: 240px;
    transform: translateX(-100%);
  }

  .sidebar .sidebar-label {
    display: inline;
  }

  .sidebar .sidebar-section-header {
    height: auto;
    padding: 16px 16px 4px;
    visibility: visible;
  }

  .sidebar .sidebar-link {
    justify-content: flex-start;
    padding: 10px 16px;
    gap: 12px;
    border-left-width: 3px;
  }

  .sidebar .sidebar-brand a {
    justify-content: flex-start;
  }

  .content-wrapper {
    margin-left: 0;
  }

  /* Slide in from left */
  body.sidebar-mobile-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-mobile-open .sidebar-overlay {
    display: block;
  }
}

/* ============================================
   Feedback Floating Button
   ============================================ */

.btn-feedback-float {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1020;
  font-size: 1.2rem;
  opacity: 0.85;
  transition: opacity 150ms ease, transform 150ms ease;
}

.btn-feedback-float:hover {
  opacity: 1;
  transform: scale(1.05);
}

@media (max-width: 767.98px) {
  .btn-feedback-float {
    bottom: 16px;
    right: 16px;
  }
}

/* Expandable transaction descriptions (bank statement/reconciliation tables) */
.desc-clip {
  display: inline-block;
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  cursor: pointer;
}

.desc-clip.desc-expanded {
  white-space: normal;
  max-width: none;
  word-break: break-word;
}

/* Reconciliation action cells: single line on desktop, wrap on mobile */
.recon-actions {
  white-space: nowrap;
}

.recon-actions-col {
  min-width: 230px;
}

@media (max-width: 767.98px) {
  .desc-clip {
    max-width: 52vw;
  }

  .recon-actions {
    white-space: normal;
  }

  .recon-actions form,
  .recon-actions .btn-group {
    margin-bottom: 0.25rem;
  }

  .recon-actions-col {
    min-width: 150px;
  }
}

/* Stacked tables on mobile — rows become card-like blocks, no horizontal scroll */
@media (max-width: 767.98px) {
  .table-stack thead {
    display: none;
  }

  .table-stack tbody,
  .table-stack tr,
  .table-stack td {
    display: block;
    width: 100%;
  }

  .table-stack tr {
    border-bottom: 2px solid #dee2e6;
    padding: 0.5rem 0;
  }

  .table-stack td {
    border: 0;
    padding: 0.15rem 0.75rem;
    text-align: left !important;
    white-space: normal;
  }

  .table-stack tr.candidates-row {
    border: 0;
    padding: 0;
  }

  .table-stack .desc-clip {
    max-width: 100%;
  }
}

@media (max-width: 767.98px) {
  .table-stack tr.stack-no-border {
    border-bottom: 0;
    padding-bottom: 0;
  }
}

/* Reconciliation panels (create-entry form / match candidates):
   inline below the row on desktop, bottom-sheet modal on mobile */
@media (max-width: 767.98px) {
  .recon-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    overflow-y: auto;
    z-index: 1055;
    background: #fff !important;
    border-top-left-radius: 0.75rem;
    border-top-right-radius: 0.75rem;
    box-shadow: 0 -0.5rem 1.5rem rgba(0, 0, 0, 0.3);
  }

  .recon-panel::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: -1;
  }
}

/* Long unbreakable words (statement filenames) must not widen the page */
@media (max-width: 767.98px) {
  .breadcrumb-item {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}

/* ============================================
   Reconciliation step indicator (은행 조정)
   Four fixed steps; the workspace body renders
   only the current step's work.
   ============================================ */

.recon-steps {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.recon-step {
  flex: 1;
  position: relative;
  text-align: center;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

/* Connector line into each step (skipped on the first) */
.recon-step::before {
  content: "";
  position: absolute;
  top: 15px;
  left: calc(-50% + 24px);
  width: calc(100% - 48px);
  height: 2px;
  background: var(--bs-border-color);
}

.recon-step:first-child::before {
  display: none;
}

.recon-step.done::before,
.recon-step.current::before {
  background: var(--bs-success);
}

.recon-step .step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  font-weight: 600;
  position: relative;
}

.recon-step .step-label {
  display: block;
  margin-top: 4px;
}

.recon-step.done .step-dot {
  border-color: var(--bs-success);
  color: var(--bs-success);
}

.recon-step.current {
  color: var(--bs-body-color);
  font-weight: 600;
}

.recon-step.current .step-dot {
  border-color: var(--bs-primary);
  background: var(--bs-primary);
  color: #fff;
}

/* ============================================
   Submit lock (static/js/submit_lock.js)
   While a form request is in flight the page
   shows a progress cursor; the clicked button is
   disabled with a spinner by the script.
   ============================================ */
body.is-submitting,
body.is-submitting * {
  cursor: progress !important;
}

/* ============================================
   Practice-site banner (staging, once production exists)
   ============================================ */

.practice-banner {
  position: sticky;
  top: 0;
  z-index: 1050;
  height: 36px;
  line-height: 36px;
  padding: 0 16px;
  background-color: #ffc107;
  color: #212529;
  font-size: 0.875rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.practice-banner a {
  color: #212529;
  font-weight: 600;
}

.practice-site .sidebar {
  top: 36px;
  height: calc(100vh - 36px);
}

.practice-site .topbar {
  top: 36px;
}

.practice-site .content-wrapper {
  min-height: calc(100vh - 36px);
}
