/* ============================================================
   Aset CKL — Responsive Design System
   Breakpoints (Bootstrap 5):
     xs  < 576px   (HP kecil)
     sm  ≥ 576px   (HP besar)
     md  ≥ 768px   (tablet portrait)
     lg  ≥ 992px   (tablet landscape / laptop)
     xl  ≥ 1200px  (desktop)
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --ckl-primary:    #1e3a5f;
  --ckl-secondary:  #2e6da4;
  --ckl-accent:     #f0a500;
  --ckl-light:      #f5f7fa;
  --ckl-sidebar-w:  240px;
  --ckl-navbar-h:   56px;
  --ckl-radius:     10px;
  --ckl-radius-sm:  6px;
  --ckl-shadow:     0 2px 12px rgba(0,0,0,.08);
  --ckl-shadow-lg:  0 8px 30px rgba(0,0,0,.12);
  --font-main:      'Inter', system-ui, -apple-system, sans-serif;

  /* Fluid font scale */
  --fs-xs:   .72rem;
  --fs-sm:   .8rem;
  --fs-base: .875rem;
  --fs-md:   .95rem;
  --fs-lg:   1.05rem;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--ckl-light);
  color: #1a1a2e;
  padding-top: var(--ckl-navbar-h);
  min-width: 320px;          /* Minimum support width */
  overflow-x: hidden;        /* Cegah horizontal scroll di body */
}

a { text-decoration: none; }
img { max-width: 100%; height: auto; }

