/* ============================================================
   KCS TWIS – style.css
   Theme: Orange (#FF6B00) · Blue (#1E5AA8) · White
   Font : Kanit (Google Fonts)
   ============================================================ */

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

:root {
  --orange      : #FF6B00;
  --orange-dark : #E05A00;
  --orange-light: #FFF3EB;
  --blue        : #1E5AA8;
  --blue-dark   : #154080;
  --blue-light  : #EBF0FB;
  --purple      : #4A2C6D;
  --red         : #D32F2F;
  --green       : #2E7D32;
  --gray        : #6B7280;
  --gray-light  : #F3F4F6;
  --white       : #FFFFFF;
  --sidebar-w   : 250px;
  --topbar-h    : 60px;
  --radius      : 10px;
  --shadow      : 0 2px 12px rgba(0,0,0,.08);
  --shadow-md   : 0 4px 24px rgba(0,0,0,.13);
  --transition  : .25s ease;
}

html { font-size: 15px; }

body {
  font-family: 'Kanit', sans-serif;
  background  : #F0F2F5;
  color       : #1F2937;
  min-height  : 100vh;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; }
input, select, textarea { font-family: inherit; font-size: .95rem; }
img { max-width: 100%; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: var(--orange); border-radius: 3px; }

/* ══════════════════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════════════════ */
.login-wrapper {
  min-height   : 100vh;
  display      : flex;
  align-items  : center;
  justify-content: center;
  background   : linear-gradient(135deg, var(--blue-dark) 0%, var(--orange-dark) 100%);
  padding      : 1rem;
}

.login-card {
  background   : var(--white);
  border-radius: 16px;
  padding      : 2.5rem 2rem;
  width        : 100%;
  max-width    : 400px;
  box-shadow   : var(--shadow-md);
}

.login-logo {
  text-align : center;
  margin-bottom: 2rem;
}
.login-logo h1 { font-size: 2rem; color: var(--blue); }
.login-logo h1 span { color: var(--orange); }
.login-logo p { color: var(--gray); font-size: .9rem; }
.login-logo small { color: var(--blue); font-size: .82rem; }
.login-version { text-align:center; color:var(--gray); font-size:.78rem; margin-top:1.5rem; }

.input-icon-wrap { position: relative; }
.input-icon-wrap input { padding-right: 2.5rem; width: 100%; }
.toggle-pw {
  position  : absolute;
  right     : .75rem;
  top       : 50%;
  transform : translateY(-50%);
  cursor    : pointer;
  font-size : 1.1rem;
  opacity   : .6;
}

/* ══════════════════════════════════════════════════════════
   APP LAYOUT
══════════════════════════════════════════════════════════ */
.app-layout {
  display     : flex;
  min-height  : 100vh;
  position    : relative;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width         : var(--sidebar-w);
  background    : linear-gradient(180deg, var(--blue-dark) 0%, var(--blue) 100%);
  color         : var(--white);
  display       : flex;
  flex-direction: column;
  position      : fixed;
  top: 0; left: 0; bottom: 0;
  z-index       : 200;
  transition    : transform var(--transition);
}

.sidebar-header {
  display       : flex;
  align-items   : center;
  justify-content: space-between;
  padding       : 1.2rem 1rem;
  border-bottom : 1px solid rgba(255,255,255,.12);
}

.sidebar-brand { display: flex; align-items: center; gap: .75rem; }
.brand-icon    { font-size: 1.8rem; }
.sidebar-brand strong { font-size: 1rem; display: block; }
.sidebar-brand small  { font-size: .75rem; opacity: .75; }
.sidebar-close { background: none; color: white; font-size: 1.2rem; display: none; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem 0; }
.sidebar-nav ul { list-style: none; }
.nav-link {
  display     : flex;
  align-items : center;
  gap         : .75rem;
  padding     : .75rem 1.25rem;
  transition  : background var(--transition);
  border-radius: 0 30px 30px 0;
  margin-right: .75rem;
}
.nav-link:hover  { background: rgba(255,255,255,.12); }
.nav-link.active { background: var(--orange); box-shadow: 0 2px 8px rgba(255,107,0,.4); }
.nav-icon  { font-size: 1.1rem; width: 24px; text-align: center; }
.nav-label { font-size: .9rem; font-weight: 500; }
.nav-header {
  padding      : 1rem 1.25rem .35rem;
  margin-top   : .5rem;
  font-size    : .72rem;
  font-weight  : 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color        : rgba(255,255,255,.55);
  border-top   : 1px solid rgba(255,255,255,.08);
}

