/* ===== CSS VARIABLES ===== */
:root {
  --bg-dark: #262626;
  --brand-red: #6B0000;
  --brand-red-light: #8B0000;
  --white: #FFFFFF;
  --gray-100: #F5F5F5;
  --gray-200: #E8E8E8;
  --gray-300: #C8C8C8;
  --gray-400: #A0A0A0;
  --gray-500: #707070;
  --gray-600: #505050;
  --sidebar-width: 240px;
  --sidebar-collapsed: 68px;
  --topbar-height: 64px;
  --border-radius: 10px;
  --border-radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.18);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.28);
  --transition: all 0.22s cubic-bezier(.4,0,.2,1);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--gray-100); color: var(--bg-dark); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }
input, select, textarea { font-family: inherit; outline: none; }
ul, ol { list-style: none; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--gray-200); }
::-webkit-scrollbar-thumb { background: var(--gray-400); border-radius: 3px; }

/* ===== LOGIN SCREEN ===== */
.login-screen {
  position: fixed; inset: 0;
  background: var(--bg-dark);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

.login-container {
  background: #2e2e2e;
  border-radius: 18px;
  padding: 48px 40px;
  width: 90%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  border: 1px solid #3a3a3a;
}

.login-logo {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin-bottom: 32px;
}

/* Real SVG logo wrappers */
.fn-logo-wrap {
  display: flex; align-items: center; justify-content: center;
}

.fn-logo-sidebar {
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.login-brand {
  font-size: 1.1rem; font-weight: 700; letter-spacing: 2px;
  color: var(--white); margin-top: 4px;
}

.login-user-select h2 {
  color: var(--white); font-size: 1rem; font-weight: 600;
  text-align: center; margin-bottom: 20px;
}

.user-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}

.user-card {
  background: #3a3a3a;
  border: 2px solid #444;
  border-radius: var(--border-radius);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--white);
}

.user-card:hover {
  border-color: var(--brand-red);
  background: #3e3e3e;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(107,0,0,0.3);
}

.user-card .avatar-big {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--brand-red);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700;
  margin: 0 auto 10px;
  color: var(--white);
}

.user-card .user-card-name { font-size: 0.82rem; font-weight: 600; }
.user-card .user-card-role {
  font-size: 0.72rem; color: var(--gray-400); margin-top: 4px;
}

/* PIN Section */
.login-pin-section { text-align: center; }
.login-pin-section h3 { color: var(--white); font-size: 1rem; margin-bottom: 20px; }

.selected-user-info {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-bottom: 24px;
}

.selected-user-info .avatar-big {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--brand-red);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700;
  color: var(--white);
}

.selected-user-info .sel-name { color: var(--white); font-weight: 600; font-size: 1.05rem; }

.pin-display {
  display: flex; gap: 14px; justify-content: center; margin-bottom: 28px;
}

.pin-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--gray-400);
  background: transparent;
  transition: var(--transition);
}

.pin-dot.filled {
  background: var(--brand-red);
  border-color: var(--brand-red);
}

.pin-keypad {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; max-width: 240px; margin: 0 auto 16px;
}

.pin-key {
  height: 58px;
  background: #3a3a3a;
  border-radius: var(--border-radius-sm);
  font-size: 1.3rem; font-weight: 600; color: var(--white);
  transition: var(--transition);
  border: 1px solid #4a4a4a;
}

