/* ==========================================================================
   KM RENT Scheduler - CSV View & Detail Sheet Styles (Tokyo Night Tokens)
   ========================================================================== */

/* 1. Toolbar View Toggle (카드 / CSV) */
.inventory-view-toggle {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  padding: 2px;
  border: 1px solid var(--border);
  gap: 2px;
}

.inventory-view-toggle .btn-view-toggle {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 500;
  border-radius: calc(var(--radius-sm) - 1px);
  cursor: pointer;
  line-height: 1.4;
  min-height: 32px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.inventory-view-toggle .btn-view-toggle:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.inventory-view-toggle .btn-view-toggle.active {
  background: var(--bg-card-selected);
  color: var(--text-main);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* 2. CSV View Container */
.inventory-csv-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: 8px;
  border-radius: var(--radius);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* 3. Desktop Sticky Header Row */
.inventory-csv-header {
  display: grid;
  grid-template-columns: var(--csv-columns);
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}

.inventory-csv-header-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 4. CSV List & Rows */
.inventory-csv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.inventory-csv-row {
  transition: background-color 0.1s ease;
}

.inventory-csv-row:last-child .inventory-csv-row-btn {
  border-bottom: none;
}

.inventory-csv-row:hover {
  background: var(--bg-card-hover);
}

.inventory-csv-row-btn {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
  text-align: left;
  padding: 8px 12px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  outline: none;
}

.inventory-csv-row-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  background: var(--bg-card-hover);
}

/* Primary Line (Desktop Grid) */
.csv-row-primary {
  display: grid;
  grid-template-columns: var(--csv-columns);
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 27px;
}

/* Cell Defaults */
.csv-cell {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-main);
  display: flex;
  align-items: center;
}

.csv-cell.col-eq-no {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text-main);
}

.csv-cell.col-model {
  color: var(--text-muted);
}

.csv-cell.col-memo {
  color: var(--text-subtle);
  font-size: 12px;
}

/* Secondary Line (Mobile Memo) */
.csv-row-secondary {
  display: none;
  width: 100%;
  margin-top: 3px;
  line-height: 1.3;
}

.csv-row-secondary .col-memo-line {
  font-size: 12px;
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* 5. Pagination / More Button */
.inventory-csv-more-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 12px;
  gap: 8px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}

.inventory-csv-count-summary {
  font-size: 13px;
  color: var(--text-muted);
}

.btn-csv-more {
  min-height: 40px;
  padding: 8px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.btn-csv-more:hover {
  background: var(--accent);
  color: var(--on-accent);
}

/* 6. Mobile Layout Adjustments (<= 760px) */
@media (max-width: 760px) {
  .inventory-csv-header {
    display: none; /* Mobile hides the table header */
  }

  /* Fixed tracks come from columns; only the model consumes remaining space.
     Overflow priority: model ellipsis, then compact chip padding. The configured
     widths keep the reservation label visible even at 360px (no dot fallback). */
  .csv-row-primary {
    grid-template-columns: var(--csv-mobile-columns);
    gap: var(--csv-mobile-gap);
  }

  .csv-cell {
    display: var(--csv-cell-mobile-display, flex);
  }

  .csv-cell.col-model .model-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .csv-row-secondary {
    display: block; /* In mobile, secondary row appears if memo exists */
    width: 100%;
    margin-top: 3px;
    line-height: 1.3;
  }

  .csv-row-secondary .col-memo-line {
    font-size: 12px;
    color: var(--text-subtle);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
  }

  .inventory-csv-row-btn {
    min-height: 44px;
    padding: 8px var(--csv-mobile-padding);
  }
}

/* 7. Compact Chips inside CSV Row */
.inventory-csv-row .badge {
  padding: 2px 6px;
  font-size: 11px;
  min-height: 22px;
  box-sizing: border-box;
  white-space: nowrap;
  max-width: 100%;
}

.inventory-csv-row .cond-badge {
  padding: 0 8px;
  font-size: 11px;
  min-height: 22px;
  height: 22px;
  box-sizing: border-box;
  white-space: nowrap;
  max-width: 100%;
}

.inventory-csv-row .cond-badge .condition-dot {
  width: 7px;
  height: 7px;
  margin-right: 4px;
}

.inventory-csv-row .clickable-val {
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.inventory-csv-row .clickable-val:hover {
  color: var(--accent) !important;
}

.inventory-csv-row .clickable-val:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}

@media (max-width: 760px) {
  .inventory-csv-row .badge {
    padding-inline: 3px;
    flex-shrink: 0;
  }

  .inventory-csv-row .cond-badge {
    padding-inline: 3px;
    gap: 3px;
    flex-shrink: 0;
  }

  .inventory-csv-row .cond-badge .condition-dot {
    margin-right: 0;
  }
}

/* 8. Equipment Detail Sheet Modal */
.equipment-detail-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-overlay);
  backdrop-filter: blur(2px);
  z-index: var(--z-index-detail-sheet, 900);
  display: flex;
  align-items: flex-end; /* Mobile: bottom sheet */
  justify-content: center;
}