/* Utility */
.fs-7       { font-size: var(--fs-xs); }
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Navbar ─────────────────────────────────────────────────── */
.ckl-navbar {
  background: var(--ckl-primary) !important;
  height: var(--ckl-navbar-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  z-index: 1040;
  /* Pastikan tidak overflow di layar kecil */
  padding-left: .75rem !important;
  padding-right: .75rem !important;
}

.ckl-navbar .navbar-brand {
  font-size: clamp(.9rem, 2.5vw, 1.15rem);
  letter-spacing: .02em;
  white-space: nowrap;
}

.ckl-navbar .navbar-brand span {
  display: inline;
}

.ckl-navbar .btn-outline-light {
  font-size: var(--fs-sm);
  border-radius: 20px;
  padding: .25rem .75rem;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sembunyikan teks nama di layar sangat kecil */
@media (max-width: 400px) {
  .ckl-navbar .btn-outline-light .user-name { display: none; }
  .ckl-navbar .navbar-brand span { display: none; }
}

/* ── Layout Wrapper ─────────────────────────────────────────── */
#appWrapper {
  display: flex;
  min-height: calc(100vh - var(--ckl-navbar-h));
  width: 100%;
}

/* ── Sidebar (Desktop ≥ lg) ─────────────────────────────────── */
.ckl-sidebar {
  width: var(--ckl-sidebar-w);
  min-width: var(--ckl-sidebar-w);
  background: #fff;
  border-right: 1px solid #e8ecf0;
  padding: 1rem 0 1.5rem;
  position: sticky;
  top: var(--ckl-navbar-h);
  height: calc(100vh - var(--ckl-navbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  /* Smooth scrollbar */
  scrollbar-width: thin;
  scrollbar-color: #d0d7e0 transparent;
}

.ckl-sidebar::-webkit-scrollbar { width: 4px; }
.ckl-sidebar::-webkit-scrollbar-thumb { background: #d0d7e0; border-radius: 4px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--ckl-primary);
  padding: .5rem 1.25rem 0;
}

.sidebar-role { padding: .4rem 1.25rem .8rem; }

.sidebar-menu { padding: 0 .75rem; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .85rem;
  border-radius: var(--ckl-radius);
  color: #4a5568;
  font-size: var(--fs-base);
  font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link i { font-size: 1.05rem; flex-shrink: 0; }
.sidebar-link span { overflow: hidden; text-overflow: ellipsis; }
.sidebar-link:hover { background: #eef2f7; color: var(--ckl-primary); }
.sidebar-link.active { background: var(--ckl-primary); color: #fff !important; }
.sidebar-footer { padding: 0 .75rem; }

/* ── Offcanvas Sidebar (Mobile < lg) ────────────────────────── */
.ckl-offcanvas {
  background: var(--ckl-primary) !important;
  width: min(280px, 85vw) !important;   /* Tidak lebih dari 85% layar */
}

.ckl-offcanvas .offcanvas-title { color: #fff; }
.ckl-offcanvas .sidebar-link    { color: rgba(255,255,255,.9); white-space: nowrap; }
.ckl-offcanvas .sidebar-link:hover  { background: rgba(255,255,255,.1); }
.ckl-offcanvas .sidebar-link.active { background: rgba(255,255,255,.2); }
.ckl-offcanvas .btn-close { filter: invert(1) brightness(2); opacity: .9; }

/* ── Main Content Area ──────────────────────────────────────── */
.ckl-main {
  flex: 1 1 0;
  min-width: 0;                    /* ← KRITIS: cegah konten memaksa lebar */
  min-height: calc(100vh - var(--ckl-navbar-h));
  padding-top: 0;
  overflow-x: hidden;
}

.ckl-main > .container-fluid {
  padding: clamp(.75rem, 2vw, 1.5rem);
  max-width: 100%;
}

/* Page title responsif */
.ckl-main h4.fw-bold {
  font-size: clamp(1rem, 3vw, 1.4rem);
  word-break: break-word;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  border: 1px solid #e8ecf0;
  border-radius: var(--ckl-radius);
  box-shadow: var(--ckl-shadow);
  width: 100%;                     /* Selalu full width container */
}

.card-header {
  border-radius: var(--ckl-radius) var(--ckl-radius) 0 0 !important;
  font-weight: 600;
  font-size: var(--fs-md);
  flex-wrap: wrap;
  gap: .5rem;
}

.card-body { overflow: hidden; }   /* Cegah card melebar */

/* ── Stat Cards (Dashboard) ─────────────────────────────────── */
.stat-card {
  border: none !important;
  border-radius: var(--ckl-radius);
  overflow: hidden;
  position: relative;
  min-height: 90px;
}

.stat-card .stat-icon {
  font-size: clamp(2rem, 5vw, 3rem);
  opacity: .18;
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.stat-card .stat-value {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 700;
  line-height: 1.1;
}

.stat-card .stat-label {
  font-size: clamp(.7rem, 2vw, .85rem);
  opacity: .85;
}

/* ── Tables ─────────────────────────────────────────────────── */
/* Wrapper: horizontal scroll pada layar kecil, tidak overflow */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  min-width: 500px;              /* Tabel boleh scroll horizontal, tidak gepeng */
  margin-bottom: 0;
}

.table thead th {
  background: var(--ckl-primary);
  color: #fff;
  font-weight: 600;
  font-size: var(--fs-xs);
  letter-spacing: .03em;
  border: none;
  vertical-align: middle;
  white-space: nowrap;
  padding: .65rem .75rem;
}

.table tbody tr:hover { background: #f0f4f8; }

.table td {
  vertical-align: middle;
  font-size: var(--fs-sm);
  padding: .6rem .75rem;
  word-break: break-word;
}

/* Tabel di layar kecil: font lebih kecil */
@media (max-width: 575.98px) {
  .table thead th,
  .table td { font-size: var(--fs-xs); padding: .45rem .5rem; }
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  border-radius: var(--ckl-radius-sm);
  font-size: var(--fs-base);
  font-weight: 500;
  white-space: nowrap;
}

.btn-sm { border-radius: 5px; font-size: var(--fs-xs); }
.btn-ckl-primary { background: var(--ckl-primary); color: #fff; border: none; }
.btn-ckl-primary:hover { background: #162d4a; color: #fff; }

/* Tombol aksi di tabel: tampilkan ikon saja di layar kecil */
@media (max-width: 767.98px) {
  .btn-tbl-label { display: none; }
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  border-radius: var(--ckl-radius-sm);
  font-weight: 600;
  font-size: var(--fs-xs);
  white-space: nowrap;
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-control,
.form-select {
  border-radius: var(--ckl-radius-sm);
  font-size: var(--fs-base);
  border-color: #d0d7e0;
  max-width: 100%;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--ckl-secondary);
  box-shadow: 0 0 0 3px rgba(46,109,164,.15);
}

.form-label {
  font-weight: 500;
  font-size: var(--fs-base);
  margin-bottom: .35rem;
}

/* Filter bar: wrap di layar kecil */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: flex-end;
}

.filter-bar .form-control,
.filter-bar .form-select {
  min-width: 120px;
  flex: 1 1 140px;
}

/* ── Foto / Upload ──────────────────────────────────────────── */
.foto-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border: 2px dashed #d0d7e0;
  border-radius: var(--ckl-radius-sm);
  background: #f8fafc;
  padding: .5rem;
}

.foto-aset-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: var(--ckl-radius-sm);
  border: 1px solid #e0e0e0;
  cursor: pointer;
  transition: opacity .2s, transform .2s;
  flex-shrink: 0;
}

.foto-aset-thumb:hover { opacity: .85; transform: scale(1.08); }

/* ── Drop Zone (Import) ─────────────────────────────────────── */
.drop-zone {
  border: 2.5px dashed var(--ckl-secondary);
  border-radius: var(--ckl-radius);
  padding: clamp(1.5rem, 4vw, 2.5rem) 1rem;
  text-align: center;
  cursor: pointer;
  transition: background .2s, border-color .2s;
  background: #f8fbff;
  width: 100%;
}

.drop-zone.dragover { background: #dbeeff; border-color: var(--ckl-primary); }
.drop-zone i { font-size: clamp(1.8rem, 5vw, 2.8rem); color: var(--ckl-secondary); }

/* ── Alert ──────────────────────────────────────────────────── */
.alert {
  border-radius: var(--ckl-radius);
  font-size: var(--fs-base);
  word-break: break-word;
}

/* ── Pagination ─────────────────────────────────────────────── */
.pagination { flex-wrap: wrap; gap: 2px; }
.page-link  { font-size: var(--fs-xs); color: var(--ckl-primary); padding: .35rem .6rem; }
.page-item.active .page-link {
  background: var(--ckl-primary);
  border-color: var(--ckl-primary);
}

/* ── Login Page ─────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--ckl-primary) 0%, var(--ckl-secondary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  border: none !important;
  border-radius: 16px !important;
  box-shadow: 0 20px 60px rgba(0,0,0,.25) !important;
}

.login-logo { font-size: clamp(2rem, 8vw, 2.8rem); color: var(--ckl-primary); }

/* ── Card Header Flex Wrap ──────────────────────────────────── */
.card-header.d-flex {
  flex-wrap: wrap;
  row-gap: .5rem;
}

/* ── SO Detail dinamis (Stock Opname) ───────────────────────── */
.so-item { border-bottom: 1px solid #f0f0f0; padding-bottom: .5rem; }

/* ── Modals ─────────────────────────────────────────────────── */
.modal-content { border-radius: var(--ckl-radius) !important; }

/* Modal di HP: full screen bawah */
@media (max-width: 575.98px) {
  .modal-dialog:not(.modal-fullscreen) {
    margin: 0;
    max-width: 100%;
    min-height: 100%;
    align-items: flex-end;
  }
  .modal-content {
    border-radius: 16px 16px 0 0 !important;
  }
}

/* ── Offcanvas (filter / panel samping) ─────────────────────── */
.offcanvas { max-width: 90vw; }

/* ── List Group (SO sidebar) ────────────────────────────────── */
.list-group-item { font-size: var(--fs-base); word-break: break-word; }

/* ── Profil Avatar ──────────────────────────────────────────── */
.avatar-circle {
  width: clamp(60px, 15vw, 80px);
  height: clamp(60px, 15vw, 80px);
  font-size: clamp(1.4rem, 5vw, 2rem);
}

/* ── Scrollbar global (webkit) ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c8d0da; border-radius: 4px; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════ */

/* ── Mobile (< 576px) ───────────────────────────────────────── */
@media (max-width: 575.98px) {

  :root {
    --ckl-navbar-h: 52px;
  }

  body { padding-top: var(--ckl-navbar-h); }

  /* Padding konten lebih kecil */
  .ckl-main > .container-fluid { padding: .75rem; }

  /* Card header: stack vertikal */
  .card-header.d-flex {
    flex-direction: column;
    align-items: flex-start !important;
  }
  .card-header.d-flex .ms-auto { margin-left: 0 !important; }

  /* Sembunyikan kolom tidak esensial di tabel */
  .col-hide-xs { display: none !important; }

  /* Stat card value lebih kecil */
  .stat-card .stat-value { font-size: 1.5rem; }

  /* Filter form: satu kolom */
  .filter-bar { flex-direction: column; }
  .filter-bar .form-control,
  .filter-bar .form-select { flex: 1 1 100%; min-width: 0; }

  /* Page header: judul lebih kecil */
  .ckl-main h4.fw-bold { font-size: 1rem; }

  /* Drop zone lebih compact */
  .drop-zone { padding: 1.25rem .75rem; }

  /* Alert: text lebih kecil */
  .alert { font-size: var(--fs-sm); }

  /* Tombol dalam card header: full width */
  .card-header .btn { width: 100%; text-align: center; }
}

/* ── Tablet Portrait (576px – 767px) ────────────────────────── */
@media (min-width: 576px) and (max-width: 767.98px) {

  .ckl-main > .container-fluid { padding: 1rem; }

  .col-hide-sm { display: none !important; }

  .stat-card .stat-value { font-size: 1.7rem; }
}

/* ── Tablet Landscape (768px – 991px) ───────────────────────── */
@media (min-width: 768px) and (max-width: 991.98px) {

  .ckl-main > .container-fluid { padding: 1.25rem; }

  /* Sidebar tersembunyi, pakai offcanvas */
  .ckl-sidebar { display: none !important; }
}

/* ── Desktop (≥ 992px): Sidebar muncul ──────────────────────── */
@media (min-width: 992px) {

  /* Tombol hamburger disembunyikan Bootstrap (d-none d-lg-none) */

  /* Main content: kasih ruang sidebar */
  .ckl-main { width: calc(100% - var(--ckl-sidebar-w)); }

  /* Tabel: lebih lapang */
  .table thead th { font-size: var(--fs-sm); padding: .75rem 1rem; }
  .table td       { font-size: var(--fs-base); padding: .7rem 1rem; }
}

/* ── Wide Desktop (≥ 1400px) ────────────────────────────────── */
@media (min-width: 1400px) {
  :root { --ckl-sidebar-w: 260px; }

  .ckl-main > .container-fluid { padding: 1.75rem 2rem; }
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  .ckl-navbar,
  .ckl-sidebar,
  .ckl-offcanvas,
  .btn,
  .pagination { display: none !important; }

  body { padding-top: 0 !important; background: #fff; }
  .ckl-main { width: 100% !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .table-responsive { overflow: visible !important; }
  .table { min-width: 0 !important; }
}

/* ══════════════════════════════════════════════
   SEARCHABLE SELECT (Modal Edit Aset)
══════════════════════════════════════════════ */
.searchable-select { position: relative; }

.ss-input-wrap { position: relative; display: flex; align-items: center; }
.ss-input-wrap .ss-search { flex: 1; padding-right: 2.2rem; }
.ss-input-wrap .ss-clear {
  position: absolute; right: .4rem; top: 50%;
  transform: translateY(-50%); z-index: 5;
  padding: 0; line-height: 1; background: none; border: none;
}

.ss-search.selected {
  background: #eef6ff;
  border-color: var(--ckl-secondary);
  color: #1e3a5f;
  font-weight: 500;
}

.ss-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff;
  border: 1px solid #c8d5e5;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,.13);
  z-index: 1070;
  max-height: 210px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c0cad8 transparent;
}
.ss-dropdown::-webkit-scrollbar { width: 5px; }
.ss-dropdown::-webkit-scrollbar-thumb { background: #c0cad8; border-radius: 4px; }

.ss-option {
  padding: .55rem .9rem;
  cursor: pointer;
  font-size: .875rem;
  transition: background .1s;
  display: flex;
  align-items: center;
  gap: .5rem;
  border-bottom: 1px solid #f4f6f9;
  line-height: 1.4;
}
.ss-option:last-child { border-bottom: none; }
.ss-option:hover,
.ss-option.hovered  { background: #eef2f7; }
.ss-option.selected { background: #dbeeff; color: #1e3a5f; font-weight: 600; }
.ss-option.d-none   { display: none !important; }

.ss-code {
  font-size: .7rem;
  font-family: 'Courier New', monospace;
  background: #e8ecf0;
  padding: 1px 5px;
  border-radius: 4px;
  color: #666;
  flex-shrink: 0;
  white-space: nowrap;
}

.ss-empty {
  padding: .8rem .9rem;
  color: #aaa;
  font-size: .85rem;
  font-style: italic;
  text-align: center;
}

/* Column Search Row */
#theadSearch td {
  padding: .3rem .5rem;
  background: #f4f7fb;
  border-bottom: 2px solid #c8d5e5;
  vertical-align: middle;
}
#theadSearch .form-control {
  font-size: .78rem;
  padding: .28rem .5rem;
  height: 28px;
  border-radius: 5px;
}
#theadSearch .btn {
  height: 28px;
  font-size: .75rem;
  padding: 0 .5rem;
}
