:root {
    --primary-color: #cf4e4e;
    --primary-color-hover: #b84545;
    --quotation-color: #2c3e50;
    --success-color: #27ae60;
    --success-color-hover: #229954;
    --background-color: #f7f8fc;
    --form-background: #ffffff;
    --text-color: #2c3e50;
    --label-color: #34495e;
    --border-color: #dfe4ea;
    --border-focus-color: #cf4e4e;
    --white-color: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.08);
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
}

.body-no-scroll {
    overflow: hidden;
}

.form-container {
    max-width: 1000px;
    margin: 30px auto;
    padding: 40px;
    background-color: var(--form-background);
    border-radius: 12px;
    box-shadow: 0 6px 20px var(--shadow-color);
}

h1, h2 {
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 25px;
    font-weight: 600;
}

h1 {
    font-size: 1.8rem;
    text-align: center;
}

h2 {
    font-size: 1.4rem;
    border-bottom: none;
    margin-bottom: 15px;
    padding-bottom: 0;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.terms-grid {
    margin-top: 40px;
}

.grid-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--label-color);
    font-size: 0.9rem;
}

.grid-item input[type="text"],
.grid-item input[type="number"],
.grid-item input[type="date"],
.grid-item textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#date {
    background-color: var(--white-color);
    cursor: pointer;
}

.grid-item input[type="text"]:focus,
.grid-item input[type="number"]:focus,
.grid-item input[type="date"]:focus,
.grid-item textarea:focus {
    outline: none;
    border-color: var(--border-focus-color);
    box-shadow: 0 0 0 3px rgba(207, 78, 78, 0.1);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

.bullet-picker {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-top: 8px;
}

.bullet-option input[type="radio"] {
    display: none;
}

.bullet-option label {
    display: block;
    padding: 10px 20px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    background-color: #f9f9f9;
    color: #555;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
    margin-bottom: 0;
}

#type-invoice:checked + label {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white-color);
}

#type-quotation:checked + label {
    background-color: var(--quotation-color);
    border-color: var(--quotation-color);
    color: var(--white-color);
}

.table-container {
    overflow-x: auto;
}

#items-table {
    width: 100%;
    min-width: 800px;
    border-collapse: collapse;
    margin-top: 40px;
    table-layout: fixed;
}

#items-table th, #items-table td {
    border: 1px solid #e9ecef;
    padding: 12px;
    text-align: left;
    vertical-align: middle;
}

#items-table th:first-child,
#items-table td:first-child {
    width: 56%;
}

#items-table th:nth-child(2),
#items-table td:nth-child(2) {
    width: 8%;
}

#items-table th:nth-child(3),
#items-table td:nth-child(3),
#items-table th:nth-child(4),
#items-table td:nth-child(4) {
    width: 10%;
}

#items-table th:last-child,
#items-table td:last-child {
    text-align: center;
    width: 8%;
}

#items-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
}

#items-table input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 1rem;
}

#items-table input:focus {
    outline: none;
    border-color: var(--border-focus-color);
}

.btn, .btn-add-item {
    padding: 12px 25px;
    border: none;
    border-radius: 6px;
    color: var(--white-color);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    transition: background-color 0.2s, opacity 0.2s;
    text-decoration: none;
    display: inline-block;
}

.btn-add-item {
    background-color: #3498db;
    margin-top: 20px;
}

.btn-add-item:hover {
    background-color: #2980b9;
}

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #6c757d;
    transition: color 0.2s;
    padding: 5px;
    margin: 0 5px;
}

.duplicate-row-btn:hover {
    color: #3498db;
}

.remove-row-btn:hover {
    color: var(--primary-color);
}

.action-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.btn-primary {
    background-color: var(--success-color);
}
.btn-primary:hover {
    background-color: var(--success-color-hover);
}

.btn-secondary {
    background-color: var(--white-color);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}
.btn-secondary:hover {
    background-color: rgba(39, 174, 96, 0.05);
}

.loader-overlay, .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(44, 62, 80, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loader-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255,255,255,0.3);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.modal-close-btn {
    position: fixed;
    top: 15px;
    right: 25px;
    border: none;
    background: transparent;
    font-size: 3rem;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    color: var(--white-color);
    opacity: 0.8;
    z-index: 10001;
    transition: opacity 0.2s;
}
.modal-close-btn:hover {
    opacity: 1;
}

.modal-content {
    background-color: var(--white-color);
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    width: 90%;
    height: 90%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-body {
    flex-grow: 1;
    padding: 0;
    overflow: hidden;
}

#pdf-preview-iframe {
    width: 100%;
    height: 100%;
}

.history-section-container {
    max-width: 1000px;
    margin: 30px auto;
    padding: 40px;
    background-color: var(--form-background);
    border-radius: 12px;
    box-shadow: 0 6px 20px var(--shadow-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-header h2 {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.btn-delete-all {
    background: none;
    border: 1px solid #e74c3c;
    color: #e74c3c;
    font-size: 0.9rem;
    padding: 8px 15px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-delete-all:hover {
    background-color: #e74c3c;
    color: var(--white-color);
}

.history-carousel {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 25px;
}

.scroll-btn {
    background-color: #e9ecef;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.scroll-btn:hover {
    background-color: #dfe4ea;
}
.scroll-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.history-items {
    flex-grow: 1;
    display: flex;
    gap: 15px;
    overflow-x: scroll;
    padding: 10px 5px;
    scroll-behavior: smooth;
    scrollbar-width: none;
}
.history-items::-webkit-scrollbar {
    display: none;
}

.no-history-message {
    width: 100%;
    text-align: center;
    color: #6c757d;
}

.history-item {
    position: relative;
    padding: 10px 20px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    background-color: #f9f9f9;
    color: #555;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-width: 200px;
}

.history-item:hover {
    border-color: var(--primary-color);
    background-color: rgba(207, 78, 78, 0.05);
}

.history-item-type {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 10px;
    color: var(--white-color);
    margin-top: 5px;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-item-type.type-invoice {
    background-color: var(--primary-color);
}

.history-item-type.type-quotation {
    background-color: var(--quotation-color);
}

.history-item-filename {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-color);
    margin-bottom: 5px;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item-date, .history-item-time {
    font-size: 0.8rem;
    color: #6c757d;
}

.history-item-delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background-color: #e9ecef;
    color: #6c757d;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s, color 0.2s;
}

.history-item:hover .history-item-delete-btn {
    opacity: 1;
}

.history-item-delete-btn:hover {
    background-color: #c0392b;
    color: white;
}

@media (max-width: 850px) {
    .form-container, .history-section-container {
        margin: 15px;
        padding: 20px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .action-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .action-buttons .btn {
        width: 100%;
        box-sizing: border-box;
    }
}
