/* ============================================
   CargoMind - Premium Dark Green Theme
   Designed for high accessibility (elderly-friendly)
   ============================================ */

/* --- CSS Variables --- */
:root {
    --primary: #1a5c38;
    --primary-dark: #0f3d24;
    --primary-light: #2d8a56;
    --primary-glow: rgba(45, 138, 86, 0.3);
    --accent: #34d399;
    --accent-dark: #059669;
    --bg-body: #f0f5f1;
    --bg-card: #ffffff;
    --bg-sidebar: #0f3d24;
    --bg-sidebar-hover: #1a5c38;
    --text-primary: #1a2e23;
    --text-secondary: #4a6e5a;
    --text-muted: #8ba89a;
    --text-white: #f0fdf4;
    --border: #d1e7d9;
    --border-light: #e8f5ec;
    --shadow-sm: 0 1px 3px rgba(15, 61, 36, 0.08);
    --shadow-md: 0 4px 14px rgba(15, 61, 36, 0.1);
    --shadow-lg: 0 10px 30px rgba(15, 61, 36, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --sidebar-width: 260px;
    --topbar-height: 70px;
    --font-base: 15px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Large Font Mode --- */
body.large-font {
    --font-base: 19px;
}
body.large-font .sidebar-nav .nav-link span { font-size: 1.1rem; }
body.large-font .page-title { font-size: 1.8rem; }
body.large-font .stat-value { font-size: 2.4rem; }
body.large-font .table th, body.large-font .table td { font-size: 1.05rem; padding: 14px 16px; }
body.large-font .btn { font-size: 1.05rem; padding: 12px 24px; }

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: var(--font-base); scroll-behavior: smooth; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-light); }

