* { box-sizing: border-box; margin: 0; padding: 0; font-family: Arial, sans-serif; }
html { font-size: 14px; }
body { background: #f4f7fb; color: #222; }

.auth-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg,#1f7a3f,#74c69d); }
.auth-card { background: #fff; padding: 26px; width: 340px; border-radius: 16px; box-shadow: 0 10px 25px rgba(0,0,0,0.15); }
.auth-card h2 { margin-bottom: 18px; text-align: center; color: #1f7a3f; font-size: 1.35rem; }
.auth-card input, .auth-card button { width: 100%; padding: 10px 12px; margin-bottom: 10px; border-radius: 10px; border: 1px solid #ccc; font-size: 0.95rem; }
.auth-card button { background: #1f7a3f; color: #fff; border: none; cursor: pointer; }
.auth-card p a{ color:#1f7a3f; font-weight:750; text-decoration:none; }

.alert { background: #ffd6d6; color: #a10000; padding: 10px; margin-bottom: 12px; border-radius: 8px; font-size: 0.92rem; }

.layout { display: flex; min-height: 100vh; width: 100%; }

.sidebar {
    width: 190px;
    min-width: 190px;
    flex-shrink: 0;
    background: #1f7a3f;
    padding: 16px 12px;
    color: white;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar h2 { margin-bottom: 16px; font-size: 1.1rem; line-height: 1.25; }
.sidebar a {
    display: block;
    color: white;
    text-decoration: none;
    padding: 9px 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: rgba(255,255,255,0.08);
    font-size: 0.9rem;
    line-height: 1.25;
    white-space: normal;
}
.sidebar a:hover { background: rgba(255,255,255,0.18); }

.main-content { flex: 1; min-width: 0; padding: 16px; }

.topbar {
    background: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    margin-bottom: 16px;
    text-align: right;
    font-weight: bold;
    font-size: 0.92rem;
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px,1fr));
    gap: 16px;
}

.card, .form-card, .table-card, .credit-card {
    background: white;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.card h3 { color: #444; margin-bottom: 8px; font-size: 1rem; }
.card p { font-size: 1.4rem; color: #1f7a3f; font-weight: bold; }

.form-card form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px,1fr));
    gap: 10px;
    margin-top: 12px;
}

.form-card input,
.form-card select,
.form-card button,
.credit-form-grid input,
.credit-form-grid select,
.credit-form-grid button,
.pay-section input,
.pay-section button,
.search-bar input,
.search-bar button,
.export-btn {
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 10px;
    font-size: 0.92rem;
}

.form-card button,
.credit-form-grid button,
.pay-btn,
.action-btn,
.search-bar button,
.export-btn {
    background: #1f7a3f;
    color: white;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.table-card { margin-top: 16px; overflow: hidden; }

.table-scroll {
    max-height: 286px;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    margin-top: 10px;
}

.table-scroll table {
    margin-top: 0;
    min-width: 100%;
    width: max-content;
}

table {
    width: 100%;
    min-width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 0.9rem;
}

th, td {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    text-align: left;
    vertical-align: top;
}

th {
    background: #eff7f1;
    position: sticky;
    top: 0;
    z-index: 2;
}

tr:hover { background: #f8fbf8; }

.low-stock { background: #ffe1e1 !important; color: #a10000; font-weight: bold; }

.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.suggestions {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-top: 8px;
    overflow: hidden;
    max-height: 220px;
    overflow-y: auto;
}

.suggestion-item {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

.suggestion-item:hover { background: #f1f8f3; }

.bill-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px,1fr));
    gap: 10px;
    margin-top: 12px;
}

#billTable button,
.return-btn {
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: #d9534f;
    color: #fff;
    cursor: pointer;
    font-size: 0.86rem;
}

#billTable button:hover,
.return-btn:hover {
    background: #c9302c;
}

.active-menu { background: rgba(255,255,255,0.22) !important; font-weight: bold; }
.near-expiry { background: #fff3b0 !important; color: #7a5d00; font-weight: bold; }
.negative-balance { background: #ffe1e1 !important; color: #a10000; font-weight: bold; }
#billSearchTable .negative-balance td { color: #a10000; font-weight: bold; }

.notice-box {
    background: #fff8d6;
    color: #7a5d00;
    padding: 12px;
    border-radius: 10px;
    margin-top: 12px;
    font-size: 0.92rem;
}

.message-box {
    margin-top: 15px;
    padding: 12px;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.92rem;
}

.success-box { background: #e2f7e2; color: #1f7a3f; }
.error-box { background: #ffdede; color: #b00020; }

.bill-return-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px,1fr));
    gap: 10px;
    margin-top: 10px;
}

.returned-label {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 8px;
    background: #e6f4ea;
    color: #1f7a3f;
    font-weight: bold;
}

.returned-row { background: #f3f6f9 !important; color: #555; }

.credit-layout { display: flex; flex-direction: column; gap: 16px; }

.credit-card h2,
.credit-card h3 {
    margin-bottom: 12px;
    color: #2b2b2b;
    font-size: 1.08rem;
}

.credit-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px,1fr));
    gap: 10px;
    margin-top: 10px;
}

.delete-btn { background: #c9302c !important; }

.pay-section {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.pending-credit { background: #ffe1e1 !important; color: #a10000; font-weight: bold; }

.credit-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px,1fr));
    gap: 10px;
    margin-top: 10px;
}

.info-pill {
    background: #eff7f1;
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.9rem;
}

/* universal stable tables */
.table-card > table,
.form-card > table {
    display: block;
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 286px;
    white-space: nowrap;
}

.table-card > table tbody,
.table-card > table thead {
    width: 100%;
}

/* Sale page bill area */
.bill-table-wrap {
    margin-top: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 10px;
    overflow: auto;
    max-height: 300px;
}

.bill-table-wrap table {
    margin-top: 0;
    min-width: 760px;
}

/* Print logo helper placeholder for normal pages */
.bill-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 6px auto;
    border: 1px solid #bbb;
    font-size: 0.72rem;
    color: #666;
}

/* Sale section bottom amount colors */
#received_amount {
    color: #000000;
    font-weight: 700;
}

#balance_amount {
    color: #1f7a3f;
    font-weight: 700;
}

#total_amount {
    color: #000000;
    font-weight: 700;
}

#discount_amount {
    color: #1f4fb8;
    font-weight: 700;
}

#net_total_amount {
    color: #c9302c;
    font-weight: 700;
}

/* Credit-purchases action column styling */
.credit-action-form {
    display: grid;
    gap: 8px;
    min-width: 180px;
}

.credit-action-form input,
.credit-action-form select,
.credit-action-form button {
    width: 100%;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-sizing: border-box;
}

.credit-action-form input,
.credit-action-form select {
    border: 1px solid #cfd8dc;
    background: #fff;
}

.credit-action-form button {
    border: none;
    background: #1f7a3f;
    color: #fff;
    cursor: pointer;
    font-weight: 600;
}

.credit-action-form button:hover {
    background: #186233;
}

/* Dashboard final layout */
.stats-main-card {
    background: #1f7a3f;
    border-radius: 26px;
    padding: 14px 16px 18px 16px;
    margin-bottom: 18px;
    border: 1px solid #5a86b1;
}

.monthly-stats-card {
    background: #1aab34;
}

.stats-main-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 14px;
}

