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

body {
    font-family: 'Bai Jamjuree', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 15px;
    font-size: 14px;
    color: #333;
}

.container {
    background: white;
    padding: 25px 20px;
    border-radius: 16px;
    max-width: 500px;
    margin: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

h1 {
    text-align: center;
    font-size: 1.3em;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 4px;
}

h2 {
    text-align: center;
    font-size: 0.95em;
    font-weight: 400;
    color: #718096;
    margin-bottom: 8px;
}

.doc-ref {
    text-align: left;
    font-size: 0.8em;
    color: #4a5568;
    margin-bottom: 20px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
    background: #f7fafc;
}

h3 {
    text-align: center;
    font-size: 1em;
    font-weight: 600;
    color: #2d3748;
    margin: 25px 0 12px;
}

/* Form top dropdowns */
.form-top {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.form-top select {
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
    font-family: 'Bai Jamjuree', sans-serif;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: #f7fafc;
    color: #4a5568;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23718096' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-top select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* Equipment info card */
.equipment-info {
    background: #edf2f7;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
    border: 1.5px solid #e2e8f0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid #e2e8f0;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 500;
    color: #4a5568;
}

.info-row span:last-child {
    color: #2d3748;
    font-weight: 600;
}

/* Inspection form */
.inspection-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 10px;
    padding: 20px;
    background: #f7fafc;
    border-radius: 12px;
    border: 1.5px solid #e2e8f0;
}

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

.form-group label {
    font-weight: 500;
    font-size: 13px;
    color: #4a5568;
}

.form-group input[type="text"],
.form-group input[type="date"] {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
    font-family: 'Bai Jamjuree', sans-serif;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: white;
    color: #2d3748;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input[type="text"]:focus,
.form-group input[type="date"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group select {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
    font-family: 'Bai Jamjuree', sans-serif;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    background: white;
    color: #4a5568;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23718096' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group input[type="file"] {
    width: 100%;
    font-size: 12px;
    font-family: 'Bai Jamjuree', sans-serif;
    margin-top: 6px;
    padding: 8px;
    border: 1.5px dashed #cbd5e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
}

.form-group .file-label {
    font-weight: 400;
    font-size: 12px;
    color: #718096;
    margin-top: 8px;
}

.form-group textarea {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
    font-family: 'Bai Jamjuree', sans-serif;
    border: 1.5px solid #fed7d7;
    border-radius: 10px;
    background: #fff5f5;
    color: #c53030;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group textarea:focus {
    outline: none;
    border-color: #e53e3e;
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.15);
}

.form-group textarea::placeholder {
    color: #feb2b2;
}

/* Photo section */
.calibration-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 6px;
}

.calibration-row div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.calibration-row label {
    font-size: 11px;
    color: #718096;
    font-weight: 400;
}

.calibration-row input {
    width: 100%;
    padding: 9px 10px;
    font-size: 13px;
    font-family: 'Bai Jamjuree', sans-serif;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    text-align: center;
}

.calibration-row input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* Photo section */
.photo-section {
    margin-top: 12px;
}

.photo-header {
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
    padding-bottom: 8px;
    border-bottom: 2.5px solid #f6ad55;
    margin-bottom: 12px;
}

.photo-header span {
    color: #2d3748;
}

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

.photo-box label {
    font-size: 12px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 4px;
    display: block;
}

.photo-placeholder {
    width: 100%;
    height: 100px;
    background: #f7fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    position: relative;
}

.photo-placeholder:active {
    background: #edf2f7;
}

.photo-placeholder .camera-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.photo-placeholder span:last-of-type {
    font-size: 11px;
    color: #a0aec0;
}

.photo-placeholder img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}

/* Radio group */
.radio-group {
    display: flex;
    gap: 0;
    margin-top: 4px;
}

.radio-group label {
    font-weight: 400;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: 1.5px solid #e2e8f0;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    justify-content: center;
}

.radio-group label:first-child {
    border-radius: 10px 0 0 10px;
}

.radio-group label:last-child {
    border-radius: 0 10px 10px 0;
    border-left: none;
}

.radio-group label:has(input:checked) {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.radio-group.result-pass label:has(input:checked) {
    background: #38a169;
    border-color: #38a169;
    color: white;
}

.radio-group.result-fail label:has(input:checked) {
    background: #e53e3e;
    border-color: #e53e3e;
    color: white;
}

.radio-group input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: white;
}

/* Button */
button {
    margin-top: 20px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 12px;
    font-size: 16px;
    font-family: 'Bai Jamjuree', sans-serif;
    font-weight: 600;
    width: 100%;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

button:active {
    transform: scale(0.97);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Table wrapper */
.table-wrapper {
    overflow-x: auto;
    margin-top: 12px;
    border-radius: 10px;
    border: 1.5px solid #e2e8f0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 6px;
    text-align: center;
    font-size: 11px;
    font-weight: 500;
}

td {
    padding: 10px 6px;
    text-align: center;
    word-break: break-word;
    border-bottom: 1px solid #edf2f7;
    color: #4a5568;
}

tr:last-child td {
    border-bottom: none;
}

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

/* Tabs */
.tab-container {
    margin-bottom: 0;
    padding: 15px 15px 10px;
    border-radius: 16px 16px 0 0;
    box-shadow: none;
    position: relative;
    padding-top: 45px;
}

.back-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    background: #e53e3e;
    color: white;
    text-decoration: none;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s;
    border: none;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(229, 62, 62, 0.3);
}

.back-btn:hover {
    background: #c53030;
}

.back-btn:active {
    transform: scale(0.95);
}

#formTab, .history-container, #registerTab {
    border-radius: 0 0 16px 16px;
    margin-top: 0;
}

.tabs {
    display: flex;
    border-radius: 10px;
    overflow: hidden;
    border: 1.5px solid #e2e8f0;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
    font-family: 'Bai Jamjuree', sans-serif;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: #edf2f7;
    color: #718096;
    transition: all 0.2s;
    margin: 0;
    border-radius: 0;
    width: auto;
    box-shadow: none;
}

.tab-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.tab-btn:active {
    transform: none;
}

.history-container {
    margin-top: 0;
}

/* Sub-tabs */
.sub-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 15px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid #e2e8f0;
}

