/* =========================================
   APP LAYOUT – Sidebar, Topbar, Main
   ========================================= */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&display=swap');

/* --- App Body --- */
.app-body {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
}

/* ================== SIDEBAR ================== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #fff;
  border-right: 1px solid var(--outline-var);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

/* --- Brand --- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--surface-mid);
}
.brand-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  mix-blend-mode: multiply;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title {
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--on-surface);
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--on-surface-var);
  font-weight: 500;
}

/* --- Nav Items --- */
.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--on-surface-var);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s ease;
  position: relative;
  min-height: var(--touch-target);
}
.nav-item .material-icons-round { font-size: 20px; flex-shrink: 0; }
.sidebar-divider {
  height: 1px;
  background: var(--surface-mid);
  margin: 6px 14px;
}
.nav-item:hover {
  background: var(--surface-low);
  color: var(--primary-light);
  text-decoration: none;
}
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-light);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--primary-light);
  border-radius: 0 3px 3px 0;
}
.nav-export-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  margin-left: auto;
}
.nav-divider {
  height: 1px;
  background: var(--outline-var);
  margin: 8px 0;
}

/* --- Sidebar User --- */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--surface-mid);
  background: var(--surface-low);
}
.user-avatar {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--primary-light), var(--tertiary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  display: block;
  font-size: 0.72rem;
  color: var(--on-surface-var);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout-btn {
  background: none;
  border: none;
  color: var(--on-surface-var);
  display: flex;
  padding: 4px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--accent-red); }
.logout-btn .material-icons-round { font-size: 18px; }

/* ================== OVERLAY ================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.4);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ================== MAIN CONTENT ================== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s;
  min-width: 0;
  width: 0; /* combined with flex:1 this prevents content from setting the width */
  overflow-x: clip;
}

/* ================== TOPBAR ================== */
.topbar {
  height: var(--topbar-h);
  background: rgba(247,249,251,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--outline-var);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--on-surface);
  padding: 10px;
  border-radius: var(--radius-sm);
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  align-items: center;
  justify-content: center;
}
.menu-toggle .material-icons-round { font-size: 24px; }

.mobile-search-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--on-surface);
  padding: 10px;
  border-radius: var(--radius-sm);
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  align-items: center;
  justify-content: center;
}
.mobile-search-toggle .material-icons-round { font-size: 24px; }

.topbar-search {
  flex: 1;
  max-width: 500px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-low);
  border: 1.5px solid var(--outline-var);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.topbar-search:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.search-icon { font-size: 18px !important; color: var(--outline); }
.topbar-search input {
  flex: 1;
  font-size: 0.875rem;
  background: transparent;
}

.global-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  background: #fff;
  border: 1px solid var(--outline-var);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}
.global-search-dropdown.open { display: block; }
.global-search-dropdown .gs-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--on-surface);
  transition: background 0.1s;
}
.global-search-dropdown .gs-item:hover,
.global-search-dropdown .gs-item.highlighted {
  background: var(--primary-soft);
}
.global-search-dropdown .gs-item .material-icons-round {
  font-size: 20px;
  color: var(--primary-light);
}
.global-search-dropdown .gs-item .gs-label { font-weight: 600; }
.global-search-dropdown .gs-empty {
  padding: 16px;
  text-align: center;
  color: var(--on-surface-var);
  font-size: 0.85rem;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar-btn {
  position: relative;
  background: var(--surface-low);
  border: 1.5px solid var(--outline-var);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  color: var(--on-surface-var);
  transition: all 0.15s;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  align-items: center;
  justify-content: center;
}
.topbar-btn:hover { border-color: var(--primary-light); color: var(--primary-light); }
.topbar-btn .material-icons-round { font-size: 20px; }

.mobile-search-bar {
  display: none;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline-var);
}
.mobile-search-bar.active { display: flex; }
.mobile-search-bar .topbar-search {
  max-width: 100%;
  flex: 1;
}
.topbar-btn .badge {
  position: absolute;
  top: -5px; right: -5px;
  background: var(--accent-red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary-light), var(--tertiary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
}

/* ================== TOPBAR BRAND ================== */
/* Hidden on desktop — sidebar already shows the logo */
.topbar-brand {
  display: none;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
}
.topbar-brand-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
  mix-blend-mode: multiply;
}
.topbar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.topbar-brand-title {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--on-surface);
  white-space: nowrap;
}
.topbar-brand-sub {
  font-size: 0.68rem;
  color: var(--on-surface-var);
  font-weight: 500;
  white-space: nowrap;
}

/* Mobile-only topbar title: hidden on desktop, shown on mobile */
.topbar-mobile-title {
  display: none;
  align-items: center;
  gap: 6px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-head);
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--on-surface);
  letter-spacing: -0.01em;
  pointer-events: none;
  user-select: none;
}

/* ================== PAGE BODY ================== */
.page-body {
  flex: 1;
  padding: 28px 28px 48px;
  max-width: 1400px;
  width: 100%;
  box-sizing: border-box;
  overflow-x: clip;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-head);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--on-surface);
  line-height: 1.2;
}
.page-sub { color: var(--on-surface-var); font-size: 0.875rem; margin-top: 4px; }
.header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.date-badge {
  background: var(--primary-soft);
  color: var(--primary-light);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-full);
}

