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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    padding: 10px;
    line-height: 1.6;
}

.developer-credit {
    text-align: center;
    padding: 8px;
    margin-bottom: 5px;
    font-size: 14px;
    color: #2c3e50;
    background: #e8f5e9;
    border-radius: 4px;
    border-left: 4px solid #4caf50;
}

.work-details {
    background: #e3f2fd;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #2196f3;
}

.work-details h3 {
    margin-top: 0;
    color: #1976d2;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
}

.details-grid div {
    padding: 5px 0;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-form .form-group {
    margin-bottom: 15px;
}

.modal-form .form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.modal-form .form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.5em;
}

h2 {
    color: #34495e;
    margin-bottom: 10px;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
    font-size: 1.2em;
}

h3 {
    color: #34495e;
    margin-bottom: 15px;
}

.input-section {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.dimensions-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}

@media (max-width: 768px) {
    .dimensions-grid {
        flex-wrap: wrap;
        align-items: flex-end;
    }

    .dimensions-grid .form-group {
        flex: 1 1 60px !important;
        min-width: 60px !important;
    }

    /* Qty vide select takes more space */
    .dimensions-grid .form-group:first-child {
        flex: 1 1 100% !important;
        min-width: 100% !important;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 5px;
    color: #555;
}

.form-group input,
.form-group select,
.form-group datalist {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
}

#itemSearch {
    width: 100%;
    position: relative;
}

.item-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    max-height: 300px;
    overflow-y: auto;
    width: 100%;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.item-dropdown.show {
    display: block;
}

.item-option {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.item-option:hover {
    background: #f5f5f5;
}

.item-option:nth-child(even) {
    background: #fafafa;
}

.item-option:nth-child(even):hover {
    background: #f0f0f0;
}

.item-option-desc {
    font-weight: 500;
    color: #333;
    margin-bottom: 3px;
}

.item-option-rate {
    font-size: 12px;
    color: #666;
}

#itemSearch::-webkit-calendar-picker-indicator {
    display: none;
}

.form-group input[readonly] {
    background: #e9ecef;
    cursor: not-allowed;
}

/* Color coding for linked dimensions */
.linked-dim-1 {
    background-color: #ffebee !important;
    border: 2px solid #e57373 !important;
}

.linked-dim-2 {
    background-color: #e3f2fd !important;
    border: 2px solid #64b5f6 !important;
}

.linked-dim-3 {
    background-color: #e8f5e9 !important;
    border: 2px solid #81c784 !important;
}

.linked-dim-4 {
    background-color: #fff3e0 !important;
    border: 2px solid #ffb74d !important;
}

.linked-dim-5 {
    background-color: #f3e5f5 !important;
    border: 2px solid #ba68c8 !important;
}

.linked-dim-6 {
    background-color: #e0f2f1 !important;
    border: 2px solid #4db6ac !important;
}

.linked-dim-7 {
    background-color: #fce4ec !important;
    border: 2px solid #f06292 !important;
}

.linked-dim-8 {
    background-color: #e8eaf6 !important;
    border: 2px solid #7986cb !important;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #3498db;
    color: white;
}

.btn-secondary:hover {
    background: #2980b9;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
}

.btn-lavender {
    background: #81c784;
    color: white;
}

.btn-lavender:hover {
    background: #66bb6a;
}

.btn-cancel {
    background: #e74c3c;
    color: white;
}

.btn-cancel:hover {
    background: #c0392b;
}

.estimate-section {
    margin-top: 30px;
}

.table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: #34495e;
    color: white;
}

th,
td {
    padding: 12px;
    text-align: left;
    border: 1px solid #ddd;
}

th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
}

tbody tr:nth-child(even) {
    background: #f8f9fa;
}

tbody tr:hover {
    background: #e9ecef;
}

.action-btn {
    padding: 6px 12px;
    margin: 0 3px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s;
}

.edit-btn {
    background: #f39c12;
    color: white;
}

.edit-btn:hover {
    background: #e67e22;
}

.delete-btn {
    background: #e74c3c;
    color: white;
}

.delete-btn:hover {
    background: #c0392b;
}

.totals-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #ddd;
}

.total-row.final {
    border-top: 3px solid #2c3e50;
    border-bottom: 3px solid #2c3e50;
    margin-top: 10px;
    padding-top: 15px;
    font-size: 1.2em;
    font-weight: bold;
}

.total-label {
    font-weight: 600;
    color: #555;
}