.stats-mini-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 14px;
}

.stats-mini-card {
    background: #ffffff;
    border-radius: 12px;
    min-height: 92px;
    padding: 12px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stats-mini-card h3 {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: #333;
    font-weight: 700;
    line-height: 1.2;
}

.stats-mini-card p {
    font-size: 1.02rem;
    font-weight: 700;
    color: #bf0a58;
    line-height: 1.2;
    word-break: break-word;
}

.monthly-mini-card p {
    color: #2f5fa7;
}

.dashboard-two-quadrant {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
    gap: 20px;
    align-items: start;
    margin-top: 4px;
}

.dashboard-chart-card {
    background: #fff;
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
    overflow: hidden;
}

.dashboard-chart-card h3 {
    text-align: center;
    font-size: 1rem;
    margin-bottom: 12px;
    color: #4b4b4b;
    font-weight: 700;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 320px;
}

.pie-chart-box {
    height: 320px;
}

.chart-box canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

@media (min-width: 1400px) {
    html { font-size: 15px; }
    .sidebar { width: 210px; min-width: 210px; }
}

@media (min-width: 2200px) {
    html { font-size: 16px; }
    .main-content { padding: 22px; }
    .card, .form-card, .table-card, .credit-card { padding: 18px; }
}

@media (max-width: 1250px) {
    .stats-mini-grid {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }
}

@media (max-width: 980px) {
    .layout { flex-direction: row; }
    .sidebar { width: 180px; min-width: 180px; }
    .main-content { padding: 12px; }
    .dashboard-cards { grid-template-columns: 1fr; }

    .stats-mini-grid {
        grid-template-columns: repeat(2, minmax(140px, 1fr));
    }

    .dashboard-two-quadrant {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .stats-mini-grid {
        grid-template-columns: 1fr;
    }

    .chart-box,
    .pie-chart-box {
        height: 260px;
    }
}


/* Dual pricing update */
.dual-mode-wrap input,
.dual-mode-wrap select {
    width: 100%;
}

.mode-select-backdrop,
.mode-select-box,
.mode-option-btn,
.mode-option-title,
.mode-option-meta,
.sale-mode-badge {
    box-sizing: border-box;
}


/* Daily purchasing professional layout */
.daily-purchase-form {
    display: grid;
    gap: 16px;
}

.daily-purchase-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 12px;
}

.daily-purchase-grid .field-group,
.dual-mode-card .field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.daily-purchase-grid .field-group label,
.dual-mode-card .field-group label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #344054;
}

