/* SAS Plantation CRM - Main Stylesheet */
:root {
    --primary: #2d7a3a;
    --primary-dark: #1e5527;
    --primary-light: #4a9e5a;
    --secondary: #8B6914;
    --accent: #c8a84b;
    --danger: #dc3545;
    --warning: #ffc107;
    --success: #28a745;
    --info: #17a2b8;
    --dark: #343a40;
    --light: #f8f9fa;
    --white: #ffffff;
    --border: #dee2e6;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 8px;
    --sidebar-width: 240px;
    --header-height: 60px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); background: #f0f2f5; color: var(--dark); min-height: 100vh; }

/* ---------- LAYOUT ---------- */
.wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
    position: fixed; top: 0; left: 0; height: 100vh;
    overflow-y: auto; z-index: 1000;
    display: flex; flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-logo {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    text-align: center;
}

.sidebar-logo img { max-width: 120px; max-height: 60px; object-fit: contain; }

.sidebar-user {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    display: flex; align-items: center; gap: 10px;
}

.sidebar-user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 15px;
}

.sidebar-user-info .name { font-weight: 600; color: #fff; font-size: 13px; }
.sidebar-user-info .role { color: rgba(255,255,255,0.65); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

.nav-section { padding: 8px 0; }
.nav-section-title {
    padding: 6px 20px 4px;
    font-size: 10px; font-weight: 700; letter-spacing: 1px;
    color: rgba(255,255,255,0.45); text-transform: uppercase;
}

.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; color: rgba(255,255,255,0.82);
    text-decoration: none; font-size: 13.5px;
    transition: all 0.2s; border-left: 3px solid transparent;
}

.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,0.12);
    color: #fff; border-left-color: var(--accent);
}

.nav-link svg { width: 16px; height: 16px; opacity: 0.85; flex-shrink: 0; }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1; display: flex; flex-direction: column;
    min-height: 100vh;
}

/* ---------- HEADER ---------- */
.topbar {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 900;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 16px; font-weight: 600; color: var(--primary-dark); }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.notif-btn {
    position: relative; background: none; border: none;
    cursor: pointer; padding: 6px; color: #555;
}