.sub-tab-btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 12px;
    font-family: 'Bai Jamjuree', sans-serif;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: #f7fafc;
    color: #718096;
    transition: all 0.2s;
    margin: 0;
    border-radius: 0;
    width: auto;
    box-shadow: none;
}

.sub-tab-btn.active {
    background: #4299e1;
    color: white;
}

.sub-tab-btn:active {
    transform: none;
}

.sub-tab-content {
    margin-bottom: 15px;
}

/* Register header */
.register-header {
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 15px;
    background: #f7fafc;
}

.register-header-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    font-size: 12px;
    color: #4a5568;
    padding: 4px 0;
}

.register-header-row:first-child {
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 8px;
    margin-bottom: 4px;
}

.register-title {
    font-weight: 700;
    font-size: 13px;
    color: #2d3748;
}

.register-table th {
    font-size: 10px;
    padding: 8px 4px;
    white-space: nowrap;
}

.register-table td {
    font-size: 11px;
    padding: 8px 4px;
}

/* History box */
.history-box {
    margin-top: 25px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}

.history-box h3 {
    margin: 0;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.95em;
    font-weight: 600;
    text-align: left;
    border-radius: 0;
}

.history-list {
    padding: 12px 16px;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 10px 12px;
    border-bottom: 1px solid #edf2f7;
    font-size: 13px;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item .history-date {
    font-weight: 600;
    color: #2d3748;
}

.history-item .history-result {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
}

.history-item .history-result.pass {
    background: #c6f6d5;
    color: #276749;
}

.history-item .history-result.fail {
    background: #fed7d7;
    color: #9b2c2c;
}

.history-item .history-detail {
    color: #718096;
    font-size: 12px;
    margin-top: 4px;
}

.empty-history {
    text-align: center;
    color: #a0aec0;
    font-size: 13px;
    padding: 20px 0;
}

/* ปุ่มเพิ่มรายการ */
.add-item-btn {
    margin-top: 15px;
    padding: 10px 20px;
    background: #4299e1;
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Bai Jamjuree', sans-serif;
    font-weight: 600;
    width: auto;
    box-shadow: 0 2px 8px rgba(66, 153, 225, 0.3);
    transition: all 0.2s;
}

.add-item-btn:hover {
    background: #3182ce;
}

.add-item-btn:active {
    transform: scale(0.97);
}

/* Radio group ขนาดเล็กสำหรับตาราง */
.radio-group-sm {
    display: flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.radio-group-sm label {
    font-size: 11px;
    padding: 5px 8px;
    flex: 1;
    justify-content: center;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    background: white;
    transition: all 0.2s;
    border: none;
    font-weight: 500;
}

.radio-group-sm label:first-child {
    border-radius: 6px 0 0 6px;
}

.radio-group-sm label:last-child {
    border-radius: 0 6px 6px 0;
}

.radio-group-sm input[type="radio"] {
    width: 12px;
    height: 12px;
}

/* Instrument Card (สำหรับฟอร์มหลายเครื่อง) */
.instrument-card {
    background: white;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.instrument-card-header {
    font-weight: 700;
    font-size: 14px;
    color: white;
    background: linear-gradient(135deg, #4299e1 0%, #667eea 100%);
    padding: 8px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    text-align: center;
}

/* Buffer Solution Section (PH Meter) */
.buffer-section {
    background: #f7fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
}

.buffer-section-title {
    font-weight: 700;
    font-size: 13px;
    color: #2b6cb0;
    text-align: center;
    padding: 6px 12px;
    background: #ebf8ff;
    border-radius: 6px;
    margin-bottom: 10px;
}

.buffer-section-title.after {
    color: #276749;
    background: #f0fff4;
}

.buffer-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.buffer-col {
    text-align: center;
}

.buffer-header {
    font-weight: 600;
    font-size: 12px;
    color: #4a5568;
    padding: 4px;
    background: #edf2f7;
    border-radius: 6px;
    margin-bottom: 6px;
}

.buffer-inputs {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.buffer-inputs div {
    display: flex;
    align-items: center;
    gap: 4px;
}

.buffer-inputs label {
    font-size: 11px;
    font-weight: 500;
    color: #718096;
    min-width: 20px;
    text-align: right;
}

.buffer-inputs input {
    width: 100%;
    padding: 7px 6px;
    font-size: 13px;
    font-family: 'Bai Jamjuree', sans-serif;
    border: 1.5px solid #e2e8f0;
    border-radius: 6px;
    text-align: center;
    background: white;
}

.buffer-inputs input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.criteria-box {
    margin-top: 10px;
    padding: 8px 14px;
    background: #fffbeb;
    border: 1.5px solid #f6e05e;
    border-radius: 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #975a16;
}

/* Media query สำหรับจอที่ใหญ่ขึ้น */
@media (min-width: 600px) {
    body {
        padding: 30px;
    }

    .container {
        padding: 35px 30px;
        max-width: 1200px;
    }

    .form-top {
        grid-template-columns: repeat(2, 1fr);
    }

    h1 {
        font-size: 1.5em;
    }

    .tabs {
        max-width: 700px;
        margin: 0 auto;
    }

    .tab-btn {
        font-size: 15px;
        padding: 14px 20px;
    }

    .register-header-row {
        font-size: 14px;
    }

    .register-table th {
        font-size: 12px;
        padding: 10px 6px;
    }

    .register-table td {
        font-size: 12px;
        padding: 10px 6px;
    }

    .history-item {
        font-size: 14px;
    }

    .history-item .history-detail {
        font-size: 13px;
    }

    .photo-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1400px;
    }

    .form-top {
        grid-template-columns: repeat(2, 1fr);
    }

    .inspection-form {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .inspection-form .form-group:first-child,
    .inspection-form #failReasonGroup {
        grid-column: span 2;
    }

    .register-table th,
    .register-table td {
        font-size: 13px;
        padding: 10px 8px;
        white-space: nowrap;
    }

    .table-wrapper {
        overflow-x: visible;
    }
}
