/* --- 1. Root Variables & Reset --- */
:root {
    --primary-color: #007bff;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --gray-color: #6c757d;
    --bg-light: #f4f4f9;
    --font-main: 'Prompt', sans-serif;
}

body { 
    font-family: var(--font-main); 
    padding: 15px; 
    background-color: var(--bg-light); 
    color: #333; 
    margin: 0; 
}

/* --- 2. Layout Containers --- */
.container { 
    max-width: 850px; 
    margin: 0 auto; 
    background: white; 
    padding: 20px; 
    border-radius: 10px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
}

.instructor-banner { 
    background-color: #d1ecf1; 
    color: #0c5460; 
    padding: 12px; 
    border-radius: 8px; 
    border: 1px solid #bee5eb; 
    margin-bottom: 20px; 
    font-weight: 600; 
    text-align: center; 
}

/* --- 3. Inputs & Forms --- */
.team-input-box { 
    text-align: center; 
    margin-bottom: 20px; 
    padding: 15px; 
    background-color: #f8f9fa; 
    border-radius: 8px; 
    border: 1px dashed #ced4da; 
}

.input-row { 
    margin-bottom: 15px; 
    text-align: left; 
}

.input-row label { 
    display: block; 
    font-weight: 600; 
    margin-bottom: 5px; 
    color: #555; 
    font-size: 0.95rem; 
}

.team-input-box input, 
.team-input-box select { 
    font-family: var(--font-main); 
    font-size: 1rem; 
    padding: 10px; 
    width: 100%; 
    border: 2px solid var(--primary-color); 
    border-radius: 8px; 
    box-sizing: border-box; 
    outline: none; 
}

/* --- 4. Settings Section --- */
.settings-box { 
    background-color: #e2e6ea; 
    padding: 15px; 
    border-radius: 8px; 
    margin-bottom: 25px; 
    border: 1px solid #ced4da; 
}

.settings-row { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    margin-bottom: 12px; 
    gap: 15px; 
    flex-wrap: wrap; 
}

.settings-row label { 
    min-width: 140px; 
    font-weight: 600; 
}

