/* Import Modern Google Font */
@import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@400;500;600;700&display=swap');

/* Modern CSS Variables for Theming */
:root {
    --primary-color: hsl(145, 20%, 55%);
    --primary-dark: hsl(145, 25%, 45%);
    --secondary-color: hsl(155, 18%, 65%);
    --accent-color: hsl(140, 22%, 60%);
    --bg-gradient-start: hsl(145, 15%, 92%);
    --bg-gradient-end: hsl(150, 12%, 96%);
    --card-bg: rgba(250, 240, 240, 0.95);
    --text-primary: hsl(0, 0%, 0%);
    --text-secondary: hsl(0, 0%, 0%);
    --border-color: hsl(145, 15%, 82%);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.15);
    --border-radius: 12px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Quicksand', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Apply font to all elements */
* {
    font-family: var(--font-family);
}

/* Main Container Styling */
.login-box {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    transition: var(--transition-smooth);
}

.form-with-panel .login-box {
    margin: 0;
}

.login-box:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    transform: translateY(-2px);
}

/* Form Container using CSS Grid */
.login-box table {
    width: 100%;
    border-collapse: collapse;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

.login-box tr {
    display: grid;
    grid-template-columns: minmax(120px, 200px) minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 1rem;
}

.login-box tr.user-box {
    display: grid;
    grid-template-columns: minmax(120px, 200px) minmax(0, 1fr) auto auto;
    gap: 1rem;
}

/* Label Styling */
.login-box label {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 1.08rem;
    letter-spacing: 0.3px;
}

/* Input Field Styling */
.login-box input[type="text"],
.login-box input[type="email"],
.login-box input[type="date"],
.login-box input[type="number"],
.login-box select {
    width: 100%;
    max-width: 100%;
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text-primary);
    background: white;
    transition: var(--transition-smooth);
    box-sizing: border-box;
}

.login-box input[type="text"]:focus,
.login-box input[type="email"]:focus,
.login-box input[type="date"]:focus,
.login-box input[type="number"]:focus,
.login-box select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    transform: translateY(-1px);
}

.login-box input[type="text"]:hover,
.login-box input[type="email"]:hover,
.login-box input[type="date"]:hover,
.login-box input[type="number"]:hover,
.login-box select:hover {
    border-color: var(--primary-dark);
}

.login-box input[type="text"]:disabled {
    background-color: hsl(145, 15%, 95%);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Override HTML size attributes to prevent overflow */
.login-box input[size] {
    width: 100% !important;
    max-width: 100% !important;
}

/* Checkbox Styling */
.login-box input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* Button Styling - 3D with Solid Colors */
.login-box button,
.button {
    padding: 0.45rem 0.65rem;
    border: none;
    border-radius: 8px;
    font-size: 1.00rem;
    font-weight: 400;
    cursor: pointer;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.5px;
    /*  min-width: 140px;*/
    white-space: wrap;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1),
        0 1px 3px rgba(0, 0, 0, 0.08),
        inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

/* Disabled button styles */
.button:disabled,
.button[disabled],
button:disabled,
button[disabled] {
    opacity: 0.5;
    cursor: not-allowed !important;
    background-color: #ccc !important;
    color: #666 !important;
    pointer-events: none;
    box-shadow: none !important;
}

.login-box button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1),
        inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

.login-box button[type="button"]:first-of-type,
button[onclick="SubmitForm(event)"] {
    background: #a8a788;
    color: #2d3a2e;
}

.login-box button[type="button"]:first-of-type:hover,
button[onclick="SubmitForm(event)"]:hover {
    background: #9a9a7a;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.1),
        inset 0 -2px 0 rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.login-box button[onclick="ClearForm()"] {
    background: #d5d5c5;
    color: #2d3a2e;
    border: 2px solid #a8a788;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08),
        0 1px 3px rgba(0, 0, 0, 0.06);
}

.login-box button[onclick="ClearForm()"]:hover {
    background: #c5c5b5;
    border-color: #a8a788;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12),
        0 2px 4px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.login-box button#addtype {
    background: #a8a788;
    color: #2d3a2e;
    padding: 0.5rem 1rem;
    font-size: 1.03rem;
    min-width: 80px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1),
        0 1px 3px rgba(0, 0, 0, 0.08),
        inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

.login-box input#typetxt {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    max-width: 150px;
}