/* ================== NOTIFICATION PANEL ================== */
.notif-panel {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  right: 24px;
  width: 340px;
  z-index: 500;
  padding: 0;
  overflow: hidden;
  animation: notifIn 0.2s ease;
}
@keyframes notifIn {
  from { opacity:0; transform: translateY(-10px); }
  to   { opacity:1; transform: translateY(0); }
}
.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--outline-var);
}
.notif-header h4 { font-size: 0.9rem; font-weight: 700; }
.notif-header button {
  background: none;
  border: none;
  font-size: 0.78rem;
  color: var(--primary-light);
  font-weight: 600;
}
.notif-list { padding: 8px; }
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s;
}
.notif-item:hover { background: var(--surface-low); }
.notif-item .material-icons-round {
  color: var(--primary-light);
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 6px;
  font-size: 18px !important;
  flex-shrink: 0;
}
.notif-item.urgent .material-icons-round { color: var(--accent-red); background: rgba(239,68,68,0.1); }
.notif-item strong { font-size: 0.82rem; font-weight: 700; display: block; }
.notif-item p { font-size: 0.78rem; color: var(--on-surface-var); margin-top: 2px; }
.notif-item small { font-size: 0.72rem; color: var(--outline); }

/* ================== VIEW TOGGLE ================== */
.view-toggle {
  display: flex;
  background: var(--surface-low);
  border: 1.5px solid var(--outline-var);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.view-btn {
  background: transparent;
  border: none;
  padding: 8px 12px;
  display: flex;
  color: var(--on-surface-var);
  transition: all 0.15s;
}
.view-btn:hover { background: var(--surface-mid); color: var(--primary-light); }
.view-btn.active { background: var(--primary-light); color: #fff; }
.view-btn .material-icons-round { font-size: 18px; }

/* ================== RESPONSIVE ================== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-content {
    margin-left: 0;
    max-width: 100%;
    overflow-x: hidden;
  }
  .menu-toggle { display: flex; }
  .page-body { padding: 20px 10px 40px; }
  .notif-panel {
    right: 12px;
    width: 320px;
  }
  /* Sidebar is hidden on mobile — show the topbar brand logo */
  .topbar-brand { display: flex; }
}
@media (max-width: 768px) {
  .notif-panel {
    right: 8px;
    left: 8px;
    width: auto;
    top: calc(var(--topbar-h) + 4px);
  }
  /* Hide brand on small screens — mobile title takes over */
  .topbar-brand {
    display: none;
  }
  /* Show the mobile-only centred title instead of full brand text */
  .topbar-mobile-title {
    display: flex;
  }
}
@media (max-width: 600px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-search { display: none; }
  .mobile-search-toggle { display: flex; }
  .page-header { flex-direction: column; }
  .page-title { font-size: 1.4rem; }
  .page-body { padding: 14px 10px 32px; }
  .topbar-btn { padding: 10px; }
  .date-badge { font-size: 0.72rem; padding: 4px 10px; }
  .sidebar-nav { padding: 12px 8px; }
  .nav-item { padding: 10px 12px; font-size: 0.82rem; min-height: var(--touch-target); }
  .sidebar-brand { padding: 14px 14px 12px; }
  .brand-title { font-size: 0.95rem; }
  .sidebar-user { padding: 10px 12px; }
  .view-btn { padding: 8px 10px; }
}
@media (max-width: 400px) {
  .page-body { padding: 10px 8px 24px; }
  .topbar { padding: 0 8px; gap: 4px; }
}

/* ================== TECHSIAH BRANDING ================== */
.techsiah-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1.5px dashed var(--outline-var);
  background: var(--surface-low);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--on-surface-var);
  transition: all 0.2s ease;
}

.techsiah-badge:hover {
  background: var(--surface-mid);
  text-decoration: none;
}

.techsiah-badge svg {
  width: 14px;
  height: 14px;
  display: block;
}

.techsiah-badge .techsiah-label {
  color: var(--outline);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.techsiah-badge .techsiah-text {
  font-family: 'Outfit', var(--font-body);
  font-weight: 700;
  color: var(--on-bg);
  letter-spacing: -0.2px;
  transition: color 0.2s ease;
}

.techsiah-badge:hover .techsiah-text {
  color: #2563EB;
}

.techsiah-badge .techsiah-dot {
  color: #2563EB;
}

/* ================== FILTER BAR ================== */
.list-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-low);
  border: 1px solid var(--outline-var);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.list-filter-bar input[type="date"],
.list-filter-bar input[type="time"] {
  background: var(--surface);
  border: 1px solid var(--outline-var);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.78rem;
  color: var(--on-surface);
  font-family: var(--font-body);
}
.list-filter-bar button {
  padding: 4px 10px;
  font-size: 0.78rem;
}

/* =============================================
   DASHBOARD TABS (Added for Single-Widget View)
   ============================================= */
.dashboard-tabs {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--surface-mid);
  padding-bottom: 12px;
  overflow-x: auto;
}
.dashboard-tab-btn {
  background: none;
  border: none;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--on-surface-var);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  white-space: nowrap;
}
.dashboard-tab-btn:hover {
  background: var(--surface-mid);
  color: var(--on-surface);
}
.dashboard-tab-btn.active {
  background: var(--primary-light);
  color: white;
}
.dashboard-tab-pane {
  display: none;
  animation: fadeIn 0.3s ease;
}
.dashboard-tab-pane.active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================== DATA TABLES ================== */
.data-table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--outline-var);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-top: 12px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px; /* Forces scroll on small screens */
  font-size: 0.85rem;
  color: var(--on-surface);
}
.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--outline-var);
}
.data-table th {
  background: #f2f4f6;
  color: var(--on-surface-var);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 var(--outline-var); /* border that stays visible under scroll */
}
.data-table tr:hover {
  background: rgba(13,148,136,0.04);
}
.data-table td.qty-critical { color: var(--accent-red); font-weight: 700; }
.data-table td.qty-low { color: #d97706; font-weight: 600; }
.data-table td.qty-ok { color: #059669; font-weight: 600; }

.pagination-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-top: 8px;
}
.pagination-controls .btn-secondary {
  padding: 6px 12px;
  font-size: 0.8rem;
}