.pin-key:hover { background: #4a4a4a; }
.pin-key:active { transform: scale(0.95); }

.pin-back { color: var(--gray-400); font-size: 1rem; }
.pin-enter { background: var(--brand-red); }
.pin-enter:hover { background: var(--brand-red-light); }

.pin-error {
  color: #ff6b6b; font-size: 0.82rem;
  display: none; margin-bottom: 12px;
}

.pin-error.show { display: block; }

.btn-back-users {
  background: none; color: var(--gray-400);
  font-size: 0.85rem; padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  transition: var(--transition);
}

.btn-back-users:hover { color: var(--white); background: #3a3a3a; }

/* ===== APP LAYOUT ===== */
.app {
  display: flex; height: 100vh; overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-dark);
  display: flex; flex-direction: column;
  transition: width 0.28s cubic-bezier(.4,0,.2,1);
  flex-shrink: 0;
  z-index: 100;
  position: relative; /* needed for user-menu-popup absolute positioning */
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .user-details { display: none; }

/* Sidebar logo scaling */
.fn-logo-sidebar svg { display: block; }


.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid #3a3a3a;
  min-height: var(--topbar-height);
}

.sidebar-brand {
  font-size: 0.85rem; font-weight: 700; letter-spacing: 1.5px;
  color: var(--white); flex: 1;
}

.sidebar-toggle {
  background: none; color: var(--gray-400);
  padding: 6px; border-radius: 5px;
  transition: var(--transition); font-size: 1rem;
}

.sidebar-toggle:hover { color: var(--white); background: #3a3a3a; }

.sidebar-nav {
  flex: 1; padding: 16px 0; overflow-y: auto;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px;
  color: var(--gray-400);
  font-size: 0.88rem; font-weight: 500;
  border-radius: 8px; margin: 2px 8px;
  transition: var(--transition);
  position: relative; white-space: nowrap; overflow: hidden;
}

.nav-item:hover { color: var(--white); background: #3a3a3a; }
.nav-item.active { color: var(--white); background: var(--brand-red); }
.nav-item i { width: 18px; text-align: center; font-size: 1rem; flex-shrink: 0; }

.nav-item .badge {
  background: #ff4444; color: white;
  border-radius: 50%; width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 700; margin-left: auto;
}

.sidebar-footer {
  border-top: 1px solid #3a3a3a;
  padding: 14px;
  display: flex; align-items: center; gap: 10px;
}

.current-user {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
}

.avatar-circle {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand-red);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: var(--white);
}

.user-details { min-width: 0; }
.user-name { display: block; font-size: 0.82rem; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 0.72rem; color: var(--gray-400); }

.btn-logout {
  background: none; color: var(--gray-500); padding: 6px;
  border-radius: 5px; transition: var(--transition);
}

.btn-logout:hover { color: #ff6b6b; background: #3a3a3a; }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; background: var(--gray-100);
}

/* ===== TOPBAR ===== */
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.topbar-left { display: flex; align-items: center; gap: 14px; }
.page-title { font-size: 1.25rem; font-weight: 700; color: var(--bg-dark); }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; font-weight: 600; color: var(--bg-dark);
}

.sidebar-toggle-mobile {
  display: none; background: none; font-size: 1.1rem;
  color: var(--bg-dark); padding: 6px;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--brand-red); color: var(--white);
  padding: 9px 18px; border-radius: var(--border-radius-sm);
  font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
  transition: var(--transition);
}

.btn-primary:hover { background: var(--brand-red-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(107,0,0,0.3); }

.btn-secondary {
  background: var(--gray-200); color: var(--bg-dark);
  padding: 9px 18px; border-radius: var(--border-radius-sm);
  font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
  transition: var(--transition);
}

.btn-secondary:hover { background: var(--gray-300); }

.btn-danger {
  background: #8B0000; color: var(--white);
  padding: 9px 18px; border-radius: var(--border-radius-sm);
  font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
  transition: var(--transition);
}

.btn-danger:hover { background: #a00000; }

.btn-icon {
  background: var(--gray-200); color: var(--bg-dark);
  padding: 8px; border-radius: var(--border-radius-sm);
  font-size: 0.9rem; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}

.btn-icon:hover { background: var(--gray-300); }

/* ===== PAGES ===== */
.page { display: none; flex: 1; overflow-y: auto; padding: 24px; }
.page.active { display: block; }

/* ===== CARDS / WIDGETS ===== */
.widget-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  transition: var(--transition);
}

.widget-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.12); }

.widget-card.clickable { cursor: pointer; }
.widget-card.clickable:hover { transform: translateY(-2px); }

.widget-title {
  font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--gray-500); margin-bottom: 10px;
}

.widget-value {
  font-size: 2.2rem; font-weight: 800; color: var(--bg-dark); line-height: 1;
}

.widget-value.red { color: var(--brand-red); }

.widget-icon {
  width: 44px; height: 44px;
  background: #F8E8E8;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--brand-red); font-size: 1.2rem;
}

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

.dashboard-grid .span-2 { grid-column: span 2; }
.dashboard-grid .span-3 { grid-column: span 3; }
.dashboard-grid .span-4 { grid-column: span 4; }

.stats-row {
  display: flex; justify-content: space-between; align-items: flex-start;
}

/* ===== TABLES ===== */
.table-container {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}

.table-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}

.table-title { font-size: 1rem; font-weight: 700; }

.data-table {
  width: 100%; border-collapse: collapse;
}

.data-table th {
  background: var(--bg-dark); color: var(--white);
  padding: 12px 16px; text-align: left;
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
}

.data-table td {
  padding: 12px 16px;
  font-size: 0.85rem; color: var(--bg-dark);
  border-bottom: 1px solid var(--gray-200);
}

.data-table tr:hover td { background: var(--gray-100); }
.data-table tr:last-child td { border-bottom: none; }

/* ===== BADGES / STATUS ===== */
.status-badge {
  padding: 4px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-block;
}