.sidebar-footer {
  padding     : 1rem;
  border-top  : 1px solid rgba(255,255,255,.12);
}
.user-info { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.user-avatar{ font-size: 1.8rem; }
.user-name  { font-size: .88rem; font-weight: 600; }
.user-role  { font-size: .75rem; opacity: .75; }
.btn-logout {
  width     : 100%;
  padding   : .5rem;
  background: rgba(255,255,255,.12);
  color     : white;
  border-radius: var(--radius);
  font-size : .85rem;
  transition: background var(--transition);
}
.btn-logout:hover { background: rgba(211,47,47,.7); }

/* ── Sidebar overlay (mobile) ────────────────────────────── */
.sidebar-overlay {
  display   : none;
  position  : fixed;
  inset     : 0;
  background: rgba(0,0,0,.5);
  z-index   : 199;
}
.sidebar-overlay.show { display: block; }

/* ── Main wrap ───────────────────────────────────────────── */
.main-wrap {
  margin-left : var(--sidebar-w);
  flex        : 1;
  display     : flex;
  flex-direction: column;
  min-height  : 100vh;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height      : var(--topbar-h);
  background  : var(--white);
  border-bottom: 2px solid var(--orange);
  display     : flex;
  align-items : center;
  padding     : 0 1.5rem;
  gap         : 1rem;
  position    : sticky;
  top         : 0;
  z-index     : 100;
  box-shadow  : 0 2px 8px rgba(0,0,0,.06);
}
.hamburger  { display: none; background: none; font-size: 1.4rem; color: var(--blue); }
.topbar-title{ font-size: 1.1rem; font-weight: 600; color: var(--blue); flex: 1; }
.topbar-right{ display: flex; align-items: center; gap: 1rem; }
.topbar-user { font-size: .85rem; color: var(--gray); }

/* ── Page content ────────────────────────────────────────── */
.page-content { flex: 1; padding: 1.5rem; overflow-x: hidden; }

/* ══════════════════════════════════════════════════════════
   CARDS
══════════════════════════════════════════════════════════ */
.card {
  background   : var(--white);
  border-radius: var(--radius);
  box-shadow   : var(--shadow);
  margin-bottom: 1.25rem;
}
.card-header {
  display       : flex;
  align-items   : center;
  justify-content: space-between;
  padding       : 1rem 1.25rem;
  border-bottom : 1px solid var(--gray-light);
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--blue); margin-bottom: .75rem; padding: .75rem 1rem 0; }

/* ══════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════ */
.btn {
  display      : inline-flex;
  align-items  : center;
  gap          : .35rem;
  padding      : .55rem 1.2rem;
  border-radius: 8px;
  font-size    : .88rem;
  font-weight  : 600;
  transition   : all var(--transition);
  white-space  : nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--orange); color: white; }
