/* journal.css - Professional organized styling for Journal module */
/* Root namespace */
#journal-modal .modal-content {
  max-width: 1400px;
  width: 96%;
  background: var(--surface, #1e252d);
  color: var(--text-primary, #e5e7eb);
  font-size: .85rem;
  line-height: 1.5;
}

#journal-modal .modal-body {
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 82vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.journal-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.journal-toolbar {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border, #2d3b46);
  background: #11181f;
  position: sticky;
  top: 0;
  z-index: 5;
  /* Ensure content below isn't covered when toolbar becomes sticky */
  margin-bottom: .5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.journal-toolbar h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: .5px;
  white-space: nowrap;
  min-width: fit-content;
}

.journal-toolbar .grow {
  flex: 1 1 auto;
  min-width: 120px;
}

.journal-toolbar input,
.journal-toolbar select {
  background: #0f1720;
  border: 1px solid #2d3b46;
  color: #e5e7eb;
  padding: .55rem .7rem;
  font-size: .78rem;
  border-radius: 6px;
  min-width: 0;
  flex-shrink: 0;
}

.journal-toolbar .btn {
  background: #1f2933;
  color: #e5e7eb;
  border: 1px solid #2d3b46;
  padding: .6rem 1rem;
  font-size: .72rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: fit-content;
  flex-shrink: 0;
  touch-action: manipulation;
}

.journal-toolbar .btn.primary {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #0f1115;
}

.journal-toolbar .btn.danger {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

.journal-toolbar .btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.journal-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  min-height: 0;
}

.journal-main.single-column {
  grid-template-columns: 1fr;
}

.journal-list-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border, #2d3b46);
  min-height: 0;
}

.journal-detail-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Journal list */
.journal-table-wrap {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

table.journal-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
  font-size: .8rem;
  table-layout: fixed;
  min-width: 800px;
  /* Ensure minimum width for desktop experience */
}

/* Hide card layout on desktop */
.journal-entries-cards {
  display: none;
}