.status-pendente { background: #FFF3CD; color: #856404; }
.status-aprovado { background: #D4EDDA; color: #155724; }
.status-em_impressao { background: #CCE5FF; color: #004085; }
.status-finalizado { background: #D4EDDA; color: #155724; }
.status-cancelado { background: #F8D7DA; color: #721C24; }
.status-tarefa { background: #E2E3E5; color: #383D41; }
.status-em_distribuicao { background: #E8D5FF; color: #5B00A0; }
.status-entregue { background: #C3F0CA; color: #0A5C1B; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 0.82rem; font-weight: 600;
  color: var(--gray-600); margin-bottom: 6px;
}

.form-control {
  width: 100%; padding: 10px 14px;
  background: var(--gray-100); border: 1.5px solid var(--gray-200);
  border-radius: var(--border-radius-sm); font-size: 0.88rem;
  color: var(--bg-dark); transition: var(--transition);
}

.form-control:focus { border-color: var(--brand-red); background: var(--white); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--gray-200);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--white);
  border-radius: 14px;
  padding: 28px;
  width: 90%; max-width: 600px;
  max-height: 88vh; overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-box.wide { max-width: 860px; }
.modal-box.narrow { max-width: 440px; }

.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--gray-200); border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-600); font-size: 0.8rem;
  transition: var(--transition);
}

.modal-close:hover { background: var(--gray-300); color: var(--bg-dark); }

.modal-title {
  font-size: 1.2rem; font-weight: 700; color: var(--bg-dark);
  margin-bottom: 20px; padding-right: 30px;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: var(--bg-dark); color: var(--white);
  padding: 12px 18px; border-radius: 8px;
  font-size: 0.85rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: slideInToast 0.3s ease;
  min-width: 260px;
}

.toast.success { border-left: 4px solid #28a745; }
.toast.error { border-left: 4px solid #dc3545; }
.toast.info { border-left: 4px solid #17a2b8; }
.toast.warning { border-left: 4px solid #ffc107; }

@keyframes slideInToast {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== SEARCH & FILTERS ===== */
.search-filter-bar {
  display: flex; gap: 12px; align-items: center;
  margin-bottom: 18px; flex-wrap: wrap;
}

.search-input-wrap {
  position: relative; flex: 1; min-width: 220px;
}

.search-input-wrap i {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--gray-400); font-size: 0.9rem;
}

.search-input-wrap input {
  width: 100%; padding: 9px 14px 9px 36px;
  background: var(--white); border: 1.5px solid var(--gray-200);
  border-radius: var(--border-radius-sm); font-size: 0.88rem;
}

.search-input-wrap input:focus { border-color: var(--brand-red); }

.filter-select {
  padding: 9px 14px; background: var(--white);
  border: 1.5px solid var(--gray-200); border-radius: var(--border-radius-sm);
  font-size: 0.85rem; color: var(--bg-dark); min-width: 140px;
}

.filter-select:focus { border-color: var(--brand-red); }

/* ===== TASK CARDS ===== */
.task-list-wrap {
  display: flex; flex-direction: column; gap: 10px;
}

.task-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  border: 1.5px solid var(--gray-200);
  display: flex; align-items: center; gap: 16px;
  transition: var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.task-card:hover { border-color: var(--brand-red); box-shadow: var(--shadow); }

.task-card-left { flex: 1; min-width: 0; }
.task-card-title { font-size: 0.92rem; font-weight: 600; color: var(--bg-dark); }
.task-card-meta { font-size: 0.78rem; color: var(--gray-500); margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }
.task-card-meta span { display: flex; align-items: center; gap: 5px; }

.task-card-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ===== STOCK GRID ===== */
.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.filament-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 18px;
  border: 1.5px solid var(--gray-200);
  transition: var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  cursor: pointer;
}

.filament-card:hover { border-color: var(--brand-red); box-shadow: var(--shadow); transform: translateY(-2px); }

.filament-color-bar {
  height: 8px; border-radius: 4px;
  margin-bottom: 14px;
}

.filament-brand { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.8px; color: var(--gray-400); font-weight: 600; }
.filament-name { font-size: 0.95rem; font-weight: 700; color: var(--bg-dark); margin-top: 2px; }
.filament-material { font-size: 0.8rem; color: var(--gray-500); margin-top: 2px; }
.filament-stats { display: flex; justify-content: space-between; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--gray-200); }
.filament-stat { text-align: center; }
.filament-stat-val { font-size: 1rem; font-weight: 700; color: var(--bg-dark); }
.filament-stat-label { font-size: 0.68rem; color: var(--gray-400); text-transform: uppercase; }

.weight-bar-wrap {
  margin-top: 12px;
  height: 5px; background: var(--gray-200); border-radius: 3px; overflow: hidden;
}

.weight-bar { height: 100%; border-radius: 3px; transition: width 0.5s; }
.weight-bar.low { background: #dc3545; }
.weight-bar.mid { background: #ffc107; }
.weight-bar.high { background: #28a745; }

/* ===== CALCULATOR ===== */
.calc-container {
  display: grid; grid-template-columns: 1fr 360px;
  gap: 20px; align-items: start;
}

.calc-piece-card {
  background: var(--white); border-radius: var(--border-radius);
  padding: 20px; border: 1.5px solid var(--gray-200);
  margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.calc-piece-title {
  font-size: 0.92rem; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

.calc-filament-row {
  display: flex; gap: 10px; align-items: flex-end;
  margin-bottom: 10px; padding: 12px;
  background: var(--gray-100); border-radius: var(--border-radius-sm);
  flex-wrap: wrap;
}

.calc-summary {
  background: var(--white); border-radius: var(--border-radius);
  padding: 24px; border: 1.5px solid var(--gray-200);
  position: sticky; top: 0;
  box-shadow: var(--shadow);
}

.calc-summary-title {
  font-size: 1rem; font-weight: 700; margin-bottom: 16px;
  color: var(--bg-dark);
}

.calc-summary-row {
  display: flex; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--gray-200);
  font-size: 0.85rem;
}

.calc-summary-row.total {
  border-bottom: none; font-weight: 700; font-size: 1rem; margin-top: 8px;
}

.calc-total-value { color: var(--brand-red); font-size: 1.4rem; font-weight: 800; }

/* ===== CHAT ===== */
.chat-layout {
  display: grid; grid-template-columns: 260px 1fr;
  gap: 0; height: calc(100vh - var(--topbar-height) - 48px);
  background: var(--white); border-radius: var(--border-radius);
  overflow: hidden; border: 1px solid var(--gray-200); box-shadow: var(--shadow);
}

.chat-sidebar {
  background: #f8f8f8;
  border-right: 1px solid var(--gray-200);
  display: flex; flex-direction: column;
}

.chat-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--gray-200);
  font-weight: 700; font-size: 0.95rem;
}

.channel-list { flex: 1; overflow-y: auto; padding: 8px; }

.channel-item {
  padding: 10px 12px; border-radius: 7px;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; gap: 10px;
  font-size: 0.87rem; color: var(--gray-600);
}

.channel-item:hover { background: var(--gray-200); }
.channel-item.active { background: var(--brand-red); color: var(--white); }
.channel-item i { width: 16px; text-align: center; }

.chat-main { display: flex; flex-direction: column; }

.chat-topbar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 12px;
  background: var(--white);
}

.chat-channel-name { font-weight: 700; font-size: 0.95rem; }
.chat-channel-info { font-size: 0.78rem; color: var(--gray-400); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 14px;
}

.chat-message {
  display: flex; gap: 10px; align-items: flex-start;
}

.chat-message .msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-red);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 700; color: white; flex-shrink: 0;
}

.msg-content { flex: 1; }
.msg-header { display: flex; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.msg-author { font-size: 0.83rem; font-weight: 700; color: var(--bg-dark); }
.msg-time { font-size: 0.72rem; color: var(--gray-400); }
.msg-text {
  font-size: 0.87rem; color: var(--gray-600);
  background: var(--gray-100); padding: 10px 14px;
  border-radius: 0 10px 10px 10px; display: inline-block;
  max-width: 80%; line-height: 1.5;
}

.chat-message.own { flex-direction: row-reverse; }
.chat-message.own .msg-text {
  background: var(--brand-red); color: white;
  border-radius: 10px 0 10px 10px;
}
.chat-message.own .msg-header { flex-direction: row-reverse; }

.chat-input-wrap {
  padding: 14px 16px;
  border-top: 1px solid var(--gray-200);
  display: flex; gap: 10px; align-items: flex-end;
}

.chat-input-wrap textarea {
  flex: 1; resize: none; border: 1.5px solid var(--gray-200);
  border-radius: 8px; padding: 10px 14px; font-size: 0.88rem;
  max-height: 100px; line-height: 1.5;
}

.chat-input-wrap textarea:focus { border-color: var(--brand-red); }

/* ===== COLOR SWATCH ===== */
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-block; border: 2px solid rgba(0,0,0,0.15);
  vertical-align: middle;
}

/* ===== STATS INFO MODAL ===== */
.stats-modal-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px;
  margin-bottom: 20px;
}

.stat-item {
  background: var(--gray-100); border-radius: var(--border-radius-sm);
  padding: 14px; text-align: center;
}

.stat-item-val { font-size: 1.6rem; font-weight: 800; color: var(--brand-red); }
.stat-item-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gray-500); margin-top: 4px; }

.color-usage-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--gray-100);
  border-radius: var(--border-radius-sm); margin-bottom: 8px;
}