.total-value {
    font-weight: 700;
    color: #2c3e50;
}

.escalation-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #ddd;
}

.misc-section {
    margin: 20px 0;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 4px;
}

.misc-section h4 {
    margin-top: 0;
    margin-bottom: 10px;
}

.misc-item {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px;
    background: white;
    border-radius: 4px;
}

.misc-item input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.misc-item button {
    padding: 8px 12px;
}

.component-header {
    background: #34495e;
    color: white;
    padding: 12px 15px;
    font-weight: bold;
    font-size: 1.1em;
    margin-top: 20px;
    border-radius: 4px;
}

.component-header:first-child {
    margin-top: 0;
}

.component-total {
    background: #ecf0f1;
    padding: 10px 15px;
    font-weight: bold;
    text-align: right;
    border-left: 4px solid #3498db;
    margin-bottom: 10px;
}

.dim-set {
    background: #f8f9fa;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 4px;
    border-left: 4px solid #3498db;
}

.dim-set-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.dim-set-header input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-weight: 600;
}

.item-header-row {
    background: #e3f2fd !important;
    font-weight: bold;
}

.dim-row {
    background: #fafafa;
}

.item-total-row {
    background: #fff3e0 !important;
    font-weight: bold;
    border-top: 2px solid #ff9800 !important;
}

.escalation-input {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.escalation-input label {
    font-weight: 600;
    color: #555;
}

.escalation-input input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 120px;
}

.escalation-results {
    margin-top: 15px;
}