table.journal-table thead th {
  text-align: left;
  background: #0f1720;
  padding: .65rem .8rem;
  font-size: .68rem;
  letter-spacing: .55px;
  text-transform: uppercase;
  font-weight: 600;
  color: #7dd3fc;
  position: sticky;
  top: 0;
  z-index: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Column width specifications for better content distribution */
table.journal-table th:nth-child(1),
table.journal-table td:nth-child(1) {
  width: 10%;
  /* Date */
}

table.journal-table th:nth-child(2),
table.journal-table td:nth-child(2) {
  width: 12%;
  /* Journal Number */
}

table.journal-table th:nth-child(3),
table.journal-table td:nth-child(3) {
  width: 18%;
  /* Reference */
  white-space: normal;
  text-overflow: initial;
}

table.journal-table th:nth-child(4),
table.journal-table td:nth-child(4) {
  width: 25%;
  /* Description */
  white-space: normal;
  text-overflow: initial;
}

table.journal-table th:nth-child(5),
table.journal-table td:nth-child(5) {
  width: 10%;
  /* Status */
  text-align: center;
}

table.journal-table th:nth-child(6),
table.journal-table td:nth-child(6) {
  width: 10%;
  /* Source */
  text-align: center;
}

table.journal-table th:nth-child(7),
table.journal-table td:nth-child(7) {
  width: 10%;
  /* Total */
  text-align: right;
}

table.journal-table th:nth-child(8),
table.journal-table td:nth-child(8) {
  width: 10%;
  /* Balanced */
  text-align: center;
}

table.journal-table th:last-child,
table.journal-table td:last-child {
  width: 5%;
  /* Actions */
  text-align: center;
  position: relative;
}

table.journal-table tbody tr {
  background: #141a20;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}

table.journal-table tbody tr:hover {
  background: #1c242c;
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .55);
}

table.journal-table tbody td {
  padding: .65rem .85rem;
  border: 0;
  vertical-align: middle;
  font-size: .72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Allow text wrapping for reference and description columns */
table.journal-table tbody td:nth-child(3),
table.journal-table tbody td:nth-child(4) {
  white-space: normal;
  text-overflow: initial;
  word-wrap: break-word;
  max-height: 3em;
  overflow: hidden;
}

table.journal-table tbody td:first-child {
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

table.journal-table tbody td:last-child {
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}

.je-status {
  display: inline-block;
  padding: .3rem .55rem;
  border-radius: 14px;
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.je-status.posted {
  background: #083a33;
  color: #5eead4;
}

.je-status.draft {
  background: #374151;
  color: #cbd5e1;
}

.je-status.reversal {
  background: #3f2d1c;
  color: #fbbf24;
}

.je-status.reversed {
  background: #334155;
  color: #e2e8f0;
}

.balanced-indicator {
  font-size: .68rem;
  font-weight: 600;
  padding: .35rem .6rem;
  border-radius: 30px;
  background: #1f3535;
  color: #5eead4;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

.unbalanced-indicator {
  background: #4f2631;
  color: #fecaca;
}

/* Detail */
.journal-detail-empty {
  padding: 1.5rem;
  font-size: .9rem;
  color: #94a3b8;
}

.journal-meta {
  padding: 1.1rem 1.25rem .65rem;
  border-bottom: 1px solid #2d3b46;
  font-size: .85rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.journal-meta h4 {
  margin: 0 0 .5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
}

.journal-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.journal-meta-row span.label {
  opacity: .6;
}

.journal-lines-wrap {
  flex: 1;
  overflow: auto;
  padding: .75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

.journal-lines-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: .75rem;
}

.journal-lines-wrap th,
.journal-lines-wrap td {
  padding: .5rem .6rem;
  border: 1px solid #2d3b46;
  background: #0f1720;
}

.journal-lines-wrap th {
  background: #162029;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-size: .68rem;
}

.journal-totals {
  display: flex;
  justify-content: flex-end;
  gap: 1.5rem;
  font-size: .75rem;
  font-weight: 600;
  margin-top: .5rem;
}

.journal-totals-panel {
  border-top: 1px solid #2d3b46;
  padding: .9rem 1.2rem;
  font-size: .75rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  background: #121a22;
  border-radius: 10px;
}

.journal-totals-panel.enlarged {
  font-size: .85rem;
}

.journal-totals-panel button.btn {
  background: #1f2933;
  border: 1px solid #2d3b46;
  color: #e5e7eb;
}

.journal-totals-panel button.btn:hover {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #0f1115;
}

.journal-audit {
  border-top: 1px solid #2d3b46;
  padding: .9rem 1.2rem;
  font-size: .75rem;
  line-height: 1.5;
  background: #121a22;
}

.journal-audit.enlarged {
  font-size: .85rem;
}

.journal-audit h5 {
  margin: .15rem 0 .4rem;
  font-size: .6rem;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: #7dd3fc;
}

/* Manual entry form */
.manual-je-form {
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  border-top: 1px solid #2d3b46;
  background: #11181f;
}

.manual-je-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .5rem;
}

.manual-je-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .5px;
}

.manual-je-form input,
.manual-je-form select,
.manual-je-form textarea {
  background: #0f1720;
  border: 1px solid #2d3b46;
  color: #e5e7eb;
  padding: .6rem .7rem;
  font-size: .78rem;
  border-radius: 6px;
}

.manual-je-lines {
  border: 1px solid #2d3b46;
  border-radius: 8px;
  overflow: hidden;
}

.manual-je-lines table {
  width: 100%;
  border-collapse: collapse;
  font-size: .72rem;
}

.account-typeahead-wrap {
  position: relative;
}

.account-typeahead-input {
  width: 100%;
}

.account-typeahead-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #0f1720;
  border: 1px solid #2d3b46;
  max-height: 230px;
  overflow: auto;
  z-index: 30;
  border-radius: 6px;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, .6);
  padding: .25rem 0;
}

.account-typeahead-item {
  padding: .5rem .7rem;
  font-size: .7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: .9rem;
}

.account-typeahead-item:hover,
.account-typeahead-item.active {
  background: #1c242c;
}

.account-typeahead-item .acct-code {
  opacity: .55;
  font-size: .52rem;
}

.account-typeahead-item .acct-type {
  font-size: .58rem;
  padding: .2rem .45rem;
  border-radius: 4px;
  background: #1f2933;
  color: #a5b4c5;
}

.account-typeahead-section {
  padding: .25rem .6rem;
  font-size: .5rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  opacity: .65;
}

.manual-je-lines th,
.manual-je-lines td {
  padding: .4rem .45rem;
  border-bottom: 1px solid #2d3b46;
  background: #0f1720;
}

.manual-je-lines th {
  background: #162029;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.manual-je-lines tr:last-child td {
  border-bottom: 0;
}

.journal-inline-actions {
  display: flex;
  gap: .35rem;
}

.journal-inline-actions button {
  background: #1f2933;
  border: 1px solid #2d3b46;
  color: #e5e7eb;
  font-size: .66rem;
  padding: .45rem .65rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.journal-inline-actions button:hover {
  background: #0ea5e9;
  color: #0f1115;
  border-color: #0ea5e9;
}

/* Scrollbars refinement */
#journal-modal ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

#journal-modal ::-webkit-scrollbar-track {
  background: #0f1720;
}

#journal-modal ::-webkit-scrollbar-thumb {
  background: #1e2935;
  border-radius: 6px;
  border: 2px solid #0f1720;
}

#journal-modal ::-webkit-scrollbar-thumb:hover {
  background: #334155;
}