@media (min-width: 761px) {
  .equipment-detail-modal-overlay {
    align-items: center; /* Desktop: center modal */
  }
}

.equipment-detail-sheet {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: sheetSlideUp 0.2s ease-out;
}

@media (min-width: 761px) {
  .equipment-detail-sheet {
    border-radius: var(--radius);
    max-height: 80vh;
  }
}

@keyframes sheetSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.equipment-detail-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.equipment-detail-sheet-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.equipment-detail-sheet-close-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  min-height: 32px;
}

.equipment-detail-sheet-close-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.equipment-detail-sheet-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Authentic Card Structure in Detail Sheet (Mobile & Desktop) */
.equipment-detail-sheet-body .inventory-table,
.equipment-detail-sheet-body .inventory-table thead,
.equipment-detail-sheet-body .inventory-table tbody,
.equipment-detail-sheet-body .inventory-table th,
.equipment-detail-sheet-body .inventory-table td,
.equipment-detail-sheet-body .inventory-table tr {
  display: block;
  width: 100% !important;
  max-width: 100%;
  box-sizing: border-box;
}

.equipment-detail-sheet-body .inventory-table thead tr {
  position: absolute;
  top: -9999px;
  left: -9999px;
}

.equipment-detail-sheet-body .inventory-table {
  border-collapse: separate;
  border-spacing: 0;
  background: transparent;
  border: none;
}

.equipment-detail-sheet-body .inventory-row {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.equipment-detail-sheet-body .inventory-row.maint-expanded {
  margin-bottom: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: 1px dashed var(--border);
}

.equipment-detail-sheet-body .inventory-maint-row {
  margin: 0;
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  background: var(--bg-inset);
  padding: 10px;
  box-sizing: border-box;
  max-width: 100%;
  overflow-x: hidden;
}

.equipment-detail-sheet-body .inventory-maint-row td.cell-maint-drawer {
  padding: 0;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.equipment-detail-sheet-body .inventory-table td {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  padding: 6px 0 !important;
  border-bottom: 1px solid var(--border) !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.equipment-detail-sheet-body .inventory-table td.cell-eq-no {
  padding-top: 2px !important;
  padding-bottom: 8px !important;
  border-bottom: 1px solid var(--border) !important;
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.equipment-detail-sheet-body .inventory-table td.cell-eq-no .maint-toggle-wrap {
  margin-top: 0 !important;
  margin-left: auto;
}

.equipment-detail-sheet-body .inventory-table td.cell-model {
  align-items: flex-start;
  flex-direction: column;
}

.equipment-detail-sheet-body .inventory-table td.cell-spec {
  align-items: flex-start;
  flex-direction: column;
}

.equipment-detail-sheet-body .inventory-table td.cell-identifiers {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

.equipment-detail-sheet-body .inventory-table td.cell-empty {
  display: none !important;
}

.equipment-detail-sheet-body .inventory-table td.cell-customer {
  align-items: flex-start;
  flex-direction: column;
}

.equipment-detail-sheet-body .inventory-table td.cell-contract {
  align-items: flex-start;
  flex-direction: column;
  border-bottom: none !important;
}