.dual-mode-card {
    margin-top: 2px;
    padding: 14px;
    border: 1px solid #dfe6e0;
    border-radius: 14px;
    background: linear-gradient(180deg, #f8fbf8, #f1f7f2);
}

.dual-mode-title {
    margin-bottom: 12px;
    font-weight: 700;
    color: #1f7a3f;
    font-size: 1rem;
}

.dual-mode-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
}

.daily-action-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.daily-action-row button {
    min-width: 160px;
}

.daily-purchase-form input[readonly] {
    background: #f5f7fa;
    color: #2d3748;
    font-weight: 700;
}

@media (max-width: 1200px) {
    .daily-purchase-grid {
        grid-template-columns: repeat(3, minmax(180px, 1fr));
    }
    .dual-mode-grid {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}

@media (max-width: 820px) {
    .daily-purchase-grid,
    .dual-mode-grid {
        grid-template-columns: 1fr;
    }
}


/* Daily purchasing live layout fix */
.form-card .daily-purchase-form{
    display:flex !important;
    flex-direction:column;
    gap:18px;
    width:100%;
    margin-top:12px;
}

.form-card .daily-purchase-grid{
    display:grid;
    grid-template-columns:repeat(5,minmax(0,1fr));
    gap:14px;
    align-items:end;
    width:100%;
}

.form-card .daily-purchase-grid .field-group,
.form-card .dual-mode-grid .field-group{
    min-width:0;
    width:100%;
}

.form-card .daily-purchase-grid .field-group.field-span-2{
    grid-column:span 2;
}

.form-card .daily-purchase-grid .field-group.field-highlight input{
    font-weight:700;
    color:#1f7a3f;
    background:#f4fbf6;
}

.form-card .field-group label{
    margin-bottom:2px;
    line-height:1.2;
}

.form-card .field-group input,
.form-card .field-group select{
    width:100%;
    min-width:0;
    max-width:100%;
    height:44px;
    padding:10px 12px;
    display:block;
}

.form-card .field-group input[type="date"]{
    min-width:0;
}

.form-card .dual-mode-card{
    width:100%;
    margin-top:0;
    padding:16px;
    overflow:hidden;
}

.form-card .dual-mode-grid{
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:14px;
    width:100%;
}

.form-card .daily-action-row{
    display:flex;
    flex-wrap:wrap;
    gap:12px;
    align-items:center;
}

.form-card .daily-action-row button{
    min-width:170px;
    height:44px;
    padding:10px 16px;
    font-weight:700;
}

@media (max-width: 1380px){
    .form-card .daily-purchase-grid{
        grid-template-columns:repeat(4,minmax(0,1fr));
    }
}

@media (max-width: 1120px){
    .form-card .daily-purchase-grid{
        grid-template-columns:repeat(3,minmax(0,1fr));
    }
    .form-card .dual-mode-grid{
        grid-template-columns:repeat(2,minmax(0,1fr));
    }
    .form-card .daily-purchase-grid .field-group.field-span-2{
        grid-column:span 1;
    }
}

@media (max-width: 780px){
    .form-card .daily-purchase-grid,
    .form-card .dual-mode-grid{
        grid-template-columns:repeat(2,minmax(0,1fr));
    }
}

@media (max-width: 560px){
    .form-card .daily-purchase-grid,
    .form-card .dual-mode-grid{
        grid-template-columns:1fr;
    }
    .form-card .daily-action-row button{
        width:100%;
        min-width:0;
    }
}


/* Credit purchasing invoice modal update */
.invoice-action-btn{
    padding:9px 14px;
    border:none;
    border-radius:8px;
    background:#1f7a3f;
    color:#fff;
    cursor:pointer;
    font-weight:700;
    min-width:96px;
}
.invoice-action-btn:hover{
    background:#186233;
}

.credit-modal-backdrop{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,0.42);
    display:none;
    align-items:center;
    justify-content:center;
    z-index:9999;
    padding:18px;
}
.credit-modal-backdrop.show{
    display:flex;
}
.credit-modal-card{
    width:100%;
    max-width:920px;
    max-height:88vh;
    background:#fff;
    border-radius:18px;
    box-shadow:0 18px 40px rgba(0,0,0,0.24);
    display:flex;
    flex-direction:column;
    overflow:hidden;
}
.credit-modal-header{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:14px;
    padding:18px 20px 12px 20px;
    border-bottom:1px solid #e7ecef;
}
.credit-modal-header h3{
    margin-bottom:6px;
    color:#1f7a3f;
    font-size:1.15rem;
}
.credit-modal-meta{
    font-size:0.92rem;
    color:#555;
    line-height:1.45;
}
.credit-modal-close{
    border:none;
    background:#f1f3f5;
    color:#333;
    width:36px;
    height:36px;
    border-radius:10px;
    font-size:1.3rem;
    cursor:pointer;
    line-height:1;
}
.credit-modal-close:hover{
    background:#e2e8ec;
}
.credit-modal-items-wrap{
    padding:0 20px;
    overflow:hidden;
}
.credit-modal-items{
    max-height:310px;
    overflow-y:auto;
    padding:14px 0;
}
.credit-modal-item-row{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:16px;
}
.credit-item-main{
    min-width:0;
    flex:1;
}
.credit-item-name{
    font-weight:700;
    color:#263238;
    margin-bottom:4px;
}
.credit-item-sub{
    color:#60707a;
    font-size:0.9rem;
}
.credit-item-values{
    min-width:220px;
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:10px;
}
.credit-item-values div{
    background:#f8faf9;
    border:1px solid #e3ece6;
    border-radius:10px;
    padding:10px 12px;
}
.credit-item-values span{
    display:block;
    font-size:0.82rem;
    color:#64707b;
    margin-bottom:4px;
}
.credit-item-values strong{
    color:#1d2939;
    font-size:0.95rem;
}
.credit-modal-item-separator{
    border-top:1px dashed #d7e0d8;
    margin:12px 0;
}
.credit-modal-divider{
    border-top:1px solid #e7ecef;
}
.credit-modal-footer{
    padding:16px 20px 18px 20px;
    background:#fff;
    position:sticky;
    bottom:0;
}
.credit-modal-summary-row{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
    margin-bottom:14px;
}
.credit-summary-pill{
    background:#f3f8f4;
    border:1px solid #dbe8de;
    padding:10px 12px;
    border-radius:10px;
    font-weight:700;
    color:#1f7a3f;
}
.credit-modal-action-grid{
    display:grid;
    grid-template-columns:1fr 1fr 1fr;
    gap:12px;
    margin-bottom:14px;
}
.credit-modal-action-grid input,
.credit-modal-action-grid select{
    width:100%;
    padding:10px 12px;
    border:1px solid #cfd8dc;
    border-radius:10px;
    font-size:0.92rem;
}
.credit-modal-button-row{
    display:flex;
    gap:12px;
    flex-wrap:wrap;
}
.credit-modal-button-row button{
    min-width:150px;
    padding:10px 16px;
    border:none;
    border-radius:10px;
    background:#1f7a3f;
    color:#fff;
    font-weight:700;
    cursor:pointer;
}
.credit-modal-button-row button:hover{
    background:#186233;
}
.credit-modal-empty{
    color:#667085;
    padding:4px 0 10px 0;
}