/* --- Sidebar --- */
.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-sidebar) 0%, #0a2e1a 100%);
    display: flex; flex-direction: column;
    z-index: 100;
    transition: var(--transition);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
}
.sidebar-brand {
    padding: 24px 20px;
    display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand i { font-size: 2rem; color: var(--accent); }
.sidebar-brand span {
    font-size: 1.5rem; font-weight: 800; color: var(--text-white);
    letter-spacing: -0.5px;
}
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.65); font-weight: 500;
    transition: var(--transition); margin-bottom: 4px;
}
.nav-link:hover { background: var(--bg-sidebar-hover); color: var(--text-white); transform: translateX(4px); }
.nav-link.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--text-white); box-shadow: 0 4px 12px var(--primary-glow);
}
.nav-link i { font-size: 1.25rem; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 16px; border-top: 1px solid rgba(255,255,255,0.08);
    display: flex; align-items: center; justify-content: space-between;
}
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--primary-light); display: flex;
    align-items: center; justify-content: center;
    color: white; font-size: 1.1rem;
}
.user-name { display: block; color: var(--text-white); font-weight: 600; font-size: 0.85rem; }
.user-role { display: block; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.btn-logout {
    background: rgba(255,255,255,0.08); border: none; color: rgba(255,255,255,0.5);
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--transition); font-size: 1.1rem;
}
.btn-logout:hover { background: #dc2626; color: white; }

/* Sidebar collapse */
body.sidebar-collapsed .sidebar { width: 72px; }
body.sidebar-collapsed .sidebar-brand span,
body.sidebar-collapsed .nav-link span,
body.sidebar-collapsed .user-details { display: none; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 24px 0; }
body.sidebar-collapsed .nav-link { justify-content: center; padding: 12px; }
body.sidebar-collapsed .sidebar-footer { justify-content: center; }
body.sidebar-collapsed .user-info { gap: 0; }
body.sidebar-collapsed .main-content { margin-left: 72px; }

/* --- Main Content --- */
.main-content {
    flex: 1; margin-left: var(--sidebar-width);
    min-height: 100vh; transition: var(--transition);
}

/* --- Topbar --- */
.topbar {
    height: var(--topbar-height); padding: 0 28px;
    display: flex; align-items: center; gap: 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    position: sticky; top: 0; z-index: 50;
}
.btn-toggle-sidebar {
    background: none; border: none; font-size: 1.4rem;
    color: var(--text-secondary); cursor: pointer;
    padding: 6px; border-radius: var(--radius-sm);
    transition: var(--transition);
}
.btn-toggle-sidebar:hover { color: var(--primary); background: var(--border-light); }
.page-title { font-size: 1.35rem; font-weight: 700; color: var(--text-primary); flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
.btn-icon {
    background: var(--border-light); border: none; width: 40px; height: 40px;
    border-radius: var(--radius-sm); display: flex; align-items: center;
    justify-content: center; cursor: pointer; color: var(--text-secondary);
    font-size: 1.15rem; transition: var(--transition);
}
.btn-icon:hover { background: var(--primary); color: white; }

/* --- Content Wrapper --- */
.content-wrapper { padding: 28px; }

/* --- Alerts --- */
.alert {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px; margin: 16px 28px 0;
    border-radius: var(--radius-md); font-weight: 500;
    animation: slideDown 0.3s ease; transition: var(--transition);
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert i { font-size: 1.3rem; }
.alert-close {
    margin-left: auto; background: none; border: none;
    cursor: pointer; color: inherit; opacity: 0.6;
    font-size: 1.2rem; padding: 2px;
}
.alert-close:hover { opacity: 1; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Cards --- */
.card {
    background: var(--bg-card); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border-light);
    overflow: hidden; transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.card-body { padding: 24px; }

/* --- Stat Cards --- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 28px; }
.stat-card {
    background: var(--bg-card); border-radius: var(--radius-lg);
    padding: 24px; box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    display: flex; align-items: flex-start; gap: 16px;
    transition: var(--transition);
    cursor: pointer;
    color: inherit;
    text-decoration: none;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary-light); }
.stat-card:active { transform: translateY(-1px); }
.stat-icon {
    width: 52px; height: 52px; border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.orange { background: #ffedd5; color: #ea580c; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; margin-bottom: 4px; }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--text-primary); line-height: 1.2; }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 0.9rem; border: none;
    cursor: pointer; transition: var(--transition);
    text-decoration: none; font-family: inherit;
}
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%); color: white; }
.btn-primary:hover { box-shadow: 0 4px 16px var(--primary-glow); transform: translateY(-1px); color: white; }
.btn-secondary { background: var(--border-light); color: var(--text-primary); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; box-shadow: 0 4px 12px rgba(220,38,38,0.3); }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-block { width: 100%; justify-content: center; }

/* --- Forms --- */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; font-size: 0.9rem; }
.form-control {
    width: 100%; padding: 11px 16px;
    border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: 0.95rem; font-family: inherit;
    transition: var(--transition); background: var(--bg-card);
    color: var(--text-primary);
}
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px var(--primary-glow); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%234a6e5a' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* --- Tables --- */
.table-wrapper { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    padding: 12px 16px; text-align: left;
    background: var(--bg-body); color: var(--text-secondary);
    font-weight: 600; font-size: 0.8rem;
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); color: var(--text-primary); }
.table tbody tr { transition: var(--transition); }
.table tbody tr:hover { background: #f0fdf4; }
.table .text-right { text-align: right; }
.table .text-center { text-align: center; }

/* --- Badge --- */
.badge {
    display: inline-flex; padding: 3px 10px;
    border-radius: 20px; font-size: 0.75rem;
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }

/* --- Pagination --- */
.pagination { display: flex; gap: 4px; justify-content: center; padding: 20px 0; }
.pagination a, .pagination span {
    padding: 8px 14px; border-radius: var(--radius-sm);
    font-weight: 500; font-size: 0.85rem; border: 1px solid var(--border);
    transition: var(--transition);
}
.pagination a { color: var(--text-secondary); background: var(--bg-card); }
.pagination a:hover { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .active span { background: var(--primary); color: white; border-color: var(--primary); }

/* --- Search Bar --- */
.search-bar {
    display: flex; gap: 12px; margin-bottom: 20px;
    align-items: center; flex-wrap: wrap;
}
.search-bar .form-control { max-width: 360px; }

/* --- Modal --- */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    z-index: 200; align-items: center; justify-content: center;
    animation: fadeIn 0.2s ease;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg); width: 90%; max-width: 520px;
    max-height: 90vh; overflow-y: auto;
    animation: scaleIn 0.25s ease;
}
.modal-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1.15rem; font-weight: 700; }
.modal-close {
    background: none; border: none; font-size: 1.4rem;
    cursor: pointer; color: var(--text-muted); padding: 4px;
    transition: var(--transition);
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-light); display: flex; gap: 12px; justify-content: flex-end; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* --- Grid Layouts --- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }

/* --- POS Layout --- */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 24px; min-height: calc(100vh - var(--topbar-height) - 56px); }
.pos-items { }
.pos-cart {
    background: var(--bg-card); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); display: flex; flex-direction: column;
    border: 1px solid var(--border-light); position: sticky; top: calc(var(--topbar-height) + 28px);
    max-height: calc(100vh - var(--topbar-height) - 56px);
}
.pos-cart-header { padding: 20px; border-bottom: 1px solid var(--border-light); }
.pos-cart-header h3 { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.pos-cart-body { flex: 1; overflow-y: auto; padding: 16px; }
.pos-cart-footer { padding: 20px; border-top: 2px solid var(--border); background: #f8fdf9; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.cart-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-light); margin-bottom: 8px;
    transition: var(--transition);
}
.cart-item:hover { border-color: var(--primary-light); }
.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; font-size: 0.9rem; }
.cart-item-rack { font-size: 0.75rem; color: var(--text-muted); }
.cart-item-price { font-size: 0.85rem; color: var(--text-secondary); }
.cart-item-qty {
    display: flex; align-items: center; gap: 6px;
}
.cart-item-qty button {
    width: 28px; height: 28px; border-radius: 50%;
    border: 1px solid var(--border); background: var(--bg-card);
    cursor: pointer; display: flex; align-items: center;
    justify-content: center; font-size: 1rem;
    transition: var(--transition); color: var(--text-primary);
}
.cart-item-qty button:hover { background: var(--primary); color: white; border-color: var(--primary); }
.cart-item-qty span { font-weight: 700; min-width: 24px; text-align: center; }
.cart-item-remove {
    background: none; border: none; color: #dc2626;
    cursor: pointer; font-size: 1.1rem; padding: 4px;
    opacity: 0.6; transition: var(--transition);
}
.cart-item-remove:hover { opacity: 1; }
.cart-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.cart-empty i { font-size: 3rem; margin-bottom: 12px; display: block; }

.cart-total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.95rem; }
.cart-total-row.grand-total { font-size: 1.3rem; font-weight: 800; color: var(--primary-dark); border-top: 2px solid var(--border); padding-top: 12px; margin-top: 8px; }

/* Item grid for POS */
.items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.item-card {
    background: var(--bg-card); border: 2px solid var(--border-light);
    border-radius: var(--radius-md); padding: 16px;
    cursor: pointer; transition: var(--transition); text-align: center;
}
.item-card:hover { border-color: var(--primary-light); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.item-card-name { font-weight: 700; font-size: 0.9rem; margin-bottom: 4px; }
.item-card-rack { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 8px; }
.item-card-price { font-weight: 800; color: var(--primary); font-size: 1rem; }
.item-card-stock { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; }

/* --- Empty State --- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { font-size: 4rem; margin-bottom: 16px; display: block; opacity: 0.4; }
.empty-state p { font-size: 1rem; }

/* --- Login Page --- */
.login-page {
    min-height: 100vh; display: flex; align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
}
.login-card {
    background: var(--bg-card); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg); width: 90%; max-width: 420px;
    padding: 48px 36px; text-align: center;
}
.login-logo { font-size: 3rem; color: var(--primary); margin-bottom: 8px; }
.login-title { font-size: 1.8rem; font-weight: 800; color: var(--text-primary); margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 32px; }

/* --- Sidebar Overlay --- */
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 90; display: none; backdrop-filter: blur(2px);
    transition: var(--transition);
}
body.sidebar-open .sidebar-overlay { display: block; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .pos-layout { grid-template-columns: 1fr; gap: 16px; }
    .pos-cart { position: relative; top: 0; max-height: none; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 16px; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 280px; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .content-wrapper { padding: 16px; }
    .topbar { padding: 0 16px; justify-content: space-between; }
    .page-title { font-size: 1.1rem; }
    
    .stats-grid { grid-template-columns: 1fr; gap: 12px; }
    .stat-card { padding: 16px; }
    .stat-value { font-size: 1.5rem; }
    
    .form-row { grid-template-columns: 1fr; gap: 12px; }
    .items-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
    .item-card { padding: 12px; }
    
    .pos-cart { position: sticky; bottom: 0; z-index: 40; border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,0.1); }
    .pos-cart-header { padding: 12px 16px; cursor: pointer; }
    .pos-cart-body { max-height: 200px; display: none; }
    .pos-cart.expanded .pos-cart-body { display: block; }
    
    .table-wrapper { margin: 0 -16px; width: calc(100% + 32px); }
    .table th, .table td { padding: 10px 12px; font-size: 0.85rem; }
}

@media (max-width: 480px) {
    .topbar-actions .btn-icon:not(#btn-toggle-font) { display: none; }
    .login-card { padding: 32px 20px; }
}

/* --- Utility --- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-column { display: flex; flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }
.hidden { display: none; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.p-0 { padding: 0 !important; }
.w-full { width: 100%; }