/* Responsive */
@media (max-width:1100px) {
  .journal-main {
    grid-template-columns: 1fr;
  }

  .journal-detail-panel {
    border-top: 1px solid #2d3b46;
  }

  .journal-totals-panel {
    position: sticky;
    bottom: 0;
  }

  #journal-modal .modal-content {
    font-size: .9rem;
  }
}

/* ============================================ */
/* DESKTOP TOOLBAR OPTIMIZATION */
/* ============================================ */

@media (min-width: 769px) and (max-width: 1200px) {
  .journal-toolbar {
    padding: .75rem 1rem;
    gap: .5rem;
  }

  .journal-toolbar .btn {
    font-size: .7rem;
    padding: .5rem .75rem;
  }

  .journal-toolbar input,
  .journal-toolbar select {
    font-size: .75rem;
    padding: .5rem .6rem;
  }
}

@media (max-width: 1024px) {

  /* Modal takes full height on mobile for better UX */
  #journal-modal .modal-content {
    height: calc(100dvh - 2 * var(--modal-mobile-pad, 16px));
    max-height: calc(100dvh - 2 * var(--modal-mobile-pad, 16px));
    width: 100vw;
    max-width: 100vw;
    margin: 0;
    border-radius: 0;
  }

  #journal-modal .modal-body {
    height: 100%;
    max-height: none;
    flex: 1;
  }

  /* Toolbar optimization for mobile */
  .journal-toolbar {
    padding: .75rem 1rem;
    gap: .5rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .journal-toolbar::-webkit-scrollbar {
    display: none;
  }

  .journal-toolbar h3 {
    font-size: .95rem;
    margin-right: .5rem;
  }

  .journal-toolbar input,
  .journal-toolbar select {
    padding: .5rem .6rem;
    font-size: .75rem;
    min-width: 120px;
  }

  .journal-toolbar .btn {
    padding: .5rem .75rem;
    font-size: .7rem;
    min-width: fit-content;
  }
}