@media (max-width: 820px){
    .credit-item-values{
        min-width:0;
        width:100%;
        grid-template-columns:1fr 1fr;
    }
    .credit-modal-item-row{
        flex-direction:column;
    }
    .credit-modal-action-grid{
        grid-template-columns:1fr;
    }
}

@media (max-width: 560px){
    .credit-modal-button-row button{
        width:100%;
        min-width:0;
    }
}


.topbar{
    position: relative;
}
.topbar-left-status{
    float:left;
    min-height:1px;
}
.system-toast{
    position: fixed;
    top: 18px;
    left: 212px;
    z-index: 10000;
    min-width: 260px;
    max-width: 420px;
    background: #fff2f2;
    color: #c9302c;
    border: 1px solid #e8b3b3;
    border-left: 5px solid #c9302c;
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.14);
    font-size: 0.9rem;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.25s ease;
}
.system-toast.success{
    background: #edf9f0;
    color: #1f7a3f;
    border-color: #b8ddc3;
    border-left-color: #1f7a3f;
}
.system-toast.show{
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
@media (max-width: 980px) {
    .system-toast{
        left: 190px;
        max-width: calc(100vw - 220px);
    }
}
@media (max-width: 700px) {
    .system-toast{
        left: 12px;
        right: 12px;
        max-width: none;
        min-width: 0;
        top: 12px;
    }
}
