* { box-sizing: border-box; }
body {
    font-family: -apple-system, "Segoe UI", Roboto, "Sarabun", Arial, sans-serif;
    background: #f4f5f7;
    color: #1c1e21;
    margin: 0;
}
.topbar {
    background: #111827;
    color: #fff;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-links { display: flex; gap: 16px; }
.logout-link { color: #cbd5e1; text-decoration: none; font-size: 14px; }
.logout-link:hover { color: #fff; }

.container { max-width: 900px; margin: 24px auto; padding: 0 16px; width: 100%; }

.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px 24px;
    margin-bottom: 24px;
}
.card h2 { font-size: 16px; margin-top: 0; }

.flash {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.status-bar {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}
.status-bar.warn {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}
.error-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.back-link { margin: 0 0 12px; }
.back-link a { color: #2563eb; text-decoration: none; font-size: 14px; }
.back-link a:hover { text-decoration: underline; }

.subtitle { text-align: center; color: #6b7280; font-size: 13px; margin: -8px 0 16px; }

.webhook-url-box {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 12px 14px;
    font-family: monospace;
    font-size: 13px;
    word-break: break-all;
    color: #111827;
}

.log-box {
    max-height: 480px;
    overflow-y: auto;
    background: #0f172a;
    border-radius: 6px;
    padding: 12px 14px;
}
.log-line {
    font-family: monospace;
    font-size: 12px;
    color: #cbd5e1;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    white-space: pre-wrap;
    word-break: break-word;
}
.log-line:last-child { border-bottom: none; }
.log-line.log-error { color: #fca5a5; }

.empty-state { color: #9ca3af; font-size: 14px; padding: 12px 0; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: #374151; }
.form-row input[type=text],
.form-row input[type=number],
.form-row input[type=email],
.form-row select {
    width: 100%;
    padding: 10px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 16px; /* 16px กันไม่ให้ iOS Safari auto-zoom ตอนโฟกัส input */
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-row label { display: flex; align-items: center; gap: 8px; font-weight: normal; }
.field-hint { font-size: 12px; color: #6b7280; margin: 4px 0 0; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

button, .btn-secondary {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 11px 18px;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    min-height: 44px; /* ขนาดขั้นต่ำที่กดง่ายบนมือถือ */
}
.btn-secondary { background: #6b7280; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid #e5e7eb;
    color: #6b7280;
    font-weight: 600;
    white-space: nowrap;
}
.data-table td { padding: 10px; border-bottom: 1px solid #f1f1f1; vertical-align: top; }
.data-table .empty { text-align: center; color: #9ca3af; padding: 20px; }

.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    border: none;
    cursor: pointer;
}
.badge-on { background: #d1fae5; color: #065f46; }
.badge-off { background: #fee2e2; color: #991b1b; }
.error-note { color: #b45309; font-size: 11px; margin-top: 4px; cursor: help; }
.line-tag { color: #06c755; font-size: 11px; font-weight: 600; }

.inline-form { display: inline; margin: 0; }
.row-actions a { margin-right: 10px; color: #2563eb; text-decoration: none; font-size: 13px; }
.link-danger { background: none; color: #dc2626; border: none; padding: 0; font-size: 13px; cursor: pointer; }

.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: #f4f5f7; }
.login-box {
    background: #fff;
    padding: 32px 36px;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    width: 320px;
}
.login-box h1 { font-size: 20px; margin-top: 0; text-align: center; }
.login-logo { display: flex; justify-content: center; margin-bottom: 12px; }
.login-logo img { max-width: 100%; height: auto; object-fit: contain; }
.login-box label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.login-box input { width: 100%; padding: 10px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 16px; }
.password-field { position: relative; display: flex; align-items: center; }
.password-field input { padding-right: 64px; }
.toggle-password {
    position: absolute;
    right: 6px;
    background: none;
    border: none;
    color: #2563eb;
    font-size: 13px;
    font-weight: 600;
    padding: 4px 8px;
    min-height: auto;
    cursor: pointer;
}
.toggle-password:hover { text-decoration: underline; }
.login-box button[type=submit] { width: 100%; margin-top: 18px; }
.login-box .error { color: #dc2626; font-size: 13px; text-align: center; }

/* ---------- Responsive ---------- */

/* แท็บเล็ต */
@media (max-width: 768px) {
    .container { margin: 16px auto; padding: 0 12px; }
    .card { padding: 16px; }
}

/* มือถือ */
@media (max-width: 600px) {
    .topbar {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .topbar h1 { font-size: 16px; }

    .container { margin: 12px auto; padding: 0 10px; }
    .card { padding: 14px; border-radius: 6px; margin-bottom: 16px; }
    .card h2 { font-size: 15px; }

    /* ฟอร์ม 2 คอลัมน์ยุบเหลือคอลัมน์เดียว */
    .two-col { grid-template-columns: 1fr; gap: 12px; }

    .form-actions { flex-direction: column; }
    .form-actions button,
    .form-actions .btn-secondary { width: 100%; text-align: center; }

    /* ตารางเลื่อนแนวนอนได้แทนล้นจอ */
    .table-scroll { margin: 0 -14px; padding: 0 14px; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 6px; }

    .row-actions { display: flex; flex-direction: column; gap: 4px; }
    .row-actions a { margin-right: 0; }

    .login-box { width: 100%; max-width: 340px; padding: 28px 22px; margin: 0 16px; }
}

/* จอเล็กมาก */
@media (max-width: 380px) {
    .topbar h1 { font-size: 15px; }
    .card h2 { font-size: 14px; }
    button, .btn-secondary { font-size: 14px; padding: 10px 14px; }
}