@media (max-width: 768px) {

  /* Full mobile experience */
  #journal-modal .modal-content {
    border-radius: 0;
    height: 100dvh;
    max-height: 100dvh;
    width: 100vw;
    max-width: 100vw;
  }

  /* Mobile-first toolbar */
  .journal-toolbar {
    flex-direction: column;
    gap: .75rem;
    padding: 1rem;
    align-items: stretch;
  }

  .journal-toolbar h3 {
    text-align: center;
    margin-bottom: .5rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid #2d3b46;
  }

  /* Create mobile-friendly button groups */
  .journal-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
  }

  .journal-toolbar input[type="search"] {
    flex: 1;
    min-width: 200px;
  }

  .journal-toolbar input[type="date"] {
    flex: 1;
    min-width: 120px;
  }

  .journal-toolbar select {
    flex: 1;
    min-width: 120px;
  }

  .journal-toolbar .btn {
    flex: 1;
    justify-content: center;
    min-width: 80px;
    font-size: .65rem;
    padding: .6rem .5rem;
  }

  /* Mobile table stacking */
  .journal-table-wrap {
    padding: 0 .5rem;
  }

  /* Hide traditional table on mobile and show card layout instead */
  table.journal-table {
    min-width: unset;
    width: 100%;
    table-layout: auto;
    display: none;
    /* Hide table completely on mobile */
  }

  /* Modern card-based layout for mobile */
  .journal-entries-cards {
    display: block;
    padding: .75rem;
    animation: fadeIn 0.3s ease-out;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .journal-entry-card {
    background: linear-gradient(135deg, #1a2332 0%, #141a20 100%);
    border: 1px solid #2d3b46;
    border-radius: 16px;
    margin-bottom: 1rem;
    padding: 1.25rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
    position: relative;
    cursor: pointer;
    transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: rgba(14, 165, 233, 0.1);
    overflow: hidden;
  }

  .journal-entry-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #3b82f6, #10b981, #f59e0b);
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .journal-entry-card:hover::before,
  .journal-entry-card:active::before {
    opacity: 1;
  }

  .journal-entry-card:hover,
  .journal-entry-card:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    border-color: #3b82f6;
  }

  .journal-entry-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
  }

  .journal-entry-card-title {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    flex: 1;
  }

  .journal-entry-card-number {
    font-size: .95rem;
    font-weight: 700;
    color: #e2e8f0;
    letter-spacing: .5px;
  }

  .journal-entry-card-date {
    font-size: .75rem;
    color: #94a3b8;
    font-weight: 500;
  }

  .journal-entry-card-menu {
    width: 44px;
    height: 44px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 12px;
    color: #3b82f6;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s ease;
    touch-action: manipulation;
    flex-shrink: 0;
  }

  .journal-entry-card-menu:hover,
  .journal-entry-card-menu:active {
    background: rgba(59, 130, 246, 0.2);
    transform: scale(1.05);
  }

  .journal-entry-card-content {
    display: grid;
    gap: .75rem;
    margin-bottom: 1rem;
  }

  .journal-entry-card-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: .5rem 0;
    border-bottom: 1px solid rgba(45, 59, 70, 0.5);
    gap: 1rem;
  }

  .journal-entry-card-row:last-child {
    border-bottom: none;
  }

  .journal-entry-card-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #7dd3fc;
    font-weight: 600;
    min-width: 80px;
    flex-shrink: 0;
  }

  .journal-entry-card-value {
    font-size: .8rem;
    color: #e2e8f0;
    text-align: right;
    flex: 1;
    word-break: break-word;
    line-height: 1.4;
  }

  .journal-entry-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: .75rem;
    border-top: 1px solid #2d3b46;
    gap: 1rem;
  }

  .journal-entry-card-status {
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
  }

  .journal-entry-card-total {
    font-size: 1.1rem;
    font-weight: 700;
    color: #10b981;
    flex-shrink: 0;
  }

  /* Enhanced status and balance indicators for cards */
  .journal-entry-card .je-status {
    padding: .4rem .8rem;
    font-size: .7rem;
    border-radius: 20px;
    font-weight: 600;
    letter-spacing: .3px;
  }

  .journal-entry-card .balanced-indicator,
  .journal-entry-card .unbalanced-indicator {
    padding: .4rem .8rem;
    font-size: .7rem;
    border-radius: 20px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
  }

  .journal-entry-card .balanced-indicator::before {
    content: "✓";
    color: #10b981;
  }

  .journal-entry-card .unbalanced-indicator::before {
    content: "⚠";
    color: #f59e0b;
  }

  /* Empty state for cards */
  .journal-entries-cards-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
    color: #64748b;
    min-height: 300px;
  }

  .journal-entries-cards-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1.5rem;
    opacity: 0.4;
    color: #475569;
  }

  .journal-entries-cards-empty h3 {
    font-size: 1.2rem;
    margin-bottom: .75rem;
    color: #94a3b8;
    font-weight: 600;
  }

  .journal-entries-cards-empty p {
    font-size: .9rem;
    line-height: 1.6;
    max-width: 320px;
    margin-bottom: 1rem;
  }

  .journal-entries-cards-empty a {
    color: #38bdf8;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
  }

  .journal-entries-cards-empty a:hover {
    color: #0ea5e9;
    text-decoration: underline;
  }

  /* Loading state */
  .journal-entries-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #64748b;
  }

  .journal-entries-loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid #374151;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: .75rem;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  /* Mobile-optimized status and balance indicators */
  .je-status {
    padding: .4rem .7rem;
    font-size: .7rem;
    border-radius: 20px;
    display: inline-block;
  }

  .balanced-indicator,
  .unbalanced-indicator {
    padding: .4rem .7rem;
    font-size: .7rem;
    border-radius: 20px;
    display: inline-block;
  }

  /* Show cards on mobile, hide table */
  .journal-entries-cards {
    display: block;
  }

  .journal-table-wrap table.journal-table {
    display: none;
  }
}