.color-usage-info { flex: 1; }
.color-usage-name { font-size: 0.85rem; font-weight: 600; }
.color-usage-details { font-size: 0.75rem; color: var(--gray-500); }

/* ===== QR CODE ===== */
.qr-container { text-align: center; padding: 16px; }
#qrcode-canvas img, #qrcode-canvas canvas { margin: 0 auto; }

/* ===== PROFILE ===== */
.profile-layout {
  max-width: 600px; margin: 0 auto;
}

.profile-header {
  background: var(--white); border-radius: var(--border-radius);
  padding: 32px; text-align: center; margin-bottom: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--gray-200);
}

.profile-avatar-big {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--brand-red); display: flex;
  align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: white;
  margin: 0 auto 16px; position: relative; cursor: pointer;
  overflow: hidden;
}

.profile-avatar-big img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-big .avatar-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: var(--transition);
}
.profile-avatar-big:hover .avatar-overlay { opacity: 1; }

.profile-name { font-size: 1.2rem; font-weight: 700; color: var(--bg-dark); }
.profile-role { font-size: 0.85rem; color: var(--gray-400); margin-top: 4px; }

/* ===== USERS PAGE ===== */
.users-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.user-manage-card {
  background: var(--white); border-radius: var(--border-radius);
  padding: 20px; border: 1.5px solid var(--gray-200);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05); transition: var(--transition);
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 8px;
}