.login-box button#addtype:hover {
    background: #9a9a7a;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.1),
        inset 0 -2px 0 rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}


/* Search Overlay - Responsive */
.overlay {
    position: absolute;
    top: 10%;
    left: 40%;
    right: 10%;
    max-height: 400px;
    overflow-y: auto;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    margin-top: 0.5rem;
}

/* Search Results Dropdown */
#search-results {
    display: none;
    position: fixed !important;
    z-index: 9999 !important;
    text-align: left !important;
    background: white;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 2px solid var(--primary-color);
    width: 600px;
    max-width: calc(100vw - 40px);
    /* Position is controlled by JavaScript - don't set left/top here */
}

/* Customer Table Styling */
.customer-table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    text-align: left !important;
}

.customer-table table {
    width: 100%;
    border-collapse: collapse;
    display: table;
    text-align: left !important;
}

.customer-table th,
.customer-table td {
    padding: 0.4rem 0.75rem;
    text-align: left !important;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.customer-table th {
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border-color);
}

/* Column-specific widths */
.customer-table th:nth-child(1),
.customer-table td:nth-child(1) {
    width: 30px;
    min-width: 30px;
    max-width: 30px;
}

.customer-table th:nth-child(2),
.customer-table td:nth-child(2) {
    width: 80px;
    min-width: 80px;
    max-width: 80px;
}

.customer-table th:nth-child(3),
.customer-table td:nth-child(3) {
    width: 70px;
    min-width: 70px;
    max-width: 70px;
}

.customer-table tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.customer-table tr.clickable-row:hover {
    background: linear-gradient(90deg, rgba(100, 150, 120, 0.05), rgba(120, 160, 130, 0.05));
    transform: scale(1.01);
}

.customer-table tr:nth-child(even) {
    background-color: hsl(145, 15%, 98%);
}

/* Employee Table Styling */
.employee-table {
    width: 600px;
    max-width: 100%;
    overflow-x: auto;
    text-align: left !important;
}

.employee-table table {
    width: 100%;
    border-collapse: collapse;
    display: table;
    text-align: left !important;
}

.employee-table th,
.employee-table td {
    padding: 0.4rem 0.75rem;
    text-align: left !important;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.employee-table th {
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border-color);
}

.employee-table tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.employee-table tr.clickable-row:hover {
    background: linear-gradient(90deg, rgba(100, 150, 120, 0.05), rgba(120, 160, 130, 0.05));
    transform: scale(1.01);
}

.employee-table tr:nth-child(even) {
    background-color: hsl(145, 15%, 98%);
}

/* Supplier Table Styling */
.supplier-table {
    width: 600px;
    max-width: 100%;
    overflow-x: auto;
    text-align: left !important;
}

.supplier-table table {
    width: 100%;
    border-collapse: collapse;
    display: table;
    text-align: left !important;
}

.supplier-table th,
.supplier-table td {
    padding: 0.4rem 0.75rem;
    text-align: left !important;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.supplier-table th {
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border-color);
}

.supplier-table tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.supplier-table tr.clickable-row:hover {
    background: linear-gradient(90deg, rgba(100, 150, 120, 0.05), rgba(120, 160, 130, 0.05));
    transform: scale(1.01);
}

.supplier-table tr:nth-child(even) {
    background-color: hsl(145, 15%, 98%);
}

/* Items Table Styling */
.items-table {
    width: 600px;
    max-width: 100%;
    overflow-x: auto;
    text-align: left !important;
}

.items-table table {
    width: 100%;
    border-collapse: collapse;
    display: table;
    text-align: left !important;
}

.items-table th,
.items-table td {
    padding: 0.4rem 0.75rem;
    text-align: left !important;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.items-table tr:nth-last-child(1) td:nth-last-child(1) {
    text-align: right !important;
}

.items-table th {
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border-color);
}

.items-table tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.items-table tr.clickable-row:hover {
    background: linear-gradient(90deg, rgba(100, 150, 120, 0.05), rgba(120, 160, 130, 0.05));
    transform: scale(1.01);
}