.btn-primary:hover:not(:disabled)  { background: var(--orange-dark); transform: translateY(-1px); }
.btn-secondary{ background: var(--gray-light); color: var(--gray); }
.btn-secondary:hover:not(:disabled){ background: #e2e4e8; }
.btn-edit     { background: var(--blue-light); color: var(--blue); }
.btn-edit:hover { background: #c9d8f5; }
.btn-delete   { background: #FEE2E2; color: var(--red); }
.btn-delete:hover { background: #fecaca; }
.btn-warning  { background: #FEF3C7; color: #92400E; }
.btn-warning:hover { background: #fde68a; }
.btn-sm { padding: .3rem .75rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; padding: .75rem; }

/* ══════════════════════════════════════════════════════════
   FORMS
══════════════════════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--gray); }
.form-full { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }

.form-control {
  padding      : .55rem .85rem;
  border       : 1.5px solid #D1D5DB;
  border-radius: 8px;
  outline      : none;
  transition   : border var(--transition), box-shadow var(--transition);
  width        : 100%;
  background   : white;
}
.form-control:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,107,0,.15); }
.form-control-sm { padding: .35rem .65rem; font-size: .82rem; }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 70px; }

/* ══════════════════════════════════════════════════════════
   TABLES
══════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }
.data-table {
  width        : 100%;
  border-collapse: collapse;
  font-size    : .85rem;
}
.data-table th {
  background   : var(--blue);
  color        : white;
  padding      : .65rem 1rem;
  text-align   : left;
  white-space  : nowrap;
  font-weight  : 600;
}
.data-table td {
  padding      : .6rem 1rem;
  border-bottom: 1px solid var(--gray-light);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--orange-light); }
.data-table tr.row-zero td { background: #FEF2F2; }
.data-table tr.row-low  td { background: #FFFBEB; }
.no-data-cell { text-align: center; color: var(--gray); padding: 2rem; }
.action-cell { white-space: nowrap; }

.qty-cell   { text-align: right; font-weight: 600; }
.qty-zero   { color: var(--red); }
.qty-low    { color: #D97706; }
.qty-highlight { color: var(--orange); font-weight: 700; font-size: 1.1rem; }

/* ══════════════════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════════════════ */
.badge {
  display      : inline-block;
  padding      : .15rem .55rem;
  border-radius: 50px;
  font-size    : .75rem;
  font-weight  : 600;
  white-space  : nowrap;
}
.badge-orange { background: #FFF3EB; color: var(--orange); }
.badge-blue   { background: var(--blue-light); color: var(--blue); }
.badge-purple { background: #F3EEF8; color: var(--purple); }
.badge-red    { background: #FEE2E2; color: var(--red); }
.badge-green  { background: #DCFCE7; color: var(--green); }
.badge-gray   { background: var(--gray-light); color: var(--gray); }

/* ══════════════════════════════════════════════════════════
   TABS
══════════════════════════════════════════════════════════ */
.tab-bar {
  display     : flex;
  gap         : .35rem;
  padding     : .75rem 1rem;
  flex-wrap   : wrap;
}
.tab-btn {
  padding     : .45rem 1rem;
  border-radius: 30px;
  background  : var(--gray-light);
  color       : var(--gray);
  font-size   : .85rem;
  font-weight : 600;
  transition  : all var(--transition);
}
.tab-btn:hover  { background: var(--orange-light); color: var(--orange); }
.tab-btn.active { background: var(--orange); color: white; }

/* ══════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════ */
.modal-overlay {
  display       : none;
  position      : fixed;
  inset         : 0;
  background    : rgba(0,0,0,.5);
  z-index       : 500;
  align-items   : center;
  justify-content: center;
  padding       : 1rem;
  overflow-y    : auto;
}
.modal-overlay.show { display: flex; }
.modal-dialog {
  background   : white;
  border-radius: 14px;
  width        : 100%;
  max-width    : 560px;
  max-height   : 90vh;
  overflow-y   : auto;
  animation    : slideUp .25s ease;
}
.modal-lg { max-width: 700px; }
.modal-header {
  display        : flex;
  align-items    : center;
  justify-content: space-between;
  padding        : 1.1rem 1.5rem;
  border-bottom  : 2px solid var(--orange);
  background     : var(--orange-light);
  border-radius  : 14px 14px 0 0;
}
.modal-header h3 { font-size: 1rem; color: var(--blue); }
.modal-close { background: none; font-size: 1.2rem; color: var(--gray); }
.modal-body    { padding: 1.25rem 1.5rem; }
.modal-footer  {
  display       : flex;
  justify-content: flex-end;
  gap           : .75rem;
  padding       : 1rem 1.5rem;
  border-top    : 1px solid var(--gray-light);
}

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

/* ══════════════════════════════════════════════════════════
   DASHBOARD
══════════════════════════════════════════════════════════ */
.filter-bar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; flex-wrap: wrap; gap: .5rem; }
.filter-inner { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.date-filters { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .85rem; }

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.cards-row-6 {
  grid-template-columns: repeat(6, 1fr);
}
@media (max-width: 1200px) { .cards-row-6 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .cards-row-6 { grid-template-columns: repeat(2, 1fr); } }
.cards-row-6 .summary-card { padding: 1rem; }
.cards-row-6 .sc-icon  { font-size: 1.8rem; }
.cards-row-6 .sc-value { font-size: 1.5rem; }
.cards-row-6 .sc-label { font-size: .75rem; }

/* ── Reports page ─────────────────────────────────────── */
.report-tabs {
  display       : flex;
  gap           : .4rem;
  flex-wrap     : wrap;
  margin-bottom : .75rem;
}
.report-tab {
  display       : inline-flex;
  align-items   : center;
  gap           : .35rem;
  padding       : .5rem .9rem;
  background    : white;
  border        : 1px solid #d1d5db;
  border-radius : 999px;
  cursor        : pointer;
  font-size     : .85rem;
  font-weight   : 500;
  color         : #374151;
  transition    : all var(--transition);
}
.report-tab:hover  { background: #f3f4f6; border-color: var(--blue); color: var(--blue); }
.report-tab.active {
  background  : var(--blue);
  border-color: var(--blue);
  color       : white;
  box-shadow  : 0 2px 6px rgba(30,90,168,.3);
}

.rp-filter {
  padding       : .75rem 1rem;
  margin-bottom : .75rem;
  display       : flex;
  align-items   : flex-end;
  gap           : .75rem;
  flex-wrap     : wrap;
}
.rp-fields {
  display              : grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap                  : .5rem .75rem;
  flex                 : 1;
}
.rp-field { display: flex; flex-direction: column; gap: .2rem; }
.rp-field label {
  font-size  : .72rem;
  color      : #6b7280;
  font-weight: 500;
}
.rp-actions { display: flex; gap: .4rem; }

.report-data-card { min-height: 60vh; }
.summary-card {
  background   : white;
  border-radius: var(--radius);
  box-shadow   : var(--shadow);
  padding      : 1.25rem;
  display      : flex;
  align-items  : center;
  gap          : 1rem;
}
.sc-icon { font-size: 2.5rem; }
.sc-label { font-size: .8rem; color: var(--gray); font-weight: 500; }
.sc-value { font-size: 2rem; font-weight: 700; color: var(--blue); }
.card-in  { border-left: 4px solid var(--green); }
.card-out { border-left: 4px solid var(--orange); }

.charts-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.chart-card { padding: .75rem; }
.chart-card-wide { padding: .75rem; }
.chart-container    { height: 260px; position: relative; }
.chart-container-sm { height: 320px; position: relative; max-width: 600px; margin: 0 auto; }

/* ══════════════════════════════════════════════════════════
   INVENTORY
══════════════════════════════════════════════════════════ */
/* ── Filter Panel (Inventory pages) ──────────────────────── */
.filter-panel { padding: .65rem 1rem; }
.filter-row {
  display    : flex;
  align-items: center;
  flex-wrap  : wrap;
  gap        : .75rem;
}
.filter-row + .filter-row { margin-top: .5rem; }
.filter-field {
  display    : flex;
  align-items: center;
  gap        : .4rem;
}
.filter-label {
  font-size  : .82rem;
  color      : var(--gray);
  white-space: nowrap;
}
.filter-field .form-control { width: 160px; }
.filter-lot-range { gap: .3rem; }
.filter-lot-range .form-control { width: 100px; }
.filter-sep { font-size: .82rem; color: var(--gray); }
.filter-actions {
  display    : flex;
  align-items: center;
  gap        : .4rem;
  margin-left: auto;
}
.btn-blue { background: var(--blue); color: white; }
.btn-blue:hover:not(:disabled) { background: var(--blue-dark); transform: translateY(-1px); }

/* Autocomplete */
.ac-wrap { position: relative; }
.ac-wrap .form-control { width: 100%; }
.ac-combo .form-control { padding-right: 2rem; }
.ac-caret {
  position   : absolute;
  right      : .5rem;
  top        : 50%;
  transform  : translateY(-50%);
  background : none;
  border     : none;
  cursor     : pointer;
  padding    : 0 .25rem;
  color      : #6b7280;
  font-size  : .85rem;
}
.ac-caret:hover { color: var(--blue); }
.ac-combo .form-control:disabled + .ac-caret { color: #cbd5e1; cursor: not-allowed; }
.ac-dropdown {
  display     : none;
  position    : absolute;
  top         : calc(100% + 4px);
  left        : 0;
  min-width   : 300px;
  z-index     : 1000;
  background  : var(--white);
  border      : 1px solid #d1d5db;
  border-radius: var(--radius);
  box-shadow  : var(--shadow-md);
  max-height  : 280px;
  overflow-y  : auto;
}
.ac-dropdown.open { display: block; }
.ac-item {
  display       : flex;
  flex-direction: column;
  gap           : .1rem;
  padding       : .5rem .75rem;
  cursor        : pointer;
  border-bottom : 1px solid var(--gray-light);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--blue-light); }
.ac-code { font-weight: 600; color: var(--blue); font-size: .875rem; }
.ac-name { font-size: .875rem; color: #111827; }
.ac-meta { font-size: .72rem; color: var(--gray); }

.inv-info-box {
  background   : var(--blue-light);
  border-left  : 4px solid var(--blue);
  border-radius: 8px;
  padding      : .85rem 1rem;
  font-size    : .88rem;
  line-height  : 1.7;
}

/* ══════════════════════════════════════════════════════════
   REPORTS
══════════════════════════════════════════════════════════ */
.row-count { font-size: .82rem; color: var(--gray); }

/* ══════════════════════════════════════════════════════════
   SKELETON LOADING
══════════════════════════════════════════════════════════ */
.skeleton-wrap { padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.skeleton, .skeleton-card {
  background : linear-gradient(90deg, #E5E7EB 25%, #F3F4F6 50%, #E5E7EB 75%);
  background-size: 200% 100%;
  animation  : shimmer 1.4s infinite;
  border-radius: 8px;
  height     : 24px;
  width      : 100%;
}
.skeleton-card { height: 100px; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  display      : inline-block;
  width        : 14px;
  height       : 14px;
  border       : 2px solid rgba(255,255,255,.4);
  border-top   : 2px solid white;
  border-radius: 50%;
  animation    : spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── No data ─────────────────────────────────────────────── */
.no-data {
  text-align : center;
  padding    : 3rem 1rem;
  color      : var(--gray);
  font-size  : .95rem;
}
.error-text { color: var(--red); }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE – Mobile
══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width    : 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main-wrap { margin-left: 0; }
  .hamburger { display: block; }

  .form-grid { grid-template-columns: 1fr; }
  .charts-row { grid-template-columns: 1fr; }
  .filter-row { gap: .5rem; }
  .filter-field .form-control { width: 130px; }
  .filter-actions { margin-left: 0; }
  .filter-bar { flex-direction: column; align-items: flex-start; }
  .date-filters { flex-wrap: wrap; }

  .page-content { padding: 1rem; }
  .card-header { flex-wrap: wrap; gap: .5rem; }

  .data-table { font-size: .78rem; }
  .data-table th, .data-table td { padding: .5rem .65rem; }

  .modal-dialog { max-width: 100%; margin: 0; border-radius: 14px 14px 0 0; position: fixed; bottom: 0; left: 0; right: 0; max-height: 95vh; }
  .modal-overlay.show { align-items: flex-end; padding: 0; }
}

@media (max-width: 480px) {
  .sc-value { font-size: 1.6rem; }
  .login-card { padding: 1.75rem 1.25rem; }
  .btn { padding: .45rem .85rem; font-size: .82rem; }
}