.user-manage-card:hover { border-color: var(--brand-red); box-shadow: var(--shadow); }

.user-manage-card .avatar-big {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand-red); display: flex;
  align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700; color: white;
  overflow: hidden;
}

.user-manage-card .avatar-big img { width: 100%; height: 100%; object-fit: cover; }
.user-manage-name { font-weight: 700; font-size: 0.92rem; }
.user-manage-email { font-size: 0.78rem; color: var(--gray-400); }
.user-manage-role { font-size: 0.75rem; }
.user-card-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ===== DIVIDERS ===== */
.section-divider {
  border: none; border-top: 1px solid var(--gray-200); margin: 20px 0;
}

/* ===== PIN CHANGE ===== */
.pin-change-row {
  display: flex; gap: 12px; align-items: center;
}

.pin-stars { font-size: 1rem; letter-spacing: 4px; color: var(--gray-500); }

/* ===== APPROVAL FORM ===== */
.approval-section {
  background: var(--gray-100); border-radius: var(--border-radius-sm);
  padding: 16px; margin-bottom: 16px;
}

.filament-select-row {
  display: grid; grid-template-columns: 1fr 120px 120px 30px;
  gap: 8px; align-items: flex-end; margin-bottom: 8px;
}

/* ===== EMPTY STATES ===== */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--gray-400);
}
.empty-state i { font-size: 3rem; margin-bottom: 14px; display: block; }
.empty-state p { font-size: 0.9rem; }

/* ===== TASK TYPE SELECTOR ===== */
.task-type-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 8px;
}

.task-type-card {
  padding: 20px 12px; border-radius: var(--border-radius);
  border: 2px solid var(--gray-200); cursor: pointer;
  text-align: center; transition: var(--transition);
}

.task-type-card:hover { border-color: var(--brand-red); }
.task-type-card.selected { border-color: var(--brand-red); background: #FFF5F5; }
.task-type-card i { font-size: 1.6rem; color: var(--brand-red); display: block; margin-bottom: 10px; }
.task-type-card span { font-size: 0.85rem; font-weight: 600; display: block; }
.task-type-card small { font-size: 0.72rem; color: var(--gray-400); }

/* ===== SIDEBAR USER MENU POPUP ===== */
.user-menu-popup {
  position: absolute;
  bottom: 70px;
  left: 10px;
  right: 10px;
  background: #1e1e1e;
  border: 1px solid #3a3a3a;
  border-radius: var(--border-radius);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
  z-index: 200;
  overflow: hidden;
  animation: popupSlide 0.18s cubic-bezier(.4,0,.2,1);
}

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

.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  font-size: 0.86rem; font-weight: 500; color: var(--gray-300);
  cursor: pointer; transition: var(--transition);
}