@media (max-width: 480px) {

  /* Extra small mobile devices */
  .journal-toolbar {
    padding: .75rem;
  }

  .journal-toolbar .btn {
    font-size: .6rem;
    padding: .5rem .4rem;
    min-width: 70px;
  }

  .journal-entries-cards {
    padding: .5rem;
  }

  .journal-entry-card {
    padding: 1rem;
    margin-bottom: .75rem;
  }

  .journal-entry-card-header {
    margin-bottom: .75rem;
  }

  .journal-entry-card-content {
    gap: .5rem;
    margin-bottom: .75rem;
  }

  .journal-entry-card-menu {
    width: 40px;
    height: 40px;
  }
}

/* Ensure proper menu positioning */
.journal-entry-card-menu,
.je-row-menu-btn {
  position: relative;
  z-index: 10;
}

/* Touch improvements */
@media (pointer: coarse) {
  .journal-toolbar .btn {
    min-height: 44px;
    touch-action: manipulation;
  }

  .je-row-menu-btn {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }

  table.journal-table tbody tr {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(14, 165, 233, 0.1);
  }
}

/* Dark mode mobile scrollbars */
@media (max-width: 768px) {
  .journal-table-wrap::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  .journal-table-wrap::-webkit-scrollbar-track {
    background: #0f1720;
  }

  .journal-table-wrap::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 6px;
  }

  .journal-table-wrap::-webkit-scrollbar-thumb:hover {
    background: #4b5563;
  }
}

/* ============================================ */
/* SINGLE ENTRY MODAL MOBILE OPTIMIZATION */
/* ============================================ */

@media (max-width: 1024px) {
  #journal-entry-modal .modal-content {
    height: calc(100dvh - 2 * var(--modal-mobile-pad, 16px));
    max-height: calc(100dvh - 2 * var(--modal-mobile-pad, 16px));
    width: 100vw;
    max-width: 100vw;
    margin: 0;
    border-radius: 0;
  }

  #journal-entry-modal .entry-edit-wrap {
    flex-direction: column !important;
    gap: 1rem !important;
    padding: .75rem !important;
  }

  #journal-entry-modal .entry-right {
    width: 100% !important;
    order: -1;
    /* Show totals/audit first on mobile */
  }

  #journal-entry-modal .entry-left {
    min-width: 0 !important;
  }

  #journal-entry-modal .modal-footer {
    flex-direction: column !important;
    gap: .5rem !important;
  }

  #journal-entry-modal .left-actions,
  #journal-entry-modal .right-actions {
    display: flex !important;
    gap: .5rem !important;
    width: 100% !important;
    justify-content: center !important;
  }

  #journal-entry-modal .left-actions .btn,
  #journal-entry-modal .right-actions .btn {
    flex: 1;
    min-height: 44px;
    touch-action: manipulation;
  }
}

@media (max-width: 768px) {
  #journal-entry-modal .modal-content {
    border-radius: 0;
    height: 100dvh;
    max-height: 100dvh;
    width: 100vw;
    max-width: 100vw;
  }

  /* Mobile journal metadata form */
  .journal-meta-row {
    flex-direction: column !important;
    gap: .75rem !important;
  }

  .journal-meta-row span {
    display: flex;
    flex-direction: column;
    gap: .25rem;
  }

  .journal-meta-row input {
    width: 100%;
    padding: .6rem;
    font-size: .8rem;
  }

  /* Mobile journal lines table */
  .journal-lines-wrap table {
    min-width: 100%;
    font-size: .7rem;
  }

  .journal-lines-wrap th,
  .journal-lines-wrap td {
    padding: .4rem .3rem;
    font-size: .65rem;
  }

  /* Mobile totals panel */
  .journal-totals-panel {
    font-size: .75rem !important;
    padding: .75rem !important;
  }

  /* Mobile audit section */
  .journal-audit {
    font-size: .7rem !important;
    padding: .75rem !important;
  }

  /* Mobile manual entry form */
  .manual-je-form {
    padding: .5rem;
  }

  .manual-je-form-row {
    grid-template-columns: 1fr !important;
  }

  .manual-je-lines table {
    font-size: .65rem;
  }

  .manual-je-lines th,
  .manual-je-lines td {
    padding: .3rem .25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #toast-container .toast {
    transition: none !important;
  }
}