/* Print Styles */
@media print {
    @page {
        margin: 20mm;
    }

    body {
        background: white;
        padding: 0;
        position: relative;
    }

    body::after {
        content: 'A.G.Lone';
        position: fixed;
        bottom: 20px;
        right: 20px;
        font-size: 18px;
        font-weight: bold;
        color: rgba(0, 0, 0, 0.3);
        transform: rotate(-45deg);
        transform-origin: center;
        z-index: 9999;
    }

    .container {
        box-shadow: none;
        padding: 20px;
        position: relative;
    }

    .no-print,
    .input-section,
    .button-group,
    .btn {
        display: none !important;
    }

    .work-details {
        background: #e3f2fd !important;
        border: 2px solid #2196f3 !important;
        border-left: 4px solid #2196f3 !important;
        border-radius: 0 !important;
        page-break-inside: avoid;
        margin-bottom: 30px !important;
        padding: 20px !important;
        display: block !important;
    }

    .work-details>div:first-child {
        display: block !important;
        margin-bottom: 15px !important;
    }

    .work-details h3 {
        background: transparent !important;
        color: #1976d2 !important;
        padding: 0 !important;
        margin: 0 0 15px 0 !important;
        font-size: 1.2em !important;
        border-bottom: 2px solid #2196f3 !important;
        padding-bottom: 8px !important;
    }

    .details-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .details-grid div {
        padding: 5px 0 !important;
        color: #333 !important;
        font-size: 13px !important;
    }

    .details-grid strong {
        color: #1976d2 !important;
    }

    h1 {
        font-size: 2em;
        margin-bottom: 25px;
        text-align: center;
        color: #2c3e50;
        border-bottom: 3px solid #3498db;
        padding-bottom: 15px;
        text-transform: uppercase;
        letter-spacing: 1px;
    }

    h2 {
        font-size: 1.3em;
        color: #34495e;
        margin-bottom: 15px;
        border-bottom: 2px solid #3498db;
        padding-bottom: 8px;
    }

    .table-wrapper {
        margin-bottom: 20px;
    }

    table {
        font-size: 13px;
        page-break-inside: auto;
        border-collapse: collapse;
        width: 100%;
    }

    thead {
        display: table-header-group;
    }

    thead tr {
        background: #e3f2fd !important;
    }

    thead th {
        background: #e3f2fd !important;
        color: #1976d2 !important;
        font-weight: bold !important;
        padding: 12px 8px !important;
        border: 1px solid #2196f3 !important;
        border-bottom: 2px solid #2196f3 !important;
        text-align: center !important;
        font-size: 13px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    .print-row {
        display: table-row !important;
    }

    .print-row td {
        padding: 8px !important;
        border: 1px solid #ddd !important;
    }

    .print-row.item-desc td {
        font-weight: bold;
        background: #f5f5f5;
        border-bottom: none !important;
    }

    .print-row.item-calc td {
        border-top: none !important;
        padding-left: 20px !important;
    }

    th:last-child {
        display: none;
    }

    th,
    td {
        padding: 6px 5px;
        font-size: 13px;
    }

    /* Fix column widths so total amount stays on one line */
    table th:nth-child(1), table td:nth-child(1) { width: 6%; }
    table th:nth-child(2), table td:nth-child(2) { width: 28%; }
    table th:nth-child(3), table td:nth-child(3) { width: 8%; }
    table th:nth-child(4), table td:nth-child(4) { width: 6%; }
    table th:nth-child(5), table td:nth-child(5) { width: 8%; white-space: nowrap; }
    table th:nth-child(6), table td:nth-child(6) { width: 11%; white-space: nowrap; }
    table th:nth-child(7), table td:nth-child(7) { width: 10%; white-space: nowrap; }
    table th:nth-child(8), table td:nth-child(8) { width: 11%; white-space: nowrap; }
    table th:nth-child(9), table td:nth-child(9) { width: 12%; white-space: nowrap; }

    .action-btn {
        display: none;
    }

    .totals-section {
        page-break-inside: avoid;
        page-break-before: avoid;
        background: white;
        border: 1px solid #ddd;
        margin-top: 20px;
    }

    .table-wrapper {
        page-break-after: avoid;
    }

    .estimate-section {
        page-break-inside: avoid;
    }

    .total-row {
        border-bottom: 1px solid #ddd;
    }

    .total-row.final {
        background: #f8f9fa;
        font-size: 1.1em;
    }

    .escalation-section h3 {
        font-size: 1.1em;
        color: #34495e;
       
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.3em;
    }

    .details-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 8px;
    }

    h1 {
        font-size: 1.2em;
        margin-bottom: 8px;
    }

    h2 {
        font-size: 1.1em;
    }

    .form-grid,
    .dimensions-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Modal action buttons: stack with spacing */
    .button-group {
        flex-direction: column;
        gap: 8px;
    }

    /* Load/cloud modal table action buttons: keep inline, add vertical spacing */
    .estimate-row td:last-child,
    .fb-est-row td:last-child,
    .sheet-estimate-row td:last-child {
        display: flex;
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
    }

    .btn {
        width: auto;
        padding: 8px 14px;
        font-size: 12px;
    }

    /* Specific buttons that should NOT be full width */
    #addManualItemBtn,
    #addComponentBtn,
    #editComponentBtn,
    #addDimSetBtn,
    #addBtn,
    #updateBtn,
    #cancelBtn,
    #addEscalationFieldBtn,
    #addMiscBtn,
    #addCurrentToFrequentBtn,
    #showFrequentItemsBtn {
        width: auto;
        display: inline-block;
    }

    /* dim-set remove button */
    .dim-set-header .btn {
        width: auto;
    }

    /* misc-item remove button */
    .misc-item .btn {
        width: auto;
        flex-shrink: 0;
    }

    /* escalation remove button */
    .escalation-input .btn {
        width: auto;
    }

    /* Search input full width */
    #itemSearch {
        width: 100%;
        min-width: 0;
    }

    /* Item dropdown visible and properly sized */
    .item-dropdown {
        width: 100%;
        max-height: 250px;
        font-size: 13px;
        z-index: 1100;
    }

    .item-dropdown.show {
        display: block;
    }

    /* Dim set name input */
    .dim-set-header input {
        min-width: 0;
        width: 100%;
    }

    /* Misc item inputs */
    .misc-item {
        flex-wrap: wrap;
    }

    .misc-item input[type="text"] {
        min-width: 0;
        flex: 1 1 100%;
    }

    .misc-item input[type="number"] {
        width: 120px !important;
        flex: 0 0 120px;
    }

    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 11px;
        min-width: 800px;
    }

    th,
    td {
        padding: 6px 4px;
    }

    .action-btn {
        padding: 4px 8px;
        font-size: 11px;
        margin: 2px;
    }

    .modal-content {
        width: 95%;
        padding: 15px;
        margin: 10% auto;
    }

    .developer-credit {
        font-size: 12px;
        padding: 6px;
    }

    .dim-set {
        padding: 10px;
    }

    .form-group input,
    .form-group select {
        padding: 8px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.1em;
    }

    .btn {
        font-size: 11px;
        padding: 6px 10px;
    }

    table {
        font-size: 10px;
    }

    th,
    td {
        padding: 4px 2px;
    }

    .total-row {
        font-size: 13px;
    }

    .total-row.final {
        font-size: 14px;
    }
}