.user-menu-item i { width: 16px; text-align: center; font-size: 0.9rem; }
.user-menu-item:hover { background: #2e2e2e; color: var(--white); }

.user-menu-danger { color: #ff6b6b !important; }
.user-menu-danger:hover { background: rgba(255,107,107,0.12) !important; }

.user-menu-divider {
  height: 1px; background: #3a3a3a; margin: 4px 0;
}

/* Sidebar footer button states */
.sidebar-footer {
  transition: var(--transition);
  user-select: none;
}
.sidebar-footer:hover { background: #2e2e2e; }
.sidebar-footer.menu-open { background: #2e2e2e; }

/* ===== PROFILE MODAL HEADER ===== */
.profile-modal-header {
  display: flex; align-items: center; gap: 16px;
  padding: 16px;
  background: var(--gray-100);
  border-radius: var(--border-radius);
  margin-bottom: 4px;
}

/* ===== SETTINGS MODAL ===== */
.settings-tabs {
  display: flex; gap: 4px; margin-bottom: 20px;
  border-bottom: 2px solid var(--gray-200);
  padding-bottom: 0;
}

.settings-tab {
  background: none; border: none;
  padding: 9px 14px; font-size: 0.82rem; font-weight: 600;
  color: var(--gray-500); cursor: pointer;
  border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
  transition: var(--transition);
  display: flex; align-items: center; gap: 6px;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.settings-tab:hover { color: var(--bg-dark); background: var(--gray-100); }
.settings-tab.active { color: var(--brand-red); border-bottom-color: var(--brand-red); }

.settings-tab-content { display: none; }
.settings-tab-content.active { display: block; }

.settings-section {
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--gray-500);
  margin-bottom: 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 6px;
}

.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--gray-200);
  gap: 16px;
}

.settings-row:last-child { border-bottom: none; }

.settings-row-info { flex: 1; min-width: 0; }
.settings-row-label { font-size: 0.87rem; font-weight: 600; color: var(--bg-dark); }
.settings-row-desc { font-size: 0.75rem; color: var(--gray-400); margin-top: 2px; }

.settings-select {
  background: var(--gray-100); border: 1.5px solid var(--gray-200);
  border-radius: var(--border-radius-sm); padding: 7px 10px;
  font-size: 0.83rem; color: var(--bg-dark); cursor: pointer;
  transition: var(--transition); min-width: 160px;
}
.settings-select:focus { border-color: var(--brand-red); outline: none; }

.settings-input-sm {
  background: var(--gray-100); border: 1.5px solid var(--gray-200);
  border-radius: var(--border-radius-sm); padding: 7px 10px;
  font-size: 0.85rem; color: var(--bg-dark); width: 80px;
  text-align: right; transition: var(--transition);
}
.settings-input-sm:focus { border-color: var(--brand-red); outline: none; }

/* Theme toggle buttons */
.theme-toggle-group { display: flex; gap: 4px; }
.theme-btn {
  padding: 7px 14px; border-radius: var(--border-radius-sm);
  font-size: 0.82rem; font-weight: 600;
  background: var(--gray-100); border: 1.5px solid var(--gray-200);
  color: var(--gray-500); cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; gap: 5px;
}
.theme-btn:hover { border-color: var(--brand-red); color: var(--bg-dark); }
.theme-btn.active { background: var(--brand-red); color: white; border-color: var(--brand-red); }

/* Toggle switch (on/off) */
.toggle-switch {
  position: relative; display: inline-block;
  width: 42px; height: 24px; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  inset: 0; background: var(--gray-300);
  border-radius: 12px; transition: .3s;
}
.toggle-slider:before {
  position: absolute; content: '';
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: white; border-radius: 50%;
  transition: .3s; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch input:checked + .toggle-slider { background: var(--brand-red); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* Currency preview block */
.currency-preview {
  background: var(--gray-100); border-radius: var(--border-radius);
  padding: 16px 20px; text-align: center; margin-top: 8px;
}

/* ===== EXPENSE CARDS ===== */
.expense-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  border: 1.5px solid var(--gray-200);
  display: flex; align-items: flex-start; gap: 16px;
  transition: var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  cursor: pointer;
  margin-bottom: 10px;
}

.expense-card:hover { border-color: var(--brand-red); box-shadow: var(--shadow); }

.expense-card-left { display: flex; gap: 14px; flex: 1; min-width: 0; align-items: flex-start; }

.expense-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-red);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; font-weight: 700; color: white; flex-shrink: 0;
}

.expense-info { flex: 1; min-width: 0; }
.expense-buyer { font-size: 0.92rem; font-weight: 700; color: var(--bg-dark); }
.expense-date { font-size: 0.75rem; color: var(--gray-400); margin-top: 2px; }

.expense-items-preview {
  display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px;
}

.expense-item-tag {
  background: var(--gray-100); color: var(--gray-600);
  font-size: 0.72rem; font-weight: 600; padding: 3px 8px;
  border-radius: 12px; white-space: nowrap;
}

.expense-card-right {
  text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end;
}

.expense-total {
  font-size: 1.1rem; font-weight: 800; color: var(--brand-red);
}

.expense-meta { font-size: 0.75rem; color: var(--gray-400); margin-top: 2px; }

/* ===== EXPENSE FORM ===== */
.expense-items-header {
  display: grid; grid-template-columns: 1fr 110px 80px 38px;
  gap: 8px; padding: 6px 0;
  font-size: 0.76rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--gray-500);
}