/* Three dots menu button - Universal styling */
.je-row-menu-btn {
  background: #1f2937;
  border: 1px solid #374151;
  color: #fff;
  padding: 0.45rem 0.6rem;
  line-height: 1;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  min-width: 34px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.15s ease;
}

.je-row-menu-btn:hover {
  background: #374151;
}

.je-row-menu-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Three dots floating menu - Universal styling */
#je-floating-menu {
  position: fixed;
  min-width: 180px;
  background: #0f1720;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.3rem 0;
  z-index: 1000000;
  /* ensure above sticky toolbars and cards */
  box-shadow: 0 14px 32px -8px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  font-family: inherit;
}

#je-floating-menu button {
  all: unset;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  display: block;
  width: 100%;
  text-align: left;
  color: #d1d5db;
  box-sizing: border-box;
  white-space: nowrap;
  font-weight: 500;
  transition: background 0.15s ease;
  font-family: inherit;
}

#je-floating-menu button:hover {
  background: #1f2937;
  color: #fff;
}

#je-floating-menu button:focus {
  background: #1f2937;
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

/* Color-coded menu items for better UX */
#je-floating-menu button[data-row-duplicate] {
  color: #93c5fd;
}

#je-floating-menu button[data-row-reverse] {
  color: #fbbf24;
}

#je-floating-menu button[data-row-delete] {
  color: #f87171;
}

/* Responsive menu adjustments */
@media (max-width: 768px) {
  #je-floating-menu {
    min-width: 160px;
    font-size: 0.7rem;
  }

  #je-floating-menu button {
    padding: 0.5rem 0.75rem;
  }

  .je-row-menu-btn {
    min-width: 30px;
    min-height: 30px;
    padding: 0.35rem 0.5rem;
  }
}

/* RTL Specific Fixes for Journal */
.rtl .journal-table tbody td:first-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}

.rtl .journal-table tbody td:last-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

.rtl .journal-list-panel {
  border-right: none;
  border-left: 1px solid var(--border, #2d3b46);
}

.rtl .account-typeahead-list {
  left: auto;
  right: 0;
}

/* Ensure account typeahead works correctly in RTL */
.rtl .account-typeahead-wrap {
  direction: rtl;
}

.rtl .account-typeahead-input {
  direction: rtl;
  text-align: right;
}

.rtl .account-typeahead-list {
  direction: rtl;
  text-align: right;
}

.rtl .account-typeahead-item {
  flex-direction: row-reverse;
  text-align: right;
}

/* Fix modal header and footer in RTL */
.rtl #journal-modal .modal-header,
.rtl #journal-entry-modal .modal-header {
  direction: rtl;
  text-align: right;
}

.rtl #journal-modal .modal-footer,
.rtl #journal-entry-modal .modal-footer {
  direction: rtl;
  flex-direction: row-reverse;
}

/* Fix toolbar button order in RTL */
.rtl .journal-toolbar {
  direction: rtl;
  flex-direction: row-reverse;
}

.rtl .journal-toolbar .grow {
  margin-left: 0;
  margin-right: auto;
}

/* Ensure form inputs are RTL-aware */
.rtl .manual-je-form {
  direction: rtl;
}

.rtl .manual-je-form-row {
  direction: rtl;
}

.rtl .manual-je-form label {
  text-align: right;
}

.rtl .manual-je-form input:not([type="number"]):not([type="date"]),
.rtl .manual-je-form select,
.rtl .manual-je-form textarea {
  direction: rtl;
  text-align: right;
}

/* Keep numbers and dates LTR */
.rtl .manual-je-form input[type="number"],
.rtl .manual-je-form input[type="date"],
.rtl .journal-toolbar input[type="number"],
.rtl .journal-toolbar input[type="date"] {
  direction: ltr;
  text-align: left;
}

/* Fix action buttons in RTL */
.rtl .journal-inline-actions {
  justify-content: flex-start;
}

.rtl .modal-footer .left-actions {
  margin-left: auto;
  margin-right: 0;
}

.rtl .modal-footer .right-actions {
  margin-right: auto;
  margin-left: 0;
}