.notif-badge {
    position: absolute; top: 0; right: 0;
    background: var(--danger); color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

.topbar-time { font-size: 12px; color: #888; }

.logout-btn {
    background: var(--danger); color: #fff;
    border: none; padding: 7px 16px; border-radius: 6px;
    cursor: pointer; font-size: 13px; font-weight: 500;
    display: flex; align-items: center; gap: 6px;
    text-decoration: none;
}

.logout-btn:hover { background: #b02a37; color: #fff; }

/* ---------- PAGE CONTENT ---------- */
.page-body { padding: 24px; flex: 1; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 22px;
}

.page-title { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.page-subtitle { font-size: 13px; color: #888; margin-top: 2px; }

/* ---------- CARDS ---------- */
.card {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}

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

.card-title { font-size: 15px; font-weight: 600; color: var(--primary-dark); }
.card-body { padding: 20px; }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }

.stat-card {
    background: var(--white); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
    display: flex; align-items: center; gap: 16px;
}

.stat-card.green  { border-left-color: var(--success); }
.stat-card.blue   { border-left-color: var(--info); }
.stat-card.orange { border-left-color: #fd7e14; }
.stat-card.red    { border-left-color: var(--danger); }
.stat-card.gold   { border-left-color: var(--accent); }

.stat-icon {
    width: 48px; height: 48px; border-radius: 12px;
    background: rgba(45,122,58,0.12);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.stat-card.green .stat-icon  { background: rgba(40,167,69,0.12); }
.stat-card.blue .stat-icon   { background: rgba(23,162,184,0.12); }
.stat-card.orange .stat-icon { background: rgba(253,126,20,0.12); }
.stat-card.red .stat-icon    { background: rgba(220,53,69,0.12); }
.stat-card.gold .stat-icon   { background: rgba(200,168,75,0.12); }

.stat-icon svg { width: 24px; height: 24px; color: var(--primary); }
.stat-card.green .stat-icon svg  { color: var(--success); }
.stat-card.blue .stat-icon svg   { color: var(--info); }
.stat-card.orange .stat-icon svg { color: #fd7e14; }
.stat-card.red .stat-icon svg    { color: var(--danger); }
.stat-card.gold .stat-icon svg   { color: var(--accent); }

.stat-value { font-size: 22px; font-weight: 700; color: var(--dark); line-height: 1; }
.stat-label { font-size: 12px; color: #888; margin-top: 4px; }

/* ---------- TABLES ---------- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    background: var(--primary-dark); color: #fff;
    padding: 11px 14px; text-align: left; font-weight: 600;
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
    white-space: nowrap;
}
tbody tr { border-bottom: 1px solid #f0f0f0; }
tbody tr:hover { background: #f9fafb; }
tbody td { padding: 10px 14px; vertical-align: middle; }
tbody tr:last-child { border-bottom: none; }

/* ---------- FORMS ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 600; font-size: 13px; color: var(--dark); margin-bottom: 6px; }
.form-label.required::after { content: ' *'; color: var(--danger); }

.form-control {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 13.5px; font-family: var(--font);
    color: var(--dark); background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45,122,58,0.12);
}

.form-control.is-invalid { border-color: var(--danger); }
.form-text { font-size: 12px; color: #888; margin-top: 4px; }

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

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ---------- BUTTONS ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 18px; border-radius: 6px; font-size: 13.5px;
    font-weight: 500; border: none; cursor: pointer;
    text-decoration: none; transition: all 0.2s;
    font-family: var(--font); white-space: nowrap;
}

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #5a6268; color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #1e7e34; color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b02a37; color: #fff; }
.btn-warning   { background: var(--warning); color: #212529; }
.btn-warning:hover { background: #e0a800; }
.btn-info      { background: var(--info); color: #fff; }
.btn-info:hover { background: #117a8b; color: #fff; }
.btn-outline-primary { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

.btn svg { width: 15px; height: 15px; }
.btn-sm svg { width: 13px; height: 13px; }

/* ---------- BADGES ---------- */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 9px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
}

.badge-success  { background: rgba(40,167,69,0.12); color: #1a7a2e; }
.badge-danger   { background: rgba(220,53,69,0.12); color: #9b1c2a; }
.badge-warning  { background: rgba(255,193,7,0.15); color: #856404; }
.badge-info     { background: rgba(23,162,184,0.12); color: #0c6675; }
.badge-secondary { background: rgba(108,117,125,0.12); color: #495057; }
.badge-primary  { background: rgba(45,122,58,0.12); color: var(--primary-dark); }

/* ---------- ALERTS ---------- */
.alert {
    padding: 12px 16px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 13.5px;
    display: flex; align-items: flex-start; gap: 10px;
}

.alert-success { background: rgba(40,167,69,0.1); border: 1px solid rgba(40,167,69,0.3); color: #155724; }
.alert-danger  { background: rgba(220,53,69,0.1); border: 1px solid rgba(220,53,69,0.3); color: #721c24; }
.alert-warning { background: rgba(255,193,7,0.1); border: 1px solid rgba(255,193,7,0.4); color: #856404; }
.alert-info    { background: rgba(23,162,184,0.1); border: 1px solid rgba(23,162,184,0.3); color: #0c5460; }

/* ---------- MODAL ---------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px; opacity: 0; pointer-events: none; transition: opacity 0.25s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--white); border-radius: 10px;
    max-width: 700px; width: 100%;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    transform: translateY(-20px); transition: transform 0.25s;
}

.modal-overlay.open .modal { transform: translateY(0); }
.modal-sm .modal { max-width: 420px; }
.modal-lg .modal { max-width: 900px; }

.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--primary-dark); color: #fff; border-radius: 10px 10px 0 0;
}

.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: rgba(255,255,255,0.7); cursor: pointer; font-size: 20px; padding: 0; line-height: 1; }
.modal-close:hover { color: #fff; }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- TABS ---------- */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 0; overflow-x: auto; }
.tab-btn {
    padding: 10px 20px; background: none; border: none;
    cursor: pointer; font-size: 13.5px; font-weight: 500;
    color: #666; border-bottom: 2px solid transparent; margin-bottom: -2px;
    white-space: nowrap; transition: all 0.2s;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- SEARCH BAR ---------- */
.search-bar {
    display: flex; gap: 10px; align-items: center;
    flex-wrap: wrap; margin-bottom: 16px;
}

.search-input-wrap { position: relative; flex: 1; min-width: 220px; }
.search-input-wrap .form-control { padding-left: 36px; }
.search-input-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: #aaa; }

/* ---------- PAGINATION ---------- */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: center; padding: 16px 0; }
.page-btn {
    min-width: 34px; height: 34px; border-radius: 6px;
    border: 1px solid var(--border); background: var(--white);
    cursor: pointer; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    color: var(--dark); transition: all 0.2s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- FOOTER ---------- */
footer {
    background: var(--white);
    border-top: 1px solid var(--border);
    padding: 14px 24px;
    text-align: center;
    font-size: 12px; color: #888;
}

footer strong { color: var(--primary-dark); }

/* ---------- POS / MOBILE ---------- */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 0; height: calc(100vh - var(--header-height)); overflow: hidden; }
.pos-products { overflow-y: auto; padding: 16px; }
.pos-cart { border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.pos-cart-header { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px; background: var(--primary-dark); color: #fff; }
.pos-cart-items { flex: 1; overflow-y: auto; padding: 12px; }
.pos-cart-footer { border-top: 1px solid var(--border); padding: 14px 16px; }

.pos-product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }

.pos-product-card {
    background: var(--white); border-radius: var(--radius);
    border: 2px solid transparent; cursor: pointer;
    padding: 14px; text-align: center;
    transition: all 0.2s; box-shadow: var(--shadow);
}
.pos-product-card:hover { border-color: var(--primary); transform: translateY(-2px); }

.pos-product-name { font-weight: 600; font-size: 13px; margin: 6px 0 4px; line-height: 1.3; }
.pos-product-price { color: var(--primary-dark); font-weight: 700; font-size: 14px; }
.pos-product-stock { font-size: 11px; color: #888; margin-top: 2px; }

.cart-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f0f0f0; }
.cart-item-name { flex: 1; font-size: 13px; font-weight: 500; }
.cart-item-qty input { width: 52px; text-align: center; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.cart-item-price { font-weight: 600; font-size: 13px; color: var(--primary-dark); min-width: 80px; text-align: right; }
.cart-item-remove { background: none; border: none; color: var(--danger); cursor: pointer; padding: 2px; }

.cart-totals { font-size: 13.5px; }
.cart-totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.cart-totals .row.total { font-size: 16px; font-weight: 700; color: var(--primary-dark); border-top: 2px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* ---------- CHARTS ---------- */
.chart-container { position: relative; }

/* ---------- SIDEBAR TOGGLE (MOBILE) ---------- */
.sidebar-toggle {
    display: none; background: none; border: none;
    cursor: pointer; padding: 6px; color: var(--primary-dark);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .pos-layout { grid-template-columns: 1fr; height: auto; }
    .pos-cart { border-left: none; border-top: 1px solid var(--border); }
    .form-row { grid-template-columns: 1fr; }
    .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 576px) {
    .page-body { padding: 14px; }
    .stats-grid { grid-template-columns: 1fr; }
    .topbar { padding: 0 14px; }
    .topbar-time { display: none; }
    table { font-size: 12px; }
    thead th { padding: 8px 10px; }
    tbody td { padding: 8px 10px; }
}

/* ---------- PRINT INVOICE ---------- */
@media print {
    body * { visibility: hidden; }
    #invoice-print, #invoice-print * { visibility: visible; }
    #invoice-print { position: absolute; left: 0; top: 0; width: 210mm; }
    .sidebar, .topbar, .no-print { display: none !important; }
}

/* ---------- UTILITIES ---------- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #888; }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.w-100 { width: 100%; }
.hidden { display: none; }
.scroll-x { overflow-x: auto; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 999;
}
.sidebar-overlay.open { display: block; }