.expense-item-row {
  display: grid; grid-template-columns: 1fr 110px 80px 38px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}

.expense-item-row .form-control { padding: 8px 10px; }

/* ===== INVOICE PHOTO UPLOAD ===== */
.invoice-photo-wrap {
  border: 2px dashed var(--gray-300); border-radius: var(--border-radius);
  overflow: hidden; transition: var(--transition);
}

.invoice-photo-wrap:hover { border-color: var(--brand-red); }

.invoice-photo-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 28px 20px; cursor: pointer;
  color: var(--gray-400); font-size: 0.88rem;
  transition: var(--transition);
}

.invoice-photo-placeholder:hover { color: var(--brand-red); background: #FFF5F5; }
.invoice-photo-placeholder i { font-size: 2rem; }

/* ===== EXPENSE WIDGET ON DASHBOARD ===== */
.expense-widget {
  cursor: pointer; transition: var(--transition);
  border: 1.5px solid var(--gray-200);
}

.expense-widget:hover {
  border-color: var(--brand-red);
  box-shadow: 0 4px 16px rgba(107,0,0,0.15);
  transform: translateY(-2px);
}

/* ===== PRINT FILE UPLOAD ===== */
.print-file-upload-wrap {
  border: 2px dashed var(--gray-300);
  border-radius: var(--border-radius-sm);
  padding: 4px;
  transition: var(--transition);
}
.print-file-upload-wrap:hover { border-color: var(--brand-red); }

.print-file-upload-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; cursor: pointer;
  font-size: 0.85rem; font-weight: 600; color: var(--gray-500);
  border-radius: var(--border-radius-sm);
  transition: var(--transition); width: 100%;
}
.print-file-upload-btn:hover { color: var(--brand-red); background: #FFF5F5; }
.print-file-upload-btn i { font-size: 1rem; }

.print-file-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--gray-100);
  border-radius: var(--border-radius-sm);
}
.print-file-preview i { color: var(--brand-red); font-size: 1.1rem; flex-shrink: 0; }

/* ===== RESPONSIVE ===== */

/* ── Tablet (≤1100px) ── */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid .span-2 { grid-column: span 2; }
  .dashboard-grid .span-3 { grid-column: span 3; }
  .calc-container { grid-template-columns: 1fr; }
  .calc-summary { position: static; }
  .chat-layout { grid-template-columns: 200px 1fr; }
  .filament-select-row { grid-template-columns: 1fr 90px 90px 30px; }
}