.items-table tr:nth-child(even) {
    background-color: hsl(145, 15%, 98%);
}

/* Damaged Items Table Styling */
.damaged-table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    text-align: left !important;
}

.damaged-table table {
    width: 100%;
    border-collapse: collapse;
    display: table;
    text-align: left !important;
}

.damaged-table th,
.damaged-table td {
    padding: 0.4rem 0.75rem;
    text-align: left !important;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.damaged-table th {
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border-color);
}

.damaged-table tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.damaged-table tr.clickable-row:hover {
    background: linear-gradient(90deg, rgba(100, 150, 120, 0.05), rgba(120, 160, 130, 0.05));
    transform: scale(1.01);
}

.damaged-table tr:nth-child(even) {
    background-color: hsl(145, 15%, 98%);
}

/* Stock Adjustment Table Styling */
.stock-table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    text-align: left !important;
}

.stock-table table {
    width: 100%;
    border-collapse: collapse;
    display: table;
    text-align: left !important;
}

.stock-table th,
.stock-table td {
    padding: 0.4rem 0.75rem;
    text-align: left !important;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.stock-table th {
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border-color);
}

.stock-table tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.stock-table tr.clickable-row:hover {
    background: linear-gradient(90deg, rgba(100, 150, 120, 0.05), rgba(120, 160, 130, 0.05));
    transform: scale(1.01);
}

.stock-table tr:nth-child(even) {
    background-color: hsl(145, 15%, 98%);
}

/* Page Title */
h2 {
    color: hsl(145, 30%, 38%);
    font-size: 2.25rem;
    font-weight: 400;
    margin-bottom: 0.5rem;
}

/* Message Styling */
#msg {
    margin-top: 0;
    margin-bottom: 0.1rem;
    padding: 0;
    border-radius: 8px;
    font-weight: 400;
    display: none;
    transition: opacity 0.5s ease-out;
}

#msg.show {
    display: block;
}

#msg.fade-out {
    opacity: 0;
}

#msg .msg {
    background: linear-gradient(135deg, hsl(140, 60%, 95%), hsl(140, 50%, 98%));
    border-left: 4px solid hsl(140, 60%, 50%);
    padding: 1rem;
    border-radius: 8px;
}

#msg .error {
    background: linear-gradient(135deg, hsl(0, 60%, 95%), hsl(0, 50%, 98%));
    border-left: 4px solid hsl(0, 60%, 50%);
    padding: 1rem;
    border-radius: 8px;
}

