:root {
    --dark-charcoal: #1a1a1a;
    --white: #fff;
    --light-gray: #f0f0f0;
    --medium-gray: #666;
    --border-color: #333;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: Arial, sans-serif;
    margin: 0;
    background: var(--white);
    color: var(--dark-charcoal);
    min-height: 100vh;
}

/* --- Login --- */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; background-color: var(--light-gray); }
.login-box { background: var(--white); padding: 40px; border-radius: 5px; box-shadow: 0 4px 6px rgba(0,0,0,.1); width: 100%; max-width: 360px; border: 1px solid #ddd; margin: 15px; }
.login-box h2 { text-align: center; margin-bottom: 10px; font-weight: bold; color: var(--dark-charcoal); }
.login-box .subtitle { text-align: center; margin-bottom: 25px; color: #666; font-size: 14px; }
.login-box .form-group { margin-bottom: 15px; }
.login-box .form-group label { display: block; font-weight: bold; margin-bottom: 5px; font-size: 14px; }
.login-box .form-group input { padding: 12px; }
.login-box .btn { width: 100%; padding: 12px; font-size: 16px; }
.error-msg { color: #c0392b; background: #f8d7da; border: 1px solid #f5c6cb; padding: 10px; border-radius: 4px; font-size: 14px; margin-bottom: 15px; text-align: center; }

/* --- Layout --- */
.sidebar { width: 220px; background: var(--dark-charcoal); color: var(--white); padding: 15px; position: fixed; height: 100%; top: 0; left: 0; z-index: 1000; transform: translateX(0); transition: transform .3s ease-in-out; }
.sidebar .logo { font-size: 18px; font-weight: bold; margin-bottom: 20px; text-align: center; padding: 10px 0; border-bottom: 1px solid var(--border-color); }
.sidebar .nav-links { display: flex; flex-direction: column; gap: 5px; }
.sidebar .nav-links a { color: var(--white); text-decoration: none; padding: 12px 15px; border-radius: 4px; font-size: 14px; transition: background-color .2s; }
.sidebar .nav-links a:hover { background-color: #333; }
.sidebar .nav-links a.active { background-color: #444; font-weight: bold; }
.main-content { margin-left: 220px; padding: 20px; transition: margin-left .3s ease-in-out; }

/* --- Header --- */
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding: 15px; background: var(--white); border: 1px solid #ddd; border-radius: 5px; }
.header h1 { font-size: 22px; font-weight: bold; }
.header-buttons { display: flex; gap: 10px; }
.mobile-header { display: none; }
.menu-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.5); z-index: 999; }
body.sidebar-open .menu-overlay { display: block; }

/* --- Components --- */
.btn { background: var(--dark-charcoal); color: var(--white); padding: 9px 16px; border: none; cursor: pointer; font-size: 14px; text-decoration: none; display: inline-block; border-radius: 4px; transition: background-color .2s; }
.btn:hover { background: #333; }
.btn-secondary { background: var(--white); color: var(--dark-charcoal); border: 1px solid var(--dark-charcoal); }
.btn-secondary:hover { background: var(--dark-charcoal); color: var(--white); }
#add-item-btn { background-color: #27ae60; color: var(--white); border: none; }
#add-item-btn:hover { background-color: #229954; }

/* --- Cards & Forms --- */
.card { background: var(--white); border: 1px solid #ddd; margin-bottom: 20px; border-radius: 5px; overflow: hidden; }
.card-header { padding: 15px; border-bottom: 1px solid #ddd; background: var(--light-gray); }
.card-header h3 { font-size: 17px; font-weight: bold; }
.card-body { padding: 15px; }
.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-weight: bold; margin-bottom: 5px; font-size: 14px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px; border: 1px solid #ccc; background: var(--white); border-radius: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 15px; }
.form-grid-3-col { display: grid; grid-template-columns: repeat(3,1fr); gap: 15px; }
.invoice-item-row { display: grid; grid-template-columns: 3fr 1fr 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.invoice-item-row input { width: 100%; padding: 10px; border: 1px solid #ccc; background: var(--white); border-radius: 4px; }
.payment-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.payment-form input { flex: 1; min-width: 120px; padding: 9px 10px; border: 1px solid #ccc; background: var(--white); border-radius: 4px; }

/* --- Notifications --- */
.notification { padding: 15px; margin-bottom: 20px; border-radius: 5px; color: #fff; position: fixed; top: 20px; right: 20px; z-index: 1050; box-shadow: 0 0 10px rgba(0,0,0,.1); opacity: 0; visibility: hidden; transform: translateX(100%); transition: opacity .3s,transform .3s,visibility .3s; }
.notification.success { background-color: #27ae60; }
.notification.error { background-color: #c0392b; }
.notification.show { opacity: 1; visibility: visible; transform: translateX(0); }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border: 1px solid #ddd; text-align: left; vertical-align: middle; }
thead th { background: var(--light-gray); font-weight: bold; text-align: left; }
tbody tr:hover { background: #f9f9f0; }
.desktop-center { text-align: center; }

/* --- Badges & Dashboard --- */
.status-badge { padding: 5px 10px; font-size: 12px; font-weight: bold; border-radius: 15px; text-transform: uppercase; }
.status-paid { background: #d4edda; color: #155724; }
.status-partially_paid { background: #fff3cd; color: #856404; }
.status-unpaid { background: #f8d7da; color: #721c24; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(250px,1fr)); gap: 20px; margin-bottom: 20px; }
.stat-card { background: var(--white); padding: 20px; border: 1px solid #ccc; text-align: center; border-radius: 5px; box-shadow: 0 4px 10px rgba(0,0,0,.05); transition: transform .2s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 15px rgba(0,0,0,.1); }
.stat-card .value { font-size: 28px; font-weight: 900; margin: 5px 0; color: var(--dark-charcoal); }
.stat-card .label { font-size: 13px; color: var(--medium-gray); text-transform: uppercase; letter-spacing: .5px; }

/* --- Inline Table Logic --- */
.sr-no { width: 40px !important; color: #666; font-size: 14px; padding-left: 15px !important; padding-right: 5px; border-top: 1px solid #eee; text-align: left; white-space: nowrap; }
.table-inline tr:first-child .sr-no { border-top: none; }
.vendor-name { width: auto !important; border-top: 1px solid #eee; text-align: left; padding-left: 0 !important; }
.table-inline tr:first-child .vendor-name { border-top: none; }
.vendor-name a { font-weight: bold; text-decoration: none; color: #1a1a1a; font-size: 16px; }
td.vendor-outstanding { width: 150px !important; font-size: 1.1em; font-weight: 700; text-align: right !important; padding-right: 15px !important; border-top: 1px solid #eee; white-space: nowrap; }
.table-inline tr:first-child td.vendor-outstanding { border-top: none; }
.outstanding-due { color: #c0392b; }
.outstanding-paid { color: #27ae60; }

/* --- Invoice Print --- */
.invoice-container { max-width: 800px; margin: auto; background: #fff; border: 1px solid #000; }
.invoice-header { display: flex; justify-content: space-between; padding: 20px; border-bottom: 2px solid #000; }
.invoice-header .company-info h1 { font-size: 24px; font-weight: bold; margin: 0; }
.invoice-header .invoice-info h2 { font-size: 28px; font-weight: bold; margin: 0; }
.invoice-body { padding: 20px; }
.details-section { display: flex; justify-content: space-between; margin-bottom: 20px; align-items: flex-start; }
.items-table { width: 100%; border-collapse: collapse; margin: 20px 0; }
.items-table th,.items-table td { padding: 10px; border: 1px solid #000; text-align: left; }
.items-table th { background: #f0f0f0; font-weight: bold; }
.totals-section { text-align: right; margin-top: 20px; }
.print-button { background: #000; color: #fff; padding: 10px 20px; border: none; cursor: pointer; }
@media print { body { padding: 0; } .print-button { display: none; } }

/* --- Mobile Responsiveness --- */
@media(min-width:769px) {
    th.desktop-right { text-align: right; }
    .desktop-center { text-align: center; vertical-align: middle; }
    td.desktop-center > a, td.desktop-center > form { display: inline-block; vertical-align: middle; margin: 0 3px; }
    td.desktop-center > form.payment-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; margin: 0; }
}
@media(max-width:768px) {
    .sidebar { transform: translateX(-100%); backdrop-filter: blur(8px); background: rgba(26,26,26,.8); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .mobile-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; background: var(--dark-charcoal); color: var(--white); position: sticky; top: 0; z-index: 500; margin-bottom: 1rem; }
    .hamburger-btn { background: none; border: none; color: white; font-size: 24px; cursor: pointer; }
    .header { display: none; }
    .header-buttons { display: none; }
    .dashboard-grid, .form-grid, .form-grid-3-col { grid-template-columns: 1fr; }
    .stat-card { text-align: start; }
    .invoice-item-row { grid-template-columns: 1fr 1fr auto; grid-template-rows: auto auto; gap: 8px; }
    .invoice-item-row input[name="item_name[]"] { grid-column: 1/-1; }
    .payment-form { flex-direction: column; align-items: stretch; }
    .payment-form input { margin-bottom: 5px; }
    .main-content table, .main-content thead, .main-content tbody, .main-content th, .main-content td, .main-content tr { display: block; }
    .main-content thead tr { position: absolute; top: -9999px; left: -9999px; }
    .main-content tr { border: 1px solid #ddd; margin-bottom: 10px; border-radius: 5px; overflow: hidden; }
    .main-content td { border: none; border-bottom: 1px solid #eee; position: relative; padding-left: 50%; padding-top: 10px; padding-bottom: 10px; min-height: 24px; text-align: end; }
    .main-content td:before { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 45%; padding-right: 10px; white-space: nowrap; font-weight: bold; color: var(--medium-gray); content: attr(data-label); text-align: left; }
    .main-content td:last-child { border-bottom: none; }
    .card-body { padding: 10px; }
    .desktop-center { text-align: end; }
    .main-content table.table-inline, .main-content table.table-inline tbody, .main-content table.table-inline tr { display: table !important; width: 100%; border-collapse: collapse; border: none !important; margin-bottom: 0 !important; border-radius: 0 !important; }
    .main-content table.table-inline tr { border-bottom: none !important; }
    .main-content table.table-inline td { display: table-cell !important; width: auto; padding: 10px 8px; padding-left: 8px; min-height: 0; border-bottom: none; border-top: 1px solid #eee; position: static !important; text-align: left; }
    .main-content table.table-inline tr:first-child td { border-top: none; }
    .main-content table.table-inline td:before { display: none !important; }
    .main-content table.table-inline .sr-no, .main-content table.table-inline .vendor-name { text-align: left; }
    .main-content table.table-inline .vendor-outstanding { text-align: right !important; }
    .main-content table.table-inline .vendor-name { padding-left: 0 !important; }
}