/* ── Mobile large (≤768px) ── */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
    --topbar-height: 56px;
  }

  /* ── Layout ── */
  .app { position: relative; }

  .sidebar {
    position: fixed; left: -100%; top: 0; height: 100vh;
    z-index: 500; transition: left 0.28s cubic-bezier(.4,0,.2,1);
    box-shadow: none;
  }
  .sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }

  /* Overlay when sidebar is open on mobile */
  .sidebar-mobile-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 499;
  }
  .sidebar-mobile-overlay.active { display: block; }

  .sidebar-toggle-mobile { display: block; }
  .sidebar.collapsed { width: var(--sidebar-width); }

  /* ── Topbar ── */
  .topbar { padding: 0 14px; gap: 8px; }
  .page-title { font-size: 1rem; }
  .topbar-right { gap: 8px; }
  .topbar-user { display: none; }
  #btn-ship-orders span { display: none; }
  #btn-ship-orders { padding: 8px 10px; }

  /* ── Pages ── */
  .page { padding: 14px; }

  /* ── Dashboard ── */
  .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
  .dashboard-grid[style*="grid-template-columns: 2fr 1fr"] { grid-template-columns: 1fr !important; }
  .dashboard-grid[style*="grid-template-columns: 3fr 2fr"] { grid-template-columns: 1fr !important; }
  .dashboard-grid[style*="grid-template-columns: repeat(5,1fr)"] { grid-template-columns: 1fr 1fr !important; }
  .widget-card { padding: 14px; }
  .widget-value { font-size: 1.7rem; }
  .widget-icon { width: 36px; height: 36px; font-size: 1rem; }

  /* ── Forms ── */
  .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 0; }
  .form-actions { flex-wrap: wrap; gap: 8px; }
  .form-actions button { flex: 1; min-width: 120px; justify-content: center; }

  /* ── Modal ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    width: 100%; max-width: 100%; border-radius: 18px 18px 0 0;
    max-height: 92vh; padding: 22px 18px;
  }
  .modal-box.wide, .modal-box.narrow { max-width: 100%; }
  .modal-title { font-size: 1.05rem; }

  /* ── Tasks ── */
  .task-card { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .task-card-actions { width: 100%; justify-content: flex-end; }
  .task-type-grid { grid-template-columns: 1fr; }
  .filament-select-row { grid-template-columns: 1fr 80px 28px; gap: 6px; }
  .filament-select-row > div:nth-child(3) { display: none; } /* hide meters on mobile */

  /* ── Stock ── */
  .stock-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  /* ── Calculator ── */
  .calc-container { grid-template-columns: 1fr; gap: 14px; }
  .calc-summary { position: static; }
  .calc-piece-card { padding: 14px; }
  .calc-filament-row { flex-wrap: wrap; gap: 6px; }
  .calc-filament-row > div { min-width: 0; }

  /* ── Chat ── */
  .chat-layout { grid-template-columns: 1fr; height: calc(100vh - var(--topbar-height) - 28px); }
  .chat-sidebar { display: none; }

  /* ── Expenses ── */
  .expense-card { flex-direction: column; gap: 10px; }
  .expense-card-right { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; }
  .expense-item-row { grid-template-columns: 1fr 90px 60px 32px; gap: 6px; }
  .expense-items-header { grid-template-columns: 1fr 90px 60px 32px; }

  /* ── Stats modal ── */
  .stats-modal-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* ── Users grid ── */
  .users-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .user-manage-card { padding: 14px; }

  /* ── Profile modal ── */
  .profile-modal-header { flex-direction: column; text-align: center; gap: 10px; }

  /* ── Settings ── */
  .settings-tabs { flex-wrap: wrap; gap: 2px; }
  .settings-tab { font-size: 0.75rem; padding: 7px 10px; }
  .settings-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .settings-row-info { width: 100%; }
  .theme-toggle-group { width: 100%; }
  .theme-btn { flex: 1; justify-content: center; }

  /* ── Sidebar user menu ── */
  .user-menu-popup { bottom: 66px; }

  /* ── Toast ── */
  .toast-container { bottom: 14px; right: 14px; left: 14px; }
  .toast { font-size: 0.83rem; padding: 10px 14px; }
}

/* ── Small mobile (≤480px) ── */
@media (max-width: 480px) {
  .btn-label-hide-sm { display: none; }
  .page { padding: 10px; }

  .dashboard-grid { grid-template-columns: 1fr !important; }
  .widget-card { padding: 12px; }
  .widget-value { font-size: 1.5rem; }

  .stock-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .users-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  .task-card { padding: 10px 12px; }

  .expense-item-row { grid-template-columns: 1fr 80px 50px 28px; font-size: 0.8rem; }
  .expense-items-header { grid-template-columns: 1fr 80px 50px 28px; font-size: 0.72rem; }

  .filament-select-row { grid-template-columns: 1fr 70px 24px; }

  .pin-keypad { max-width: 220px; }
  .pin-key { height: 50px; font-size: 1.2rem; }

  .modal-box { padding: 18px 14px; max-height: 95vh; }
  .modal-title { font-size: 1rem; }

  .calc-filament-row { display: grid; grid-template-columns: 1fr 70px; gap: 6px; }
  .calc-filament-row > div:nth-child(3) { display: none; }

  .profile-modal-header .profile-avatar-big { width: 64px; height: 64px; font-size: 1.6rem; }

  .topbar-right .btn-quick-task span { display: none; }
  .btn-quick-task { padding: 8px 10px; }
  .btn-quick-task i { margin: 0; }
}

/* ── Very small (≤360px) ── */
@media (max-width: 360px) {
  .page { padding: 8px; }
  .topbar { padding: 0 10px; }
  .page-title { font-size: 0.9rem; }
  .dashboard-grid { gap: 8px; }
  .stock-grid { grid-template-columns: 1fr; }
  .users-grid { grid-template-columns: 1fr; }
  .expense-item-row { grid-template-columns: 1fr 70px 28px; }
  .expense-items-header { grid-template-columns: 1fr 70px 28px; }
  .expense-item-row > *:nth-child(3) { display: none; }
  .expense-items-header > *:nth-child(3) { display: none; }
}