/* Responsive Design - Mobile First */
@media (max-width: 480px) {
    .login-box {
        padding: 1rem;
        border-radius: 8px;
    }

    .login-box tr,
    .login-box tr.user-box {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .login-box td {
        grid-column: 1;
    }

    .hide-column {
        display: none !important;
    }

    .login-box label {
        display: inline-block;
        margin-bottom: 0.25rem;
    }

    .login-box input[type="text"],
    .login-box input[type="email"],
    .login-box select {
        width: 100%;
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    .login-box button,
    .button {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    .customer-table {
        font-size: 0.875rem;
    }

    .customer-table th,
    .customer-table td {
        padding: 0.5rem;
    }

    .overlay {
        max-height: 300px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .login-box {
        padding: 1.5rem;
    }

    .login-box tr,
    .login-box tr.user-box {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .hide-column {
        display: none !important;
    }

    .login-box label {
        display: inline-block;
    }

    .login-box button {
        padding: 0.85rem 1.5rem;
    }

    h2 {
        font-size: 1.75rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .login-box {
        max-width: 800px;
    }

    .login-box tr,
    .login-box tr.user-box {
        grid-template-columns: 180px 1fr auto auto;
    }
}

@media (min-width: 1025px) {
    .login-box {
        max-width: 900px;
    }
}

/* Smooth Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-box {
    animation: fadeIn 0.5s ease-out;
}

/* Focus visible for accessibility */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Scrollbar Styling */
.overlay::-webkit-scrollbar {
    width: 8px;
}

.overlay::-webkit-scrollbar-track {
    background: hsl(220, 20%, 95%);
    border-radius: 4px;
}

.overlay::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.overlay::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Description Panel Styles */
.form-with-panel {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    width: 78%;
    max-width: 100%;
}

.form-with-panel form {
    margin: 0;
    padding: 0;
}

.description-panel {
    display: none;
    /* Hidden by default on mobile/tablet */
    flex: 0 0 350px;
    max-width: 350px;
    position: sticky;
    top: 1rem;
    margin-top: 0;
    z-index: 100;
    background: var(--card-bg);
    backdrop-filter: blur(15px);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transition: var(--transition-smooth);
    animation: slideInRight 0.5s ease-out;
}

.description-panel:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.panel-content {
    padding: 1.5rem;
}

.panel-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-color);
    transition: var(--transition-smooth);
}

.panel-body {
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.6;
    transition: opacity 0.3s ease-in-out;
}

.panel-body p {
    margin-bottom: 0.75rem;
}

.panel-body strong {
    color: var(--primary-dark);
    font-weight: 600;
}

.panel-body em {
    color: var(--text-secondary);
    font-style: italic;
}

.panel-body ul {
    margin: 0.5rem 0 0.75rem 1.5rem;
    padding: 0;
}

.panel-body li {
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
}

/* Desktop only - Show panel on screens >= 1025px */
@media (min-width: 1025px) {
    .description-panel {
        display: block;
    }

    .form-with-panel form {
        flex: 1;
        min-width: 0;
        /* Allows flex item to shrink below content size */
    }
}

/* Ensure panel is hidden on tablets and mobile */
@media (max-width: 1024px) {
    .description-panel {
        display: none !important;
    }

    .form-with-panel {
        display: block;
        width: 100%;
    }
}

/* Bill Preview Table Container - Horizontal Scroll */
#invoice-preview {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
}

#invoice-preview::-webkit-scrollbar {
    height: 8px;
}

#invoice-preview::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#invoice-preview::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#invoice-preview::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Bill Preview Table (for void bills) */
.bill-preview-table {
    width: 100%;
    min-width: 320px;
    margin: 10px 0;
    border-collapse: collapse;
    font-size: 0.75em;
    table-layout: auto;
}

.bill-preview-table th,
.bill-preview-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    white-space: nowrap;
    transition: all 0.3s ease;
}

/* Row hover effect */
.bill-preview-table tbody tr {
    transition: all 0.3s ease;
    cursor: pointer;
}

.bill-preview-table tbody tr:hover {
    background-color: #f0f8f4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.bill-preview-table tbody tr:hover td {
    font-weight: 500;
    padding: 8px 10px;
}

.bill-preview-table th {
    background-color: hsl(145, 15%, 96%);
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 0.85em;
}

.bill-preview-table tfoot td {
    font-weight: bold;
    background-color: hsl(145, 15%, 94%);
    border-top: 2px solid var(--border-color);
    font-size: 0.95em;
    padding: 8px;
    white-space: nowrap;
}

/* Force all tfoot cells to left alignment */
.bill-preview-table tfoot tr td {
    text-align: left !important;
}

/* Compact column widths to fit in 350px panel */
.bill-preview-table th:nth-child(1),
.bill-preview-table td:nth-child(1) {
    width: 18%;
    min-width: 45px;
}

.bill-preview-table th:nth-child(2),
.bill-preview-table td:nth-child(2) {
    width: 32%;
    min-width: 80px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Show full name on hover */
.bill-preview-table tbody tr:hover td:nth-child(2) {
    white-space: normal;
    word-wrap: break-word;
    overflow: visible;
}

.bill-preview-table th:nth-child(3),
.bill-preview-table td:nth-child(3) {
    width: 12%;
    min-width: 35px;
    text-align: right;
}

.bill-preview-table th:nth-child(4),
.bill-preview-table td:nth-child(4) {
    width: 18%;
    min-width: 45px;
    text-align: right;
}

.bill-preview-table th:nth-child(5),
.bill-preview-table td:nth-child(5) {
    width: 20%;
    min-width: 50px;
    text-align: right;
}

/* Void Button Disabled State */
#void-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #ccc !important;
    color: #666 !important;
}

#void-submit-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Slide in animation for panel */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(60px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}