.input-group-tight { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

.input-group-tight input { 
    font-family: var(--font-main); 
    width: 80px; 
    padding: 6px; 
    text-align: center; 
    border: 2px solid #adb5bd; 
    border-radius: 6px; 
    font-weight: 700; 
}

/* --- 5. Timer & Progress Display --- */
.timer-display { 
    font-size: 5.5rem; 
    font-weight: 700; 
    text-align: center; 
    margin: 10px 0; 
    color: #222; 
    font-variant-numeric: tabular-nums; 
}

.live-progress-container { 
    width: 100%; 
    height: 45px; 
    background-color: #e9ecef; 
    border-radius: 8px; 
    position: relative; 
    margin-bottom: 40px; 
    overflow: visible; 
    border: 1px solid #ced4da; 
}

.live-safe-zone { 
    position: absolute; 
    top: 0; bottom: 0; 
    background-color: rgba(40, 167, 69, 0.2); 
    border-left: 2px dashed #1e7e34; 
    border-right: 2px dashed #1e7e34; 
    z-index: 1; 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end; 
}

.limit-label { 
    font-size: 0.75rem; 
    font-weight: 600; 
    color: #155724; 
    background-color: #ffffff; 
    padding: 2px 6px; 
    border-radius: 4px; 
    border: 1px solid #ced4da;
    z-index: 10; 
    position: absolute;
    bottom: -32px; 
    transform: translateX(-50%);
    white-space: nowrap;
}

#lblMinOnBar { left: 0; }
#lblMaxOnBar { left: 100%; }

.live-progress-bar { 
    height: 100%; 
    width: 0%; 
    background-color: var(--warning-color); 
    transition: width 1s linear, background-color 0.5s ease; 
    position: absolute; 
    top: 0; left: 0; 
    z-index: 2; 
    opacity: 0.9;
    border-radius: 8px;
}

/* --- 6. Controls & Buttons --- */
.controls { 
    text-align: center; 
    margin-bottom: 25px; 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: center; 
    gap: 10px; 
}

button { 
    font-family: var(--font-main); 
    font-weight: 600; 
    padding: 12px 20px; 
    font-size: 1.1rem; 
    cursor: pointer; 
    border: none; 
    border-radius: 8px; 
    color: white; 
    min-width: 100px; 
    flex: 1; 
    max-width: 140px; 
    transition: transform 0.1s, opacity 0.2s; 
}

button:active { transform: scale(0.95); }

.btn-start { background-color: var(--success-color); }
.btn-pause { background-color: var(--warning-color); color: #333; }
.btn-stop  { background-color: var(--danger-color); }
.btn-reset { background-color: var(--gray-color); }

button:disabled { 
    background-color: #ccc !important; 
    color: #666 !important; 
    opacity: 0.7; 
    cursor: not-allowed; 
}

/* --- 7. Result & History --- */
#resultBox { 
    display: none; 
    padding: 20px; 
    border-radius: 10px; 
    margin-top: 20px; 
    text-align: center; 
    border: 1px solid #ddd; 
}

.result-pass { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb !important; }
.result-fail { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb !important; }

.diff-highlight-box {
    margin: 5px auto 15px auto;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.2rem;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

#calculationMethod {
    margin-top: 5px; 
    padding: 15px;
    background: rgba(255, 255, 255, 0.85); 
    border-radius: 8px;
    border: 1px dashed #adb5bd;
    display: inline-block;
    text-align: left;
    line-height: 1.6;
    color: #333;
    font-size: 0.9rem;
    width: 90%;
    max-width: 450px;
    box-sizing: border-box;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.history-section { 
    margin-top: 40px; 
    border-top: 2px dashed #ccc; 
    padding-top: 20px; 
    display: none; 
}

.table-responsive { 
    width: 100%; 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    margin-top: 15px; 
    border-radius: 8px; 
    border: 1px solid #dee2e6; 
}

.history-table { 
    width: 100%; 
    border-collapse: collapse; 
    font-size: 0.9rem; 
    min-width: 750px; 
}

.history-table th, 
.history-table td { 
    border: 1px solid #dee2e6; 
    padding: 12px; 
    text-align: center; 
    white-space: nowrap; 
}

.history-table th { 
    background-color: #f8f9fa; 
    font-weight: 600; 
}

/* --- 8. [NEW] Style สำหรับ CMA Drill Box --- */
.drill-box {
    background: #fff7e6; 
    border: 1px dashed #faad14; 
    border-radius: 8px; 
    margin-bottom: 20px; 
    padding: 10px 15px;
    transition: all 0.3s ease;
}

.drill-header {
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    margin-bottom: 5px;
}

.drill-header h4 {
    margin: 0; 
    color: #d46b08;
    font-size: 14px;
    font-weight: 700;
}

/* Status Badges */
.badge-ready { background: #d9d9d9; color: #555; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.badge-active { background: #faad14; color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; animation: blink 1s infinite; }
.badge-done { background: #52c41a; color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; }

@keyframes blink { 50% { opacity: 0.5; } }

.drill-body {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin: 10px 0;
}

.drill-time {
    font-size: 2.2rem;
    font-weight: 800;
    color: #d46b08;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.btn-drill {
    background-color: #faad14;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 14px;
    width: auto !important;
    box-shadow: 0 2px 5px rgba(250, 173, 20, 0.3);
    min-width: auto;
    flex: initial;
}

.btn-drill:hover { background-color: #d48806; transform: translateY(-1px); }
.btn-drill:active { transform: translateY(0); }
.btn-drill:disabled { background-color: #d9d9d9 !important; color: #999 !important; cursor: not-allowed; box-shadow: none; opacity: 0.7; }

.drill-remark {
    font-size: 11px;
    color: #8c8c8c;
    margin: 5px 0 0 0;
    text-align: center;
    font-style: italic;
}

/* --- 9. Responsive --- */
@media (max-width: 600px) { 
    .timer-display { font-size: 4rem; } 
    .container { padding: 15px; } 
    .drill-body { flex-direction: column; gap: 5px; }
    .btn-drill { width: 100% !important; max-width: 100%